[antlr-interest] ANTLR Parsing Negation

colin gray cgswtsu78 at gmail.com
Fri Jan 20 11:17:43 PST 2012


Actually, the below is more representative of what I want to accomplish.

I'm using ANTLR 3.4 and I have the below rules in my .g file. I want to
create a different object other than SelectQueryInfo if $columns.a equals
`count(*)`, else create an instance of SelectQueryInfo. Any ideas?

    selectQuery returns [Info q]
        : ('select' | 'SELECT') columns
          ('from' | 'FROM') table
          (('where' | 'WHERE') filter_clause)?
          { $q = new SelectQueryInfo($columns.a, $table.e,
$filter_clause.e); }

     columns returns [ArrayList<String> a]
    : { $a = new ArrayList<String>(); }
      ('*' { $a.add("*"); }
      |
      ('count(*)' | 'COUNT(*)') { $a.add("count(*)"); }
      | c1 = COL { $a.add($c1.text); }
        (
        ',' c2 = COL { $a.add($c2.text); }
        )*
      )
    ;

On Fri, Jan 20, 2012 at 10:42 AM, colin gray <cgswtsu78 at gmail.com> wrote:

> Hello,
>
> I'm using ANTLR 3.4 and I have the below rule in my .g file.  I want to
> match text that has *select* or *SELECT* but excludes *select count(*)* and
> *SELECT COUNT(*)*.  So if the text was select count(*) from tablename where
> x=2 it would not create a new SelectQueryInfo.  I want to create a
> different object if count(*) exists in the text.  Any ideas?
>
>     selectQuery returns [Info q]
>         : ('select' | 'SELECT') columns
>           ('from' | 'FROM') table
>           (('where' | 'WHERE') filter_clause)?
>           { $q = new SelectQueryInfo($columns.a, $table.e,
> $filter_clause.e); }
>
>
> Thanks,
>
> CG
>



-- 
Colin Gray


More information about the antlr-interest mailing list