|
Re: Xtext parser rules overlap problem [message #1772569 is a reply to message #1772474] |
Tue, 12 September 2017 14:30 |
|
did you consider to do the same a xbase does (using '<''=' instead of '<='
OpCompare:
'>=' | '<' '=' | '>' | '<' ;
(to tame the lexer)
and predicates instead of backtracing for the parser e.g.
XConstructorCall returns XExpression:
{XConstructorCall}
'new' constructor=[types::JvmConstructor|QualifiedName]
(=>'<' typeArguments+=JvmArgumentTypeReference (',' typeArguments+=JvmArgumentTypeReference)* '>')?
(=>explicitConstructorCall?='('
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Xtext parser rules overlap problem [message #1772737 is a reply to message #1772569] |
Thu, 14 September 2017 14:00 |
Svilen Yanovski Messages: 3 Registered: September 2017 |
Junior Member |
|
|
Hi Christian,
Thank you for the advise regarding my problem. I've tried today to rewrite the lexer but unfortunately this is not solving the problem. Cases like "List<String> " are still causing clashes in the parser rules.
I'm parsing existing Java classes (not some custom language) with this program in order to build AST and i cannot change the parse rules really.
Regarding the backtracking - i'm using it in order to avoid left recursion in the lexer.
Regards,
Svilen
[Updated on: Thu, 14 September 2017 14:37] Report message to a moderator
|
|
|
Re: Xtext parser rules overlap problem [message #1772749 is a reply to message #1772737] |
Thu, 14 September 2017 17:23 |
|
you should still try to get rid of backtracking.
minimize your grammar to identify problems
FormalParameterList:
params+=FormalParameter (',' params+=FormalParameter)* (',' formalParam=LastFormalParameter)?
| LastFormalParameter
;
LastFormalParameter:
modifiers+=VariableModifier* type=Type '...' decl=VariableDeclaratorId
;
FormalParameter:
modifiers+=VariableModifier* type=Type decl=VariableDeclaratorId
;
VariableModifier:
{VariableModifier}
'final'
;
VariableDeclaratorId:
idName=ID ('[' ']')*
;
ClassOrInterfaceType:
ids+=ID args+=TypeArguments? ('.' ids+=ID args+=TypeArguments? )*
// QualifiedName
;
TypeArguments:
'<' args+=TypeArgument (',' args+=TypeArgument)* '>'
;
Type:
ClassOrInterfaceType ('[' ']')*
// | primitive=PRIMITIVE_TYPE ('[' ']')*
;
TypeArgument:
type=Type
| {TypeArgument} '?' (('extends' | 'super') boundedType=Type)?
;
adapt the wf to obtain a debug grammar to be used in antlr works
language = StandardLanguage {
name = "org.xtext.example.mydsl1.MyDsl"
fileExtensions = "mydsl1"
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
parserGenerator = {
debugGrammar = true
}
}
....
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.04282 seconds