Hi,
I'd like to parse some fairly simple string, basically an ORDER BY clause. However, when I parse the input string "ORDER BY id ASC, name DESC", I get these error messages/warnings:
line 1:6 extraneous input 'BY' expecting {'AS', WS}
line 1:9 extraneous input 'id' expecting {'AS', WS}
line 1:12 extraneous input 'ASC' expecting {'AS', WS}
line 1:16 extraneous input ' ' expecting ID
line 1:22 extraneous input 'DESC' expecting {'AS', WS}
My grammar (AntLR 4) is below. Glad about any response.
Thanks,
Jochen
grammar OrderBy;
orderType
: ( DESCENDING | ASCENDING | DESC | ASC )?
;
orderBy
: ( ORDER WS+ BY)? propertyReference (typeCast)? orderType?
(COMMA propertyReference (typeCast)? orderType?)*
;
typeCast
: WS+ 'AS' ID
;
propertyReference
: ID (DOT ID)*
;
ID
: ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')*
;
WS: [ \n\t\r];
ORDER
: 'ORDER'
;
BY
: 'BY'
;
DESCENDING
: 'DESCENDING'
;
ASCENDING
: 'ASCENDING'
;
DESC
: 'DESC'
;
ASC
: 'ASC'
;
COMMA
: ','
;
DOT
: '.'
;