r2390 - findTagWarnings(): employ getTagByName()
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 3 Feb 2009 17:30:25 +0000 (17:30 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Tue, 3 Feb 2009 17:30:25 +0000 (17:30 +0000)
 - getSentencesFromLexems(): save line numbers inside SYNT_CTXMOD to use in messages
 - introduce findCtxModWarnings() for SYNT_ADJUSTMENT nodes checking
 - highlight "true" and "false" as keywords in CodePress

inc/code.php
js/codepress/languages/rackcode.js

index f10c1b57d2042ea7e45fc9d2b671df7bfa04e5fa..598d6d86b97dc047024b8831d1b9b3e9ff1f4865 100644 (file)
@@ -371,7 +371,7 @@ function getSentencesFromLexems ($lexems)
                                        (
                                                'type' => 'SYNT_CTXMOD',
                                                'lineno' => $stacktop['lineno'],
-                                               'load' => array ('op' => 'insert', 'tag' => $stacktop['load'])
+                                               'load' => array ('op' => 'insert', 'tag' => $stacktop['load'], 'lineno' => $stacktop['lineno'])
                                        )
                                );
                                continue;
@@ -392,7 +392,7 @@ function getSentencesFromLexems ($lexems)
                                        (
                                                'type' => 'SYNT_CTXMOD',
                                                'lineno' => $stacktop['lineno'],
-                                               'load' => array ('op' => 'remove', 'tag' => $stacktop['load'])
+                                               'load' => array ('op' => 'remove', 'tag' => $stacktop['load'], 'lineno' => $stacktop['lineno'])
                                        )
                                );
                                continue;
@@ -921,8 +921,11 @@ function getRackCodeWarnings ()
                        case 'SYNT_DEFINITION':
                                $ret = array_merge ($ret, findTagWarnings ($sentence['definition']));
                                break;
-                       case 'SYNT_GRANT':
                        case 'SYNT_ADJUSTMENT':
+                               $ret = array_merge ($ret, findTagWarnings ($sentence['condition']));
+                               $ret = array_merge ($ret, findCtxModWarnings ($sentence['modlist']));
+                               break;
+                       case 'SYNT_GRANT':
                                $ret = array_merge ($ret, findTagWarnings ($sentence['condition']));
                                break;
                        default:
@@ -1117,7 +1120,6 @@ function findAutoTagWarnings ($expr)
 // Idem WRT tags.
 function findTagWarnings ($expr)
 {
-       global $taglist;
        switch ($expr['type'])
        {
                case 'LEX_BOOLCONST':
@@ -1127,9 +1129,8 @@ function findTagWarnings ($expr)
                        // Only verify stuff, that has passed through the saving handler.
                        if (!mb_ereg_match (TAGNAME_REGEXP, $expr['load']))
                                return array();
-                       foreach ($taglist as $taginfo)
-                               if ($taginfo['tag'] == $expr['load'])
-                                       return array();
+                       if (getTagByName ($expr['load']) !== NULL)
+                               return array();
                        return array (array
                        (
                                'header' => refRCLineno ($expr['lineno']),
@@ -1154,6 +1155,21 @@ function findTagWarnings ($expr)
        }
 }
 
+// Check context modifiers, warn about those, which try referencing non-existent tags.
+function findCtxModWarnings ($modlist)
+{
+       $ret = array();
+       foreach ($modlist as $mod)
+               if (($mod['op'] == 'insert' or $mod['op'] == 'remove') and NULL === getTagByName ($mod['tag']))
+                       $ret[] = array
+                       (
+                               'header' => refRCLineno ($mod['lineno']),
+                               'class' => 'warning',
+                               'text' => "Tag '${mod['tag']}' does not exist."
+                       );
+       return $ret;
+}
+
 // Return true, if the expression makes use of the predicate given.
 function referencedPredicate ($pname, $expr)
 {
index 684345a79d67f98f8d7aae90982e1a1a66ae298d..cdeee088473cd83ecb1b8b3c16c5a4fab8eddf64 100644 (file)
@@ -4,6 +4,6 @@ Language.shortcuts = []
 Language.syntax = [
        { input : /{(.*?)(}|<br>|<\/P>)/g, output : '<s>{$1$2</s>'}, // tags
        { input : /\[(.*?)(\]|<br>|<\/P>)/g, output : '<s>[$1$2</s>'}, // predicatess
-       { input : /\b(define|allow|deny|and|not|or|context|clear|insert|remove|on)\b/g, output : '<b>$1</b>'}, // keywords
+       { input : /\b(define|allow|deny|true|false|and|not|or|context|clear|insert|remove|on)\b/g, output : '<b>$1</b>'}, // keywords
        { input : /([^:]|^)#(.*?)(<br|<\/P)/g, output : '$1<i>#$2</i>$3'} // comments //        
 ]