用不同数量的字段编写ParseKit语法(按顺序)

时间:2012-04-03 18:08:28

标签: objective-c parsekit

我在编写语法方面不是很有经验,但是假设我有类似这样的记录类型: (实施例)

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;

基本上:

  1. 必须以“record#Number”开头,并以分号结尾。
  2. 可按以下顺序包含0或1次捕获:
  3. 源数据集
  4. 数据集的参数
  5. 数据集
  6. 中的字段
  7. 数据集中的值
  8. 这是我的语法,它不起作用:

    ---开始语法:

    @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的开发者”,能帮帮我吗?

    谢谢:)

1 个答案:

答案 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;