Hi,
I have this grammar defined below with the idea to parse ASTM messages (standard E1394).
An ASTM message is composed of segments, records that start with a segment type and
and end with a carriage return.
A valid ASTM message always start with a 'H' (header) segment and ends with a 'L' segment (trailer).
I used this example as input (I replaced the carriage returns with <CR> for readability)
H|\^&||a LL e||xyz|P<CR>L|1|F<CR>
The first 4 characters following the 'H' on the 'H' segment defined the limiters
that are used in the message (default is | for fields, \ for repeats, ^ for components and & as escape character)
I started with a simple version where the segments only consists of fields separated by
a '|', so the repeat, component and escape delimiters are for future enhancement.
Now there is something wrong with my grammar as it gives an error on the 19th
character, the 'P' just before the <CR>.
line 1:19 extraneous input 'P' expecting '\r'
If someone could help me out with this, that would be great.
Thanks in advance!
Olivier
---
grammar astm;
message: header segment* trailer EOF;
header: HEADER_START FIELD_DELIMITER REPEAT_DELIMITER COMPONENT_DELIMITER ESCAPE_DELIMITER data SEGMENT_END;
segment: SEGMENT_START data SEGMENT_END;
trailer: TRAILER_START data SEGMENT_END;
data: (FIELD_DELIMITER field)*;
field: CHARACTER?;
HEADER_START: 'H';
TRAILER_START: 'L';
SEGMENT_START: 'P' | 'O' | 'R' | 'Q' | 'S' | 'M' | 'C' | 'E';
SEGMENT_END: '\r';
FIELD_DELIMITER: '|';
REPEAT_DELIMITER: '\\';
COMPONENT_DELIMITER: '^';
ESCAPE_DELIMITER: '&';
CHARACTER: (~[|\\^&\r])+;