[英]How do I Handle tokens within text blocks in JavaCC?
I have a simple aspect of a DSL where I can define a key and a value as such: 我有一个简单的DSL方面,我可以定义一个键和一个值:
mykey=\\ This is my $REF{useful} multiline string where I terminate with a backslash but I support escaped \\\\ characters and I wish to handle the value part of this string as 3 blocks in this example. \\
The three tokens (for the value part) I would like in this example are 在这个例子中我想要的三个标记(对于值部分)是
I defined a rule for the value as such: 我为这个值定义了一个规则:
void multiLineValue(): {} {
< BACKSLASH >< EOL >
(
valuePartLiteralMulti() |
valuePartRef()
)*
< BACKSLASH >
}
Here is my TOKEN definition for the multiline string type: 这是多行字符串类型的TOKEN定义:
TOKEN :
{
< MULTILINE_STRING:( ( (~["\\"])
| ("\\"
( ["\\", "'", "\"", "$", "n", "r", "t", "b", "f"]
| ["u", "U"]["+"]["0"-"9","a"-"f","A"-"F"]["0"-"9","a"-"f","A"-"F"]["0"-"9","a"-"f","A"-"F"]["0"-"9","a"-"f","A"-"F"]
)
) ))+>
}
My problem is that my multi line string token type also consumes the character sequence of the '$REF{' characters. 我的问题是我的多行字符串标记类型也使用了'$ REF {'字符的字符序列。
I would like to modify this multi-line string so that it will stop consuming characters when it encounters an unescaped "$REF{" (but will continue reading past a "\\$REF{" sequence). 我想修改此多行字符串,以使其在遇到未转义的“ $ REF {”时将停止使用字符(但将继续读取“ \\ $ REF {”序列)。
Any assistance would be much appreciated. 任何援助将不胜感激。
I'm not sure, but in your token definition you also include $ (in unicode?), maybe you should add ~("$") (or the unicode equivalent) at the beginnig. 我不确定,但是在您的令牌定义中,您还包括$(在unicode中?),也许您应该在beginnig处添加〜(“ $”)(或与unicode等价)。
Or you can use syntatic LOOKAHEAD, something like LOOKAHEAD(valuePartRef())... 或者您可以使用语法LOOKAHEAD,类似LOOKAHEAD(valuePartRef())。
ps Can you have more than one REF? ps你有多个REF吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.