ID looks like an expression [message #1748524] |
Thu, 24 November 2016 00:00 |
Jonah Graham Messages: 416 Registered: June 2014 |
Senior Member |
|
|
I am working on creating an XText grammar and the supporting infrastructure for GNU Linker Scripts. This is for the Eclipse CDT project.
In the grammar 2+3, for example, depending on context, can either be an identifier or an expression:
For example, this is a valid file:
SECTIONS {
.out_name : {
file*.o(.text.*)
2+3(*)
symbol = 2+3;
}
}
The first 2+3 is a filename, so almost anything that can be a filename is allowed there. The second 2+3 is an expression to be assigned to symbol.
This is part of my xtext file. I am using ValidID for the places that an ID is needed (like symbol in example) and FilenameID for the file*.o, .text.* and * parts.
ValidID hidden():
ID | "MEMORY" | "o" | "org" | "l" | "len";
FilenameID hidden():
(ID | '*' | '?' | '^' | '!')+;
terminal ID:
('a'..'z' | 'A'..'Z' | '.' | '/' | '\\' | '$' | '_' | '~')
('a'..'z' | 'A'..'Z' | '.' | '/' | '\\' | '$' | '_' | '~' | '0'..'9' | '-' | '+' | ':' | '[' | ']')*;
This appears to work, but with warning from ANTLR on the FilenameID rule like this one:
Decision can match input such as "'^'" using multiple alternatives: 4, 6 As a result, alternative(s) 6 were disabled for that input
However, if I expand FilenameID to include all the symbols I need, which includes leading 0-9 + - then I get more warnings like the above from ANTLR, and I start getting parsing errors.
GNU ld solves this by using context lexing rules, but AFAIU for XText I should be doing this with datatype rules.
Any ideas? Thanks,
Jonah
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04831 seconds