JFlex Lexer.多行字符串



我正在尝试使用 JFlex 解析一些带有多行字符串文字的语言。

例子:

'''
this is a valid multiline string literal with 'quoted' word
'''

我创建了两个状态:

%x IN_QUOTED_STRING
%x IN_MULTILINE_QUOTED_STRING

并创建了几个宏和规则:

QUOTED_STRING_TAIL=[^']* "'"
QUOTED_STRING_START="@"? "'"
MULTILINE_QUOTED_STRING_START = "@"? "'''"
MULTILINE_QUOTED_STRING_TAIL = [.]* "'''"
%%
<YYINITIAL> {MULTILINE_QUOTED_STRING_START} {yybegin(IN_MULTILINE_QUOTED_STRING);}
<YYINITIAL> {QUOTED_STRING_START} {yybegin(IN_QUOTED_STRING);}
<IN_QUOTED_STRING> {QUOTED_STRING_TAIL} {yybegin(YYINITIAL); return STRING;}
<IN_MULTILINE_QUOTED_STRING> {MULTILINE_QUOTED_STRING_TAIL} {yybegin(YYINITIAL); return STRING;}

但它不起作用。我收到"错误:无法匹配输入"

谁能帮我做道具?

OP写道:

为我工作:

QUOTED_LITERAL="'" ([^\'rn] | {ESCAPE_SEQUENCE} | ([rn]))* ("'"|)?
ESCAPE_SEQUENCE=[^rn] 
ANY_ESCAPE_SEQUENCE = [^] 
THREE_QUO = (""") 
ONE_TWO_QUO = ("[^"]) | ("[^]) | (""[^"]) | (""[^]) 
QUO_STRING_CHAR = [^\"] | {ANY_ESCAPE_SEQUENCE} | {ONE_TWO_QUO}
TRIPLE_QUOTED_LITERAL = {THREE_QUO} {QUO_STRING_CHAR}* {THREE_QUO}?
%%
<YYINITIAL> {TRIPLE_QUOTED_LITERAL }{ return STRING; } 
<YYINITIAL> {QUOTED_LITERAL} { return STRING; }

相关内容

  • 没有找到相关文章

最新更新