Add syntax word for ebnf
parent
7578538122
commit
708d55fb8e
|
@ -99,6 +99,11 @@ M: ebnf (generate-parser) ( ast -- id )
|
||||||
|
|
||||||
DEFER: 'rhs'
|
DEFER: 'rhs'
|
||||||
|
|
||||||
|
: syntax ( string -- parser )
|
||||||
|
#! Parses the string, ignoring white space, and
|
||||||
|
#! does not put the result in the AST.
|
||||||
|
token sp hide ;
|
||||||
|
|
||||||
: 'identifier' ( -- parser )
|
: 'identifier' ( -- parser )
|
||||||
#! Return a parser that parses an identifer delimited by
|
#! Return a parser that parses an identifer delimited by
|
||||||
#! a quotation character. The quotation can be single
|
#! a quotation character. The quotation can be single
|
||||||
|
@ -144,23 +149,23 @@ DEFER: 'choice'
|
||||||
|
|
||||||
: 'group' ( -- parser )
|
: 'group' ( -- parser )
|
||||||
[
|
[
|
||||||
"(" token sp hide ,
|
"(" syntax ,
|
||||||
[ 'choice' sp ] delay ,
|
[ 'choice' sp ] delay ,
|
||||||
")" token sp hide ,
|
")" syntax ,
|
||||||
] seq* [ first ] action ;
|
] seq* [ first ] action ;
|
||||||
|
|
||||||
: 'repeat0' ( -- parser )
|
: 'repeat0' ( -- parser )
|
||||||
[
|
[
|
||||||
"{" token sp hide ,
|
"{" syntax ,
|
||||||
[ 'choice' sp ] delay ,
|
[ 'choice' sp ] delay ,
|
||||||
"}" token sp hide ,
|
"}" syntax ,
|
||||||
] seq* [ first <ebnf-repeat0> ] action ;
|
] seq* [ first <ebnf-repeat0> ] action ;
|
||||||
|
|
||||||
: 'optional' ( -- parser )
|
: 'optional' ( -- parser )
|
||||||
[
|
[
|
||||||
"[" token sp hide ,
|
"[" syntax ,
|
||||||
[ 'choice' sp ] delay ,
|
[ 'choice' sp ] delay ,
|
||||||
"]" token sp hide ,
|
"]" syntax ,
|
||||||
] seq* [ first <ebnf-optional> ] action ;
|
] seq* [ first <ebnf-optional> ] action ;
|
||||||
|
|
||||||
: 'sequence' ( -- parser )
|
: 'sequence' ( -- parser )
|
||||||
|
@ -196,12 +201,12 @@ DEFER: 'choice'
|
||||||
: 'rule' ( -- parser )
|
: 'rule' ( -- parser )
|
||||||
[
|
[
|
||||||
'non-terminal' [ ebnf-non-terminal-symbol ] action ,
|
'non-terminal' [ ebnf-non-terminal-symbol ] action ,
|
||||||
"=" token sp hide ,
|
"=" syntax ,
|
||||||
'rhs' ,
|
'rhs' ,
|
||||||
] seq* [ first2 <ebnf-rule> ] action ;
|
] seq* [ first2 <ebnf-rule> ] action ;
|
||||||
|
|
||||||
: 'ebnf' ( -- parser )
|
: 'ebnf' ( -- parser )
|
||||||
'rule' sp "." token sp hide list-of [ <ebnf> ] action ;
|
'rule' sp "." syntax list-of [ <ebnf> ] action ;
|
||||||
|
|
||||||
: ebnf>quot ( string -- quot )
|
: ebnf>quot ( string -- quot )
|
||||||
'ebnf' parse [
|
'ebnf' parse [
|
||||||
|
|
Loading…
Reference in New Issue