debugging, documentation for peg-lexer
parent
cccaff40b1
commit
995d28fb2f
extra/peg-lexer
|
@ -0,0 +1,11 @@
|
|||
USING: peg.ebnf help.syntax help.markup strings ;
|
||||
IN: peg-lexer
|
||||
ABOUT: "peg-lexer"
|
||||
|
||||
HELP: ON-BNF:
|
||||
{ $syntax "ON-BNF: word ... ;ON-BNF" }
|
||||
{ $description "Creates a parsing word using a parser for lexer control, adding the resulting ast to the stack. Parser syntax is as in " { $link POSTPONE: EBNF: } } ;
|
||||
|
||||
HELP: create-bnf
|
||||
{ $values { "word" string } { "parser" parser } }
|
||||
{ $description "Runtime equivalent of ON-BNF- also useful with manually constructed parsers." } ;
|
|
@ -38,11 +38,11 @@ M: lex-hash at* swap {
|
|||
[ execute [ error-stack get first throw ] unless* ] with-global-lexer
|
||||
ast>> ;
|
||||
|
||||
: create-bnf ( name parser -- ) [ lexer get skip-blank parse* dup V{ } = [ parsed ] unless ] curry
|
||||
define POSTPONE: parsing ;
|
||||
|
||||
: create-bnf ( name parser -- ) reset-tokenizer [ lexer get skip-blank parse* dup V{ } = [ parsed ] unless ] curry
|
||||
define word make-parsing ;
|
||||
|
||||
: ON-BNF: CREATE-WORD reset-tokenizer ";ON-BNF" parse-multiline-string parse-ebnf
|
||||
main swap at reset-tokenizer create-bnf ; parsing
|
||||
main swap at create-bnf ; parsing
|
||||
|
||||
! Tokenizer like standard factor lexer
|
||||
EBNF: factor
|
||||
|
|
Loading…
Reference in New Issue