]> gitweb.factorcode.org Git - factor.git/commitdiff
core: Don't allow nested defintions in :, ::, M:, M::. Fixes #469.
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 24 Aug 2012 22:53:00 +0000 (15:53 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 24 Aug 2012 22:53:45 +0000 (15:53 -0700)
basis/locals/parser/parser.factor
core/effects/parser/parser.factor
core/generic/parser/parser.factor

index 0bb47586c29d791228e70dee7f100fb16bc8f7a2..4b212f098ea9c5e8a61faab9e8bc3e66fe8b2cbc 100644 (file)
@@ -86,13 +86,17 @@ M: lambda-parser parse-quotation ( -- quotation )
     (parse-locals-definition) ; inline
 
 : (::) ( -- word def effect )
-    scan-new-word
-    [ parse-definition ]
-    parse-locals-definition ;
+    [
+        scan-new-word
+        [ parse-definition ]
+        parse-locals-definition
+    ] in-word-definition ;
 
 : (M::) ( -- word def )
-    scan-new-method
     [
-        [ parse-definition ]
-        parse-locals-method-definition drop
-    ] with-method-definition ;
+        scan-new-method
+        [
+            [ parse-definition ]
+            parse-locals-method-definition drop
+        ] with-method-definition
+    ] in-word-definition ;
index ea378b68c7832fbcaee89e30649b6ef3de96f50a..f14877a5650ae7f32d00726b46813b8b60ad0abb 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: lexer sets sequences kernel splitting effects
-combinators arrays make vocabs.parser classes parser ;
+USING: arrays combinators effects kernel lexer make namespaces
+parser sequences splitting words ;
 IN: effects.parser
 
 DEFER: parse-effect
@@ -13,6 +13,8 @@ ERROR: stack-effect-omits-dashes ;
 
 SYMBOL: effect-var
 
+SYMBOL: in-definition
+
 <PRIVATE
 : end-token? ( end token -- token ? ) [ nip ] [ = ] 2bi ; inline
 : effect-opener? ( token -- token ? ) dup { f "(" "((" "--" } member? ; inline
@@ -52,7 +54,17 @@ PRIVATE>
 : parse-call( ( accum word -- accum )
     [ ")" parse-effect ] dip 2array append! ;
 
+ERROR: can't-nest-definitions word ;
+
+: check-in-definition ( -- )
+    in-definition get [ word can't-nest-definitions ] when ;
+
+: in-word-definition ( quot -- )
+    [ check-in-definition t in-definition ] dip with-variable ; inline
+
 : (:) ( -- word def effect )
-    scan-new-word
-    scan-effect
-    parse-definition swap ;
+    [
+        scan-new-word
+        scan-effect
+        parse-definition swap
+    ] in-word-definition ;
index dcb0f665dbdb79dd405dc201e529601c33a46c57..90f7b91f839888d9fb28659ebe120fd745693e26 100644 (file)
@@ -54,4 +54,6 @@ ERROR: bad-method-effect ;
 PRIVATE>
 
 : (M:) ( -- method def )
-    scan-new-method [ parse-method-definition ] with-method-definition ;
+    [
+        scan-new-method [ parse-method-definition ] with-method-definition
+    ] in-word-definition ;