[antlr-interest] Fixed field
Brian Lavender
brian at brie.com
Thu Jul 29 18:07:40 PDT 2010
Well, it looks like my attempt isn't so feeble, but I can't seem to get the input to
match on the newline. Do I need to do something different?
grammar Agenda;
agenda : bill+;
bill : title author '\n' { System.out.println($bill.text); }
;
author : LTR LTR LTR LTR LTR LTR LTR LTR LTR { System.out.println($author.text); };
title : LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR { System.out.println($title.text); };
LTR : ('a'..'z'|'A'..'Z' | ' ' | '1'..'9') ;
Input is the following.
Bill to allow eBill Joy
Bill to preventFrank Dist
On Mon, Jul 26, 2010 at 08:27:41PM -0700, Brian Lavender wrote:
> What's the best way to get the words out of a fixed field file? Say the title
> is in the first 20 columns, and then the author is in the next 20?
>
> Below is a feeble attempt that will get four letters, but I would like to ignore
> any whitespace that occurs after the last letter before the end column.
>
> brian
>
>
> grammar Foo;
>
> title : LTR LTR LTR LTR '\n'{System.out.println($title.text);};
>
> LTR : ('a'..'z'|'A'..'Z');
>
> --
> Brian Lavender
> http://www.brie.com/brian/
>
> "There are two ways of constructing a software design. One way is to
> make it so simple that there are obviously no deficiencies. And the other
> way is to make it so complicated that there are no obvious deficiencies."
>
> Professor C. A. R. Hoare
> The 1980 Turing award lecture
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
Brian Lavender
http://www.brie.com/brian/
"There are two ways of constructing a software design. One way is to
make it so simple that there are obviously no deficiencies. And the other
way is to make it so complicated that there are no obvious deficiencies."
Professor C. A. R. Hoare
The 1980 Turing award lecture
More information about the antlr-interest
mailing list