]> gitweb.factorcode.org Git - factor.git/commitdiff
peg.ebnf: Add EBNF-PARSER: to define a word that returns an EBNF parser
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 6 Aug 2017 05:17:25 +0000 (00:17 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 6 Aug 2017 05:17:25 +0000 (00:17 -0500)
This is in contrast to defining a word that parser.

basis/peg/ebnf/ebnf.factor
extra/cpu/8080/emulator/emulator.factor

index f9c196a8a4d68c20fefb5bdcf1f848aec52623ef..5f58951fce7165be12a5492ff10dac3a9633e467 100644 (file)
@@ -4,7 +4,7 @@ USING: accessors assocs combinators combinators.short-circuit
 effects kernel make math math.parser multiline namespaces parser
 peg peg.parsers quotations sequences sequences.deep splitting
 stack-checker strings strings.parser summary unicode
-vocabs.parser words ;
+vocabs.parser words fry ;
 FROM: vocabs.parser => search ;
 FROM: peg.search => replace ;
 IN: peg.ebnf
@@ -538,7 +538,8 @@ ERROR: could-not-parse-ebnf ;
 PRIVATE>
 
 SYNTAX: EBNF:
-    reset-tokenizer scan-new-word dup scan-object
+    reset-tokenizer
+    scan-new-word dup scan-object
     ebnf>quot swapd
     ( input -- ast ) define-declared "ebnf-parser" set-word-prop
     reset-tokenizer ;
@@ -554,3 +555,9 @@ SYNTAX: EBNF[==[ "]==]" parse-multiline-string define-inline-ebnf ;
 SYNTAX: EBNF[===[ "]===]" parse-multiline-string define-inline-ebnf ;
 SYNTAX: EBNF[====[ "]====]" parse-multiline-string define-inline-ebnf ;
 
+SYNTAX: EBNF-PARSER:
+    reset-tokenizer
+    scan-new-word
+    scan-object parse-ebnf main of '[ _ ]
+    ( -- parser ) define-declared
+    reset-tokenizer ;
index 6c7801bae167e8415f5e0dbcda6c78932896e9ab..adb06e68f09c8e366488f194c8eacd9f75e88ded 100644 (file)
@@ -755,31 +755,31 @@ SYMBOLS: $1 $2 $3 $4 ;
         { "EX-RR,RR" [ [ $1 ] keep [ $3 ] keep [ $2 ] keep $4 ] }
     } ;
 
-: 8-bit-registers ( -- parser )
+EBNF-PARSER: 8-bit-registers
     ! A parser for 8-bit registers. On a successfull parse the
     ! parse tree contains a vector. The first item in the vector
     ! is the getter word for that register with stack effect
     ! ( cpu -- value ). The second item is the setter word with
     ! stack effect ( value cpu -- ).
-    EBNF[=[
+    [=[
         main=("A" | "B" | "C" | "D" | "E" | "H" | "L") => [[ register-lookup ]]
-    ]=] ;
+    ]=]
 
-: all-flags ( -- parser )
+EBNF-PARSER: all-flags
     ! A parser for 16-bit flags.
-    EBNF[=[
+    [=[
         main=("NZ" | "NC" | "PO" | "PE" | "Z" | "C" | "P" | "M") => [[ flag-lookup ]]
-    ]=] ;
+    ]=]
 
-: 16-bit-registers ( -- parser )
+EBNF-PARSER: 16-bit-registers
     ! A parser for 16-bit registers. On a successfull parse the
     ! parse tree contains a vector. The first item in the vector
     ! is the getter word for that register with stack effect
     ! ( cpu -- value ). The second item is the setter word with
     ! stack effect ( value cpu -- ).
-    EBNF[=[
+    [=[
         main=("AF" | "BC" | "DE" | "HL" | "SP") => [[ register-lookup ]]
-    ]=] ;
+    ]=]
 
 : all-registers ( -- parser )
     ! Return a parser that can parse the format