我正在尝试使用带有简单 fs.readFile 函数的 js 将数据从 .RC(资源定义文件)解析为 JSON,但是我收到了 SyntaxError: Invalid or unexpected token。目前我没有找到其他解决方案来解析这种类型的文件,请为我提供输入。以下是 .RC 示例。
#include "shapes.h"
ShapesCursor CURSOR SHAPES.CUR
ShapesIcon ICON SHAPES.ICO
ShapesMenu MENU
{
POPUP "&Shape"
{
MENUITEM "&Clear", ID_CLEAR
MENUITEM "&Rectangle", ID_RECT
}
}
我在节点中找到了一个名为“Jison”的包,它是一个用于在 JavaScript 中创建类似于“PegJS”的解析器的 API,但是如果它支持的话,我也无法弄清楚需要为我的文件类型编写的语法文件类型。解析后的结构可能类似于,
{
"directive": [
"include",
"shapes.h"
],
"data": [
{
"name": "ShapesCursor",
"values": [
"CURSOR",
"SHAPES.CUR"
],
"children": []
},
{
"name": "ShapesIcon",
"values": [
"CURSOR",
"SHAPES.ICO"
],
"children": []
},
{
"name": "POPUP",
"values": [
"&Shape"
],
"children": [
{
"name": "MENUITEM",
"values": [
"&Clear",
"ID_CLEAR"
],
"children": []
},
{
"name": "MENUITEM",
"values": [
"&Rectangle",
"ID_RECT"
],
"children": []
}
]
}
]
}