- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在尝试使用 JavaCC 作为解析器来解析 UTF-8(语言是日语)的源代码。在 JavaCC 中,我们有这样的声明:
< #LETTER:
[
"\u0024",
"\u0041"-"\u005a",
"\u005f",
"\u0061"-"\u007a",
"\u00c0"-"\u00d6",
"\u00d8"-"\u00f6",
"\u00f8"-"\u00ff",
"\u0100"-"\u1fff",
"\u3040"-"\u318f",
"\u3300"-"\u337f",
"\u3400"-"\u3d2d",
"\u4e00"-"\u9fff",
"\uf900"-"\ufaff"
]
>
如果遇到像“日建フェンス工业”这样的字符串,就会因为业字符而失败。如果我删除它,它会按预期工作。业字符的代码是“\u696d”,从声明中可以看出,它应该属于“\u4e00”-“\u9fff”的范围
对此有什么建议吗?
PS:如果我们用Antlr重写这个语法,会是什么样子
非常感谢
最佳答案
您的 token 片段没有问题,JavaCC 也没有问题。问题出在别处。
这是通过将您的问题代码复制并粘贴到 JavaCC 中而制定的 JavaCC 规范。
options {
static = true;
debug_token_manager = true ; }
PARSER_BEGIN(MyNewGrammar)
package funnyunicode;
import java.io.StringReader ;
public class MyNewGrammar
{
public static void main(String args []) throws ParseException
{
MyNewGrammar parser = new MyNewGrammar(new StringReader("日建フェンス工業"));
MyNewGrammar.go() ;
System.out.println("OK."); } }
PARSER_END(MyNewGrammar)
TOKEN :
{
< WORD : (<LETTER>)+ >
|
< #LETTER:
[
"\u0024",
"\u0041"-"\u005a",
"\u005f",
"\u0061"-"\u007a",
"\u00c0"-"\u00d6",
"\u00d8"-"\u00f6",
"\u00f8"-"\u00ff",
"\u0100"-"\u1fff",
"\u3040"-"\u318f",
"\u3300"-"\u337f",
"\u3400"-"\u3d2d",
"\u4e00"-"\u9fff",
"\uf900"-"\ufaff"
] >
}
void go() :
{Token tk ; }
{
tk=<WORD> <EOF>
}
这是生成的 Java 程序的输出
Current character : \u65e5 (26085) at line 1 column 1
Starting NFA to match one of : { <WORD> }
Current character : \u65e5 (26085) at line 1 column 1
Currently matched the first 1 characters as a <WORD> token.
Possible kinds of longer matches : { <WORD> }
Current character : \u5efa (24314) at line 1 column 2
Currently matched the first 2 characters as a <WORD> token.
Possible kinds of longer matches : { <WORD> }
Current character : \u30d5 (12501) at line 1 column 3
Currently matched the first 3 characters as a <WORD> token.
Possible kinds of longer matches : { <WORD> }
Current character : \u30a7 (12455) at line 1 column 4
Currently matched the first 4 characters as a <WORD> token.
Possible kinds of longer matches : { <WORD> }
Current character : \u30f3 (12531) at line 1 column 5
Currently matched the first 5 characters as a <WORD> token.
Possible kinds of longer matches : { <WORD> }
Current character : \u30b9 (12473) at line 1 column 6
Currently matched the first 6 characters as a <WORD> token.
Possible kinds of longer matches : { <WORD> }
Current character : \u5de5 (24037) at line 1 column 7
Currently matched the first 7 characters as a <WORD> token.
Possible kinds of longer matches : { <WORD> }
Current character : \u696d (26989) at line 1 column 8
Currently matched the first 8 characters as a <WORD> token.
Possible kinds of longer matches : { <WORD> }
****** FOUND A <WORD> MATCH (\u65e5\u5efa\u30d5\u30a7\u30f3\u30b9\u5de5\u696d) ******
Returning the <EOF> token.
OK.
如您所见,生成的分词器可以毫无问题地将 \u696d
视为 LETTER
。
关于JavaCC 和 Unicode 问题。为什么\u696d属于 "\u4e00"-"\u9fff"范围,但在JavaCC中无法管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30933785/
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我正在使用我在论坛中看到的示例来突出显示当前导航菜单。 例如,我可以让我的事件导航菜单具有 background-color:#fff,但我没有成功执行 color:#fff。为什么 backgrou
如何将 #ffffff 转换为 #fff 或将 #fff 转换为 #ffffff 以进行断言? 我正在使用 getCssValue("background")从 Selenium 返回 rgb(255
我有一个 href 链接“打开菜单”,并且该链接的颜色为灰色。 我想使用 jQuery,因为当我单击此“打开菜单”时,我想将颜色更改为 #FFF。 我尝试使用下面的代码执行此操作,但它不起作用,我正在
我有一个包含十六进制数字的字符串,我想递增该十六进制数字,直到达到我的最大数字 (FFF)。我如何遍历才能获得起始十六进制和 FFF 之间的每个数字? 我尝试将字符串转换为字节数组,但之后卡住了。 s
我正在尝试使用 google test 测试我的 C 库,但是我在使用 fff.h 模拟函数时遇到了麻烦框架。这是我的文件结构: . ├── Makefile.am ├── configure.ac
我正在处理这个页面。 http://www.careersinmusic.com/aaaa-testing-link.aspx 所以当我的主要问题是底部的不可见区域时。我希望它是白色的,但我不知道如何
我们希望在电子邮件中以表格形式显示订单详情 Header 1 Header 2 Header 3
我正在尝试解析 MP3 文件并检测可变比特率 (VBR) MP3 文件中的所有帧。我浏览了整个互联网,但找不到合适的解决方案来检测新的帧头同步。从其他帖子来看,它说我应该寻找 FFE 或 FFF,但在
日期时间中的fff和ms有什么区别? DateTime dt = DateTime.Now; string s1 = dt.ToString("yyyy-MM-dd HH:mm:ss.fff"); s
首先,是的,我知道渲染相同的颜色,我的问题是关于速度的简单查询。 这只是一个关于优化页面加载速度的有趣主题,但标题中的哪个选项会呈现得更快(即使是最微小的差异)? 我的想法是,使用简写版本 (#fff
如果我有: .foo { background-color:#fff; } LESS 将其转换为: .foo { background-color:white; } 这是为什么?浏览器处
在 PowerShell V2 中,我想计算给定字符串的总秒数和毫秒数。 我的字符串是 00:03:56,908,所需的输出是 236.908 我的工作,但笨拙的代码是 $a = "00:03:56,
我想知道是否有人可以帮助我解决这个问题。我需要验证文本框中的文本输入。我需要确保它采用 TimeSpan 可接受的格式。预期格式应为 hh:mm:ss:fff(即小时、分钟、秒和毫秒。例如 15:30
我无法显示“关闭窗口”文本。难道某处是白色的吗?! 根据开发人员的说法,“关闭”应该是要更改的正确值。 transition: "elastic", speed: 300, width
这个 SVG 有 2 个填充,一个是无,第二个是红色。当它没有悬停时,我如何做到这一点,然后当它悬停时,它会变成颜色? 顺便说一下,它现在只改变红色的 .icon{ fill: re
This Wordpress front page使用子主题。 父主题包含 CSS: body { background: #fff; } 这个首页使用 CSS: body.home {
我正在从需要存储在文本框中的数据库中提取 DateTime 值(如果您必须知道,它是一个 ASP.NET 文本框)。此 DateTime 包含毫秒。然后我需要将此值保存回数据库。 问题:当我这样做时
当使用“shorthand hexidecimal”(style="color: #FFF;")定义颜色时,是否有定义的方法来扩展shorthand? (style="color: #F0F0F0;"
我在 :hover 上遇到了 block 子元素的一些问题事件。我有一个定价 block ,主要任务是在 :hover 上获取所有文本 #fff 颜色. 因为当我尝试 :hover 元素和 它们是元素
我是一名优秀的程序员,十分优秀!