我在编写语法方面不是很有经验,但是假设我有类似这样的记录类型: (实施例)
record # 1 source ages params A = 1 and b = 2 fields are A, B, C with values 1, 2, 3;
record # 2;
record # 3 source ages;
record # 4 params A = 1 and b = 2 fields are A, B, C with values 1, 2, 3;
record # 5 source ages fields are A, B, C with values 1, 2, 3;
record # 6 with values 1, 2, 3;
基本上:
这是我的语法,它不起作用:
---开始语法:
@start = record;
record = 'record' '#' numeric rest* ';';
rest = 'source' alphanumeric paramsAndOrFieldsAndOrWithValues*;
paramsAndOrFieldsAndOrWithValues = (paramsList)? (fieldsList)? (valuesList)?;
paramsList = 'params' alpha expr numeric ('and' alpha expr numeric)*;
fieldsList = 'fields' 'are' alpha (comma alpha)*;
valuesList = 'with' 'values' numeric (comma numeric)*;
alpha = Word;
numeric = Number;
alphanumeric = (alpha | numeric | '_' | '.');
comma = ',';
expr = '=';
---结束语法
@“ParseKit的开发者”,能帮帮我吗?
谢谢:)
答案 0 :(得分:1)
ParseKit的开发人员。
你的语法有点偏。我编写了一个与您的示例输入相匹配的语法。我使用DebugApp
目标运行此功能,并确认它适用于您的示例。
@start = records;
records = record+;
record = prefix source? params? fields? values? suffix;
prefix = 'record' '#' Number;
suffix = ';';
// source
source = 'source' Word;
// params
params = 'params' expr ('and' expr)*;
expr = name '=' Number;
name = Word;
// fields
fields = 'fields' 'are' name (',' name)*;
// values
values = 'with' 'values' val (',' val)*;
val = Number;