mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Syntax highlighter now knows about built in functions
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@599 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -2,6 +2,73 @@
|
||||
|
||||
// Syntax highlighting of script and reader code
|
||||
|
||||
global $built_in_functions;
|
||||
$built_in_functions = array(
|
||||
// text
|
||||
'to_upper' =>'',
|
||||
'to_lower' =>'',
|
||||
'to_title' =>'',
|
||||
'reverse' =>'',
|
||||
'substring' =>'',
|
||||
'format' =>'', 'format_rule' =>'format',
|
||||
'curly_quotes' =>'',
|
||||
'replace' =>'', 'replace_rule' => 'replace',
|
||||
'filter_text' =>'', 'filter_rule' => 'filter_text',
|
||||
'sort_text' =>'', 'sort_rule' => 'sort_text',
|
||||
'contains' =>'',
|
||||
'match' =>'', 'match_rule' => 'match',
|
||||
// tags
|
||||
'tag_contents' =>'', 'tag_contents_rule'=>'tag_contents',
|
||||
'remove_tag' =>'', 'tag_remove_rule' =>'remove_tag',
|
||||
// lists
|
||||
'postion' =>'',
|
||||
'length' =>'',
|
||||
'number_of_items' =>'',
|
||||
'sort_list' =>'',
|
||||
'filter_list' =>'',
|
||||
// keywords
|
||||
'expand_keywords' =>'', 'expand_keywords_rule'=>'expand_keywords',
|
||||
'keyword_usage' =>'',
|
||||
// english
|
||||
'english_number' =>'',
|
||||
'english_number_a' =>'english_number',
|
||||
'english_number_multiple'=>'english_number',
|
||||
'english_number_ordinal' =>'english_number',
|
||||
'english_plural' =>'',
|
||||
'english_singular' =>'english_plural',
|
||||
'process_english_hints' =>'',
|
||||
// fields and values
|
||||
'forward_editor' =>'',
|
||||
'combined_editor' =>'combined_editor',
|
||||
'primary_choice' =>'',
|
||||
'chosen' =>'',
|
||||
'require_choice' =>'',
|
||||
'exclusive_choice' =>'',
|
||||
'require_exclusive_choice'=>'',
|
||||
'remove_choice' =>'',
|
||||
// images
|
||||
'linear_blend' =>'',
|
||||
'masked_blend' =>'',
|
||||
'combine_blend' =>'',
|
||||
'set_mask' =>'',
|
||||
'set_alpha' =>'',
|
||||
'set_combine' =>'',
|
||||
'enlarge' =>'',
|
||||
'crop' =>'',
|
||||
'drop_shadow' =>'',
|
||||
'symbol_variation' =>'',
|
||||
'built_in_image' =>'',
|
||||
// html export
|
||||
'to_html' =>'',
|
||||
'symbols_to_html' =>'',
|
||||
'to_text' =>'',
|
||||
'copy_file' =>'',
|
||||
'write_text_file' =>'',
|
||||
'write_image_file' =>'',
|
||||
'trace' =>'',
|
||||
);
|
||||
|
||||
|
||||
function syntax_highlight($code) {
|
||||
if (preg_match("@^(\s*#.*\n)*\s*[-a-zA-Z0-9 _/,]+:([^=]|$)@", $code)) {
|
||||
return highlight_reader($code);
|
||||
@@ -53,12 +120,14 @@ function highlight_reader($code) {
|
||||
}
|
||||
|
||||
function highlight_script($code) {
|
||||
global $built_in_functions;
|
||||
global $current_doc_file;
|
||||
$ret = '';
|
||||
$string = '';
|
||||
$string = ''; // inside "{..}" braces? b for braces, s for string
|
||||
while(strlen($code)) {
|
||||
if (preg_match("@^<[^>]+>@",$code, $matches)) {
|
||||
$ret .= $matches[0]; // plain tag
|
||||
} else if (preg_match("@^(if|then|else|for|in|do|and|or|xor|not|rgb)\b@",$code, $matches)) {
|
||||
} else if (preg_match("@^(if|then|else|for( each)?|in(?= )|do|and|or|xor|not|rgb|from|to)\b(?!:)@",$code, $matches)) {
|
||||
$ret .= "<span class='hl-kw'>" . $matches[0] . "</span>";
|
||||
} else if (preg_match("@^(include file:)(.*)@",$code, $matches)) {
|
||||
$ret .= "<span class='hl-key'>" . $matches[1] . "</span>" . $matches[2];
|
||||
@@ -74,20 +143,34 @@ function highlight_script($code) {
|
||||
// return from string quote
|
||||
$ret .= "<span class='hl-str'>" . highlight_script_string($matches[0]) . "</span>";
|
||||
$string = substr($string,0,-1);
|
||||
if ($matches[3] == '{') $string .= 's';
|
||||
if ($matches[2] == '{') $string .= 's';
|
||||
} else if (preg_match("@^\\#.*@",$code, $matches)) {
|
||||
$ret .= "<span class='hl-comment'>" . $matches[0] . "</span>";
|
||||
} else if (preg_match("@^([-+*/=!.]|<|>)+|^:=@",$code, $matches)) {
|
||||
$ret .= "<span class='hl-op'>" . $matches[0] . "</span>";
|
||||
} else if (preg_match("@^([}]|[\\(\\)\\[\\]{,]+)@",$code, $matches)) {
|
||||
$ret .= "<span class='hl-paren'>" . $matches[0] . "</span>";
|
||||
if ($matches[0] == '{') $string .= 'p';
|
||||
if ($matches[0] == '{') $string .= 'b';
|
||||
elseif ($matches[0] == '}') $string = substr($string,0,-1);
|
||||
} else if (preg_match("@^[a-zA-Z_][a-zA-Z0-9_]*:@",$code, $matches)) {
|
||||
$ret .= "<span class='hl-ckey'>" . $matches[0] . "</span>";
|
||||
} else if (preg_match("@^([a-zA-Z0-9_]+\s*|\s+|&#?[a-zA-Z0-9]+;)@",$code, $matches)) {
|
||||
//$ret .= '[' . $matches[0] . ']';
|
||||
$ret .= $matches[0];
|
||||
} else if (preg_match("@^([a-zA-Z0-9_]+|\s+|&#?[a-zA-Z0-9]+;)@",$code, $matches)) {
|
||||
$m = $matches[0];
|
||||
// function call?
|
||||
if (isset($built_in_functions[$m]) // to built in function
|
||||
) {
|
||||
$f = $built_in_functions[$m];
|
||||
if ($f == '') $f = $m;
|
||||
$f = 'function/' . $f;
|
||||
if (!isset($current_doc_file) || $current_doc_file != $f) {
|
||||
$ret .= "<a class='hl-fun' href='" . url('doc/' . $f) . "'>" . $m . "</a>";
|
||||
} else {
|
||||
$ret .= "<span class='hl-this'>$m</span>"; // current function
|
||||
}
|
||||
} else {
|
||||
$ret .= $m;
|
||||
//$ret .= '[' . $m . ']';
|
||||
}
|
||||
} else {
|
||||
// fallback
|
||||
$matches = array($code[0]);
|
||||
|
||||
Reference in New Issue
Block a user