[antlr-interest] No t in title

Alexander Brill alex at brill.no
Fri Nov 30 07:28:38 PST 2007


Hi,

I'm rather new to antlr, just started picking it up a couple of days ago as
I wanted a better way to parse some message files to a object in Java.

What I'd like to have is that the :KEY VALUE pair is to be saved in a Map
for easy retrieval.

I've come a long way in setting it up - but there are some quirks I haven't
quite figured out yet. All the statements, but the 'message' statement,
works on its own. But its the 'message' statement thats going to tie it all
together. tspobject.g and some test data attached below.

What I could figure out was that the T token is messing things up a bit. It
makes all my keys starting with T (:TITLE) go fubar. What am I missing?

tspobject.g:

grammar tspobject;
@header {
package test;
import java.util.HashMap;
}

@lexer::header {package test}

@members {
HashMap memory = new HashMap();
}


char    :    UPPERALPHA|LOWERALPHA|INT|WS        ;
attrname    :    UPPERALPHA +            ;
year    :    INT INT INT INT            ;
month    :    INT INT                ;
date    :    INT INT                ;
hour    :    INT INT                ;
minute    :    INT INT                ;
second    :    INT INT                ;
milli    :    INT INT INT                ;
gmt    :    INT INT                ;
str    :    char*                ;
list    :    LPAREN (QUOTE str QUOTE)* RPAREN        ;
message    :    LPAREN MESSAGE keypair* RPAREN        ;
attrvalue    :    list|QUOTE str QUOTE|INT*            ;
keypair    :    WS? COLON attrname WS* attrvalue        ;
timestamp    :    ALPHA year DASH month DASH date T hour COLON minute COLON
second DOT milli PLUS gmt;


T    :    'T'                ;
MESSAGE    :    'MESSAGE'                ;
INT    :    '0'..'9'                ;
UPPERALPHA    :    'A'..'Z'                ;
LOWERALPHA    :    'a'..'z'                ;
WS     :      (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}     ;
QUOTE    :    '"'                ;
DASH    :    '-'                ;
ALPHA    :    '@'                ;
DOT    :    '.'                ;
PLUS    :    '+'                ;
RPAREN    :    ')'                ;
LPAREN    :    '('                ;
COLON    :    ':'                ;
SEMI    :    ';'                ;


Testdata:
(MESSAGE
 :TOPIC "en"
 :PAGE 100
 :INITIALS "lmg"
 :REVISION 0
 :SOURCE "The Journalist"
 :CUSTOMER "The Customer"
 :TICKERS ("nyhe" "enov" "vind" "utby" "nor" "poli")
 :BYLINE "Anton Oter"
 :TIMESTAMP @2007-02-02T07:09:28.484+01
 :PRIORITY 2
 :TITLE "Some title"
 :BODY
 ("Line1"
  "Line2.")
 :SIGNATURE
 ("-- "
  "COMPANY"
  "Anton Oter"))


-- 
Med vennlig hilsen,
Alexander Brill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071130/408529d9/attachment.html 


More information about the antlr-interest mailing list