[英]Treetop Grammar does not recognize “/”
我是Treetop的新手,語法非常簡單,我無法工作。 我有一些測試:
it "parses a open tag as some text surrouded by brackets" do
document = "[b]"
Parser.parse(document).should_not be_nil
end
it "parses a close tag as a tag with a / preceeding the tag name" do
document = '[/b]'
Parser.parse(document).should_not be_nil
end
這是我的語法:
grammar BBCode
rule open_tag
"[" tag_name "]"
end
rule tag_name
[a-zA-Z\*]+
end
rule close_tag
"[/" tag_name "]"
end
end
第一次測試通過,第二次測試失敗。 我還嘗試了以下替代規則:
"[" [\/] tag_name "]"
"[" "/" tag_name "]"
"[\/" tag_name "]"
所有這些都失敗了。
無論嘗試如何,我似乎都無法識別結束標記。
我發現了這個問題: https : //github.com/nathansobo/treetop/issues/25 ,它似乎已經回答了我的問題。
我的語法沒有包含允許打開或關閉標簽的頂級規則,因此,甚至沒有考慮第二種可能性:
grammar BBCode
rule document
(open_tag / close_tag)
end
rule open_tag
("[" tag_name "]")
end
rule tag_name
[a-zA-Z\*]+
end
rule close_tag
("[/" tag_name "]")
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.