[英]BNF to handle escape sequence
I use this BNF to parser my script: 我使用这个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;
It can parse correctly the following text into tree structure 它可以将以下文本正确解析为树结构
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"
}
}
my question is, how do I handle escape sequence inside string literal: 我的问题是, 如何在字符串文字中处理转义序列 :
"some text of \"quotation\" should escape"
Define str as: 将str定义为:
str = ( strset strescape ) *;
with 同
strescape = { \\ } {\" } ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.