Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Where is the recursive rule?
Where is the recursive rule? [message #945657] Mon, 15 October 2012 14:03 Go to next message
Alexey Romanov is currently offline Alexey RomanovFriend
Messages: 263
Registered: May 2010
Senior Member
I don't understand why I am getting this error:
Quote:

error(211): ../ru.focusmedia.fire.idl/src-gen/ru/focusmedia/fire/idl/parser/antlr/internal/InternalIDL.g:592:3: [fatal] rule ruleField has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.

with this grammar:
grammar ru.focusmedia.fire.idl.IDL with org.eclipse.xtext.xbase.Xbase

generate idl "http://www.focusmedia.ru/fire/idl/IDL"

// extended thrift with interfaces: replace services, allow references to interfaces in proxies and return types

Model:
	'package' name=QualifiedName
	imports+=Import*
	definitions+=Definition*;

Import:
	'import' importedNamespace=ImportName;

ImportName:
	QualifiedName '.*'?;

Definition:
	EnumDef | StructDef | InterfaceDef;

EnumDef:
	'enum' name=ValidID '{' enumConsts+=EnumConstDef* '}';

EnumConstDef:
	name=ValidID '=' id=INT ListSeparator?;

StructDef:
	'struct' name=ValidID '{' fields+=Field* '}';

	// absent requiredness is treated as "required"
Field:
	(id=FieldID)? (requiredness=Requiredness)? type=FieldType name=ValidID ('=' default=ConstValue) ListSeparator?;

FieldID:
	INT ':';

enum Requiredness:
	REQUIRED='required' | OPTIONAL='optional';

FieldType:
	{StructType} struct=[StructDef|QualifiedName] |
	{InterfaceType} '*' interface=[InterfaceDef|QualifiedName] |
	{BaseType} ('bool' | 'byte' | 'i16' | 'i32' | 'i64' | 'double' | 'string' | 'binary') |
	ContainerType;

ConstValue:
	literal=(XNumberLiteral | XBooleanLiteral | XStringLiteral) | ConstList | ConstMap;

ConstList:
	'[' elements+=ConstValue (ListSeparator? elements+=ConstValue)* ']';

ConstMap:
	'{' elements+=ConstMapElement (ListSeparator? elements+=ConstValue)* '}';

ConstMapElement:
	key=ConstValue ':' value=ConstValue;

ContainerType:
	{ListType} 'list' '<' elementType=FieldType '>' |
	{SetType} 'set' '<' elementType=FieldType '>' |
	{MapType} 'map' '<' keyType=FieldType ',' valueType=FieldType '>';

InterfaceDef:
	'interface' name=ValidID 'extends'
	(super+=[InterfaceDef|QualifiedName] (',' super+=[InterfaceDef|QualifiedName])*)?
	'{' methods+=MethodDecl* '}';

MethodDecl:
	(oneway?='oneway' | returnType=FieldType) name=ValidID '(' (args+=Field (','
	args+=Field)*) ')';

ListSeparator:
	',' | ';';

Field doesn't have any alternatives, and I can't see any place where I have left recursion. Am I missing something? In case it's useful, I've attached InternalIDL.g.
  • Attachment: InternalIDL.g
    (Size: 147.96KB, Downloaded 120 times)

[Updated on: Mon, 15 October 2012 14:07]

Report message to a moderator

Re: Where is the recursive rule? [message #945677 is a reply to message #945657] Mon, 15 October 2012 14:21 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Alternative 1,2 is this part: "type=FieldType" which references
FieldType, and a FieldType refers to a ContainerType, which in turn
references FieldType.

Regards
- henrik

On 2012-15-10 16:03, Alexey Romanov wrote:
> I don't understand why I am getting this error:
> Quote:
>> error(211):
>> ../ru.focusmedia.fire.idl/src-gen/ru/focusmedia/fire/idl/parser/antlr/internal/InternalIDL.g:592:3:
>> [fatal] rule ruleField has non-LL(*) decision due to recursive rule
>> invocations reachable from alts 1,2. Resolve by left-factoring or
>> using syntactic predicates or using backtrack=true option.
>
> with this grammar:
>
> grammar ru.focusmedia.fire.idl.IDL with org.eclipse.xtext.xbase.Xbase
>
> generate idl "http://www.focusmedia.ru/fire/idl/IDL"
>
> // extended thrift with interfaces: replace services, allow references
> to interfaces in proxies and return types
>
> Model:
> 'package' name=QualifiedName
> imports+=Import*
> definitions+=Definition*;
>
> Import:
> 'import' importedNamespace=ImportName;
>
> ImportName:
> QualifiedName '.*'?;
>
> Definition:
> EnumDef | StructDef | InterfaceDef;
>
> EnumDef:
> 'enum' name=ValidID '{' enumConsts+=EnumConstDef* '}';
>
> EnumConstDef:
> name=ValidID '=' id=INT ListSeparator?;
>
> StructDef:
> 'struct' name=ValidID '{' fields+=Field* '}';
>
> // absent requiredness is treated as "required"
> Field:
> (id=FieldID)? (requiredness=Requiredness)? type=FieldType
> name=ValidID ('=' default=ConstValue) ListSeparator?;
>
> FieldID:
> INT ':';
>
> enum Requiredness:
> REQUIRED='required' | OPTIONAL='optional';
>
> FieldType:
> {StructType} struct=[StructDef|QualifiedName] |
> {InterfaceType} '*' interface=[InterfaceDef|QualifiedName] |
> {BaseType} ('bool' | 'byte' | 'i16' | 'i32' | 'i64' | 'double' |
> 'string' | 'binary') |
> ContainerType;
>
> ConstValue:
> literal=(XNumberLiteral | XBooleanLiteral | XStringLiteral) |
> ConstList | ConstMap;
>
> ConstList:
> '[' elements+=ConstValue (ListSeparator? elements+=ConstValue)* ']';
>
> ConstMap:
> '{' elements+=ConstMapElement (ListSeparator?
> elements+=ConstValue)* '}';
>
> ConstMapElement:
> key=ConstValue ':' value=ConstValue;
>
> ContainerType:
> {ListType} 'list' '<' elementType=FieldType '>' |
> {SetType} 'set' '<' elementType=FieldType '>' |
> {MapType} 'map' '<' keyType=FieldType ',' valueType=FieldType '>';
>
> InterfaceDef:
> 'interface' name=ValidID 'extends'
> (super+=[InterfaceDef|QualifiedName] (','
> super+=[InterfaceDef|QualifiedName])*)?
> '{' methods+=MethodDecl* '}';
>
> MethodDecl:
> (oneway?='oneway' | returnType=FieldType) name=ValidID '('
> (args+=Field (','
> args+=Field)*) ')';
>
> ListSeparator:
> ',' | ';';
>
> Field doesn't have any alternatives, and I can't see any place where I
> have left recursion. Am I missing something?
Re: Where is the recursive rule? [message #945732 is a reply to message #945677] Mon, 15 October 2012 15:33 Go to previous messageGo to next message
Alexey Romanov is currently offline Alexey RomanovFriend
Messages: 263
Registered: May 2010
Senior Member
Thanks, I'll try to figure out how best to deal with it.
Re: Where is the recursive rule? [message #946364 is a reply to message #945732] Tue, 16 October 2012 06:37 Go to previous message
Alexey Romanov is currently offline Alexey RomanovFriend
Messages: 263
Registered: May 2010
Senior Member
The problem turned out actually to lie in ListSeparators. Replacing "ListSeparator?" with "ListSeparator" or "(=>ListSeparator?)" fixes it.
Previous Topic:Combining JvmModelInferrer with IGenerator
Next Topic:[xbase] narrow cross references for java based JvmTypes
Goto Forum:
  


Current Time: Tue Apr 23 14:02:50 GMT 2024

Powered by FUDForum. Page generated in 0.04897 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top