ASTM message parsing - extraneous input

26 views
Skip to first unread message

Olivier-R

unread,
Jun 5, 2024, 2:52:19 AMJun 5
to antlr-discussion
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])+;

andy....@btinternet.com

unread,
Jun 7, 2024, 9:20:35 PMJun 7
to antlr-discussion
Hi, Have u tried using the debugger ? Andy

From: antlr-di...@googlegroups.com <antlr-di...@googlegroups.com> on behalf of Olivier-R <orom...@gmail.com>
Sent: 05 June 2024 7:52 AM
To: antlr-discussion <antlr-di...@googlegroups.com>
Subject: [antlr-discussion] ASTM message parsing - extraneous input
 
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/antlr-discussion/39eaef2a-78b9-44d6-8f16-3901d4bbf454n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages