From 633621558d5709ee1df19a53c355bdaf4eaeafe6 Mon Sep 17 00:00:00 2001 From: twanvl Date: Fri, 3 Aug 2007 21:32:40 +0000 Subject: [PATCH] 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 --- tools/website/drupal/fromfile.module | 3 + .../drupal/mse-drupal-modules/autoformat.inc | 3 +- .../drupal/mse-drupal-modules/highlight.inc | 97 +++++++++++++++++-- 3 files changed, 95 insertions(+), 8 deletions(-) diff --git a/tools/website/drupal/fromfile.module b/tools/website/drupal/fromfile.module index e1e571c5..efff2d1b 100644 --- a/tools/website/drupal/fromfile.module +++ b/tools/website/drupal/fromfile.module @@ -80,6 +80,8 @@ function fromfile_page() { return drupal_not_found(); } $raw = file($full_path); + global $current_doc_file; + $current_doc_file = "$file"; foreach($raw as $k=>$l) $raw[$k] = preg_replace("/\r?\n/","",$l); @@ -106,6 +108,7 @@ function fromfile_page() { // done drupal_set_breadcrumb($breadcrumbs); + drupal_set_title($title); // view as a node $node = array( 'title' => $title, diff --git a/tools/website/drupal/mse-drupal-modules/autoformat.inc b/tools/website/drupal/mse-drupal-modules/autoformat.inc index adba00ac..258b8ad4 100644 --- a/tools/website/drupal/mse-drupal-modules/autoformat.inc +++ b/tools/website/drupal/mse-drupal-modules/autoformat.inc @@ -9,7 +9,8 @@ global $nice_names; $nice_names = array( 'type:double' => 'real number', 'type:int' => 'number', - 'type:indexmap' => 'map', + 'type:indexmap' => 'field map', + 'type:vector2d' => '2D-vector', ); diff --git a/tools/website/drupal/mse-drupal-modules/highlight.inc b/tools/website/drupal/mse-drupal-modules/highlight.inc index d8e4e972..d8fc527c 100644 --- a/tools/website/drupal/mse-drupal-modules/highlight.inc +++ b/tools/website/drupal/mse-drupal-modules/highlight.inc @@ -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 .= "" . $matches[0] . ""; } else if (preg_match("@^(include file:)(.*)@",$code, $matches)) { $ret .= "" . $matches[1] . "" . $matches[2]; @@ -74,20 +143,34 @@ function highlight_script($code) { // return from string quote $ret .= "" . highlight_script_string($matches[0]) . ""; $string = substr($string,0,-1); - if ($matches[3] == '{') $string .= 's'; + if ($matches[2] == '{') $string .= 's'; } else if (preg_match("@^\\#.*@",$code, $matches)) { $ret .= "" . $matches[0] . ""; } else if (preg_match("@^([-+*/=!.]|<|>)+|^:=@",$code, $matches)) { $ret .= "" . $matches[0] . ""; } else if (preg_match("@^([}]|[\\(\\)\\[\\]{,]+)@",$code, $matches)) { $ret .= "" . $matches[0] . ""; - 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 .= "" . $matches[0] . ""; - } 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 .= "" . $m . ""; + } else { + $ret .= "$m"; // current function + } + } else { + $ret .= $m; + //$ret .= '[' . $m . ']'; + } } else { // fallback $matches = array($code[0]);