在Racket中使用#lang ragg
为简单语言创建解析器。这是语法:
#lang ragg
program : sexpr* start* layout
sexpr : SEXPR
start : WORD WORD "[" WORD* "=" ">" sexpr "]"
layout : elem*
elem : info | text | sexpr
info : "{" text "}"
text : WORD*
以下是最初的几个令牌:
#(struct:token-struct SEXPR (define a 'something) #f 1 0 #f #f)
#(struct:token-struct WORD run #f 1 22 #f #f)
#(struct:token-struct WORD ram-loop #f 1 26 #f #f)
#(struct:token-struct [ [ #f 1 35 #f #f)
#(struct:token-struct WORD ram #f 1 36 #f #f)
#(struct:token-struct WORD max-ram #f 1 40 #f #f)
#(struct:token-struct = = #f 1 48 #f #f)
#(struct:token-struct > > #f 1 49 #f #f)
(编辑)输入文字为:(define a 'something) run ram-loop [ram max-ram => (format \"~a/~a GB RAM\" ram max-ram)] {ram} {fg:#966} {cpu} Some text (leftsep #363)
(编辑)当然..我在令牌流上调用(parse)
时得到的错误:
; Encountered unexpected token #\[ ("[") while parsing #f [line=1, column=35,
; offset=#f] [,bt for context]
语法似乎应该接受SEXPR WORD WORD [
。知道为什么不是吗?