Menu

[r45]: / trunk / python / python.lang.php  Maximize  Restore  History

Download this file

107 lines (82 with data), 2.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
<?php
require_once __DIR__.'/../lime/parse_engine.php';
require_once __DIR__.'/common.php';
require_once __DIR__.'/python.execfile.php';
##
class lang_python extends lang_python_execfile {
##
private static $parser = null;
##
public static function getParser() {
if (static::$parser == null) {
static::$parser = new parse_engine(new lang_python());
}
return static::$parser;
}
}
/*
define('__PYTHON__',__DIR__);
$_PYTHON = array(
"DEBUG" => array(
"DUMP_TOKEN" => true
),
"PARSER" => null,
);
function python_start() {
global $_PYTHON;
require_once __LIME__ .'/parse_engine.php';
require_once __PYTHON__ .'/python.class.php';
require_once __PYTHON__ .'/python.tokenize.php';
require_once __PYTHON__ .'/python.interface.php';
require_once __PYTHON__ .'/python.eval.php';
$_PYTHON["PARSER"] = new parse_engine(new python());
}
function python_exec($filename) {
$code = file_get_contents($filename);
#echo '<pre>';
#echo htmlentities($code);
#echo '</pre>';
python_eval($code);
}
function python_build() {
require_once __LIME__.'/lime.php';
$code = parse_lime_grammar(__PYTHON__.'/python.lime');
file_put_contents(__PYTHON__.'/python.class.php',"<?php \n".$code."\n?>");
}
function python_sanitize($code) {
return $code;
}
function re($regex,$input,&$output) {
return preg_match($regex,$input,&$output);
}
function python_token($name,$value=null,$len=1) {
return array(
"name" => $name,
"value" => $value,
"len" => $len
);
}
function python_parse_comment($comment) {
global $_PYTHON;
if (re("/^#\{([a-zA-Z_][a-zA-Z0-9_]*)\}:(.*)/",$comment,$r)){
$_PYTHON["DEBUG"][$r[1]] = trim($r[2]);
#var_dump($_PYTHON["DEBUG"]);
}
}
function python_dump_token($token) {
echo '<span style="margin:0 2px 2px 0;display:inline-block;padding:0px 4px;font-family:arial;font-size:10px;background:yellow;color:#323232;border:1px solid #323232;">';
if (is_object($token["value"])) {
echo $token["name"].'('.strip_tags($token["value"]->name).')';
} else {
echo $token["name"].'('.strip_tags($token["value"]).')';
}
echo '</span>';
}
function python_run($script) {
#python_build();
python_start();
python_exec($script);
}
*
*
*/
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.