r2779 - semanticFilter(): don't allow redefining predicates (ticket:214)
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 19 May 2009 17:07:32 +0000 (17:07 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Tue, 19 May 2009 17:07:32 +0000 (17:07 +0000)
inc/code.php

index a44613e1649e5a0897c2dac7430c7a1fe6f13fad..65ecea5b0bff2a5974b3122c4fc2330d2e326890 100644 (file)
@@ -889,12 +889,21 @@ function semanticFilter ($code)
                switch ($sentence['type'])
                {
                        case 'SYNT_DEFINITION':
+                               // A predicate can only be defined once.
+                               if (in_array ($sentence['term'], $predicatelist))
+                                       return array
+                                       (
+                                               'result' => 'NAK',
+                                               'load' => "[${sentence['term']}] has already been defined earlier"
+                                       );
+                               // Check below makes sure, that definitions are built from already existing
+                               // tokens. This also makes recursive definitions impossible.
                                $up = firstUnrefPredicate ($predicatelist, $sentence['definition']);
                                if ($up !== NULL)
                                        return array
                                        (
                                                'result' => 'NAK',
-                                               'load' => "definition [${sentence['term']}] uses unknown predicate [${up}]"
+                                               'load' => "definition of [${sentence['term']}] refers to [${up}], which is not (yet) defined"
                                        );
                                $predicatelist[] = $sentence['term'];
                                break;