I have the following ABNF rule for string definition.
STRING = ALPHA *(allowedchar)
allowedchar = "-" / "_" / DIGIT / ALPHA
ALPH = A-Z ,a-z
Valid tokens:
aa1
a_1___a
a23
a
a-1
a_a
(if first char is alpha, then reset can be any char form 'allowedchar')
Invalid tokens:
-e
--
-1
-a
--1
--a
1
(doesn't starts with Alphabets).
So far, I have the grammar works for all the inputs(both valid and invalid) except "--a"
and "__a"
.
ANTL4 accepts this token as valid strings.
I am not sure why this is not working.
My Grammar
STRING : ALPHANUMERIC
ALPHA : [a-zA-Z]+ ;
fragment ALPHANUMERIC : ALPHA (ALLOWEDATTCHAR)* ;
fragment ALLOWEDATTCHAR : '-' | '_' | [0-9] | ALPHA ;