ura*_*ray 5 grammar parsing escaping bnf
我使用这个 BNF 来解析我的脚本:
{identset} = {ASCII} - {"\{\}}; //<--all ascii charset except '\"' '{' and '}'
{strset} = {ASCII} - {"};
ident = {identset}*;
str = {strset}*;
node ::= ident "{" nodes "}" | //<--entry point
"\"" str "\"" |
ident;
nodes ::= node nodes |
node;
Run Code Online (Sandbox Code Playgroud)
它可以正确地将以下文本解析为树结构
doc {
title { "some title goes here" }
refcode { "SDS-1" }
rev { "1.0" }
revdate { "04062010" }
body {
"this is the body of the document
all text should go here"
chapter { "some inline section" }
"text again"
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何处理字符串文字中的转义序列:
"some text of \"quotation\" should escape"
Run Code Online (Sandbox Code Playgroud)
将 str 定义为:
str = ( strset strescape ) *;
Run Code Online (Sandbox Code Playgroud)
和
strescape = { \\ } {\" } ;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2675 次 |
最近记录: |