是否可以解析固定宽度的内容?
我勾画了以下内容,但它没有编译:
grammar FixedWidth;
content: name age birthday;
name: character[10, false];
age: integer[2, false];
birthday: date['yyyy-MM-dd', true];
salary: float[9, 2, true];
character[int n, boolean required] locals [int i=1]:
({$required && $i == 1}? NONBLANKCHAR {!$required && $i == 1}? CHAR {$i < $n}? CHAR {$i++;});
integer[int n, boolean required] locals [int i=1]: ({$i <= $n}? INT {$required}? | SPACE {$i++;});
float[int n, int decimals, boolean required] locals [int i=1]: ({$i < $n}? INT {$i == $n - $decimals - 1}? '.' {$i++;});
date[String dateFormat, boolean required] locals [int i=1;int n = $dateFormat.length();String mask = $dateFormat.replace('y', $INT).replace('M', $INT).replace('d', $INT)]: ($mask {!$required}? | String.format("%" + $n + "s", "")) ;
NONBLANKCHAR: ~[SPACE] ;
CHAR: [.] ;
INT: [0-9] ;
SPACE: ' ' ;
如果上面有任何愚蠢的错误,请原谅我。我是g4的新手。