peg.ebnf: Add EBNF-PARSER: to define a word that returns an EBNF parser

This is in contrast to defining a word that parser.
modern-harvey2
Doug Coleman 2017-08-06 00:17:25 -05:00
parent 42ceea05cb
commit fad9e9d002
2 changed files with 18 additions and 11 deletions

View 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 ;

View 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