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