Skip to content
Snippets Groups Projects
RelAstBase.parser 2.21 KiB
Program goal = 
	type_decls.t relations.r {: return new Program(t, r); :}
	| STRING_LITERAL STAR {: return new Program(); :}
	;

List type_decls =
	/* empty */ {: return new List(); :}
	| type_decls.l type_decl.d {: return l.add(d); :}
	;

TypeDecl type_decl =
	ID type_decl_super.s components_opt.c SCOL 
	{: return new TypeDecl(ID, false, s, c); :}
	| ABSTRACT ID type_decl_super.s components_opt.c SCOL 
	{: return new TypeDecl(ID, true, s, c); :}
	;

Opt type_decl_super =
	/* empty */ {: return new Opt(); :}
	| COL type_use.u {: return new Opt(u); :}
	;

TypeUse type_use =
	ID {: return new TypeUse(ID); :}
	;

List components_opt =
	/* empty */ {: return new List(); :}
	| ASSIGN components.l {: return l; :}
	;

List components =
	{: return new List(); :}
	| components.l component.c {: return l.add(c); :}
	;

Component component =
	ID COL type_use.u {: return new NormalComponent(ID, u); :}
	| type_use.u {: return new NormalComponent(u.getID(), u); :}
	// List
	| ID COL type_use.u STAR {: return new ListComponent(ID, u); :}
	| type_use.u STAR {: return new ListComponent(u.getID(), u); :}
	// Opt
	| ID COL type_use.u QUESTION_MARK {: return new OptComponent(ID, u); :}
	| type_use.u QUESTION_MARK {: return new OptComponent(u.getID(), u); :}
	// Token
	| LT ID COL type_use.u GT {: return new TokenComponent(ID, u); :}
	| LT ID GT {: return new TokenComponent(ID, new TypeUse("String")); :}
	;

List relations =
	/* empty */ {: return new List(); :}
	| relations.l relation.r {: return l.add(r); :}
	;

Relation relation =
	RELATION relation_comp.l direction relation_comp.r SCOL
	{: return new Relation(l, direction, r); :}
	;

RelationComponent relation_comp =
	// One
	type_use.u DOT ID {: return new OneRelationComponent(ID, u); :}
	| type_use.u {: return new OneRelationComponent("", u); :}
	// Optional
	| type_use.u DOT ID QUESTION_MARK {: return new OptionalRelationComponent(ID, u); :}
	| type_use.u QUESTION_MARK {: return new OptionalRelationComponent("", u); :}
	// Many
	| type_use.u DOT ID STAR {: return new ManyRelationComponent(ID, u); :}
	| type_use.u STAR {: return new ManyRelationComponent("", u); :}
	;

Direction direction =
	RIGHT {: return new RightDirection(); :}
	| BIDIRECTIONAL {: return new Bidirectional(); :}
	;