You need to include the following rule at the end of your lexer. Without
wildcards, all allowed characters must appear in explicit rules.

ANY_CHAR : . ;

Sam

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of John Rossi
Sent: Tuesday, December 21, 2010 8:26 AM
To: [email protected]
Subject: [antlr-interest] Freeform Text Parsing


I plan to use ANTLR to parse generated (and hence predictable) English
sentences.  To verify that I know what I'm doing, I wanted to create a
grammar that parses a simple address book into an entry tree.

The following grammar is wrong, but it expresses my intent.  (~(NEWLINE))+
doesn't grab arbitrary non-newline text, but rather matches known,
non-newline tokens, which isn't what I want.  What's the right way?  Or is
ANTLR unsuitable for grammars that can't identify string literals at the
lexing stage?

John Rossi
Home
555-7293

Michael Raster
Work
555-8374

grammar AddressBook;
options {
output=AST;
ASTLabelType=CommonTree;
}

tokens {
ENTRIES;
ENTRY;
NAME;
CONTACTTYPE;
PHONE;
HOME;
WORK;
}

@header {
package org.roxton;
}

@lexer::header {
package org.roxton;
}

addressbook
:(entry (NEWLINE)?)+ -> ^(ENTRIES entry+); entry:name NEWLINE contactType
NEWLINE phone NEWLINE -> ^(ENTRY ^(NAME name) ^(CONTACTTYPE contactType)
^(PHONE phone)); name:(~(NEWLINE))+; contactType :('Home'->HOME |
'Work'->WORK); phone:(~(NEWLINE))+;

NEWLINE:'\r'? '\n' ;



      

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to