Skip to content

Commit

Permalink
Fixing bug on parsing of qualified names with more than 2 level nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
etirelli committed Nov 23, 2016
1 parent fe6e7c3 commit bfce0a2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,18 @@ interval
qualifiedName
@init {
String name = null;
int count = 0;
}
: n1=nameRef { name = getOriginalText( $n1.ctx ); } ( '.' {helper.recoverScope( name );} n2=nameRef {name=getOriginalText( $n2.ctx ); helper.dismissScope();} )*
@after {
for( int i = 0; i < count; i++ )
helper.dismissScope();
}
: n1=nameRef { name = getOriginalText( $n1.ctx ); }
( '.'
{helper.recoverScope( name ); count++;}
n2=nameRef
{name=getOriginalText( $n2.ctx );}
)*
;

nameRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,35 @@ public void testNestedContexts() {
assertThat( address.getEntries().get( 1 ).getName().getText(), is("city") );
}

@Test
public void testNestedContexts2() {
String inputExpression = "{ an applicant : { "
+ " home address : {"
+ " street name: \"broadway st\","
+ " city : \"New York\" "
+ " } "
+ " },\n "
+ " street : an applicant.home address.street name \n"
+ "}";
BaseNode ctxbase = parse( inputExpression );

assertThat( ctxbase, is( instanceOf( ContextNode.class ) ) );
assertThat( ctxbase.getText(), is( inputExpression ) );

ContextNode ctx = (ContextNode) ctxbase;
assertThat( ctx.getEntries().size(), is( 2 ) );

ContextEntryNode entry = ctx.getEntries().get( 1 );
assertThat( entry.getName(), is( instanceOf( NameDefNode.class ) ) );
NameDefNode name = (NameDefNode) entry.getName();
assertThat( name.getText(), is("street") );
assertThat( entry.getValue(), is( instanceOf( QualifiedNameNode.class ) ) );
QualifiedNameNode qnn = (QualifiedNameNode) entry.getValue();
assertThat( qnn.getParts().get( 0 ).getText(), is("an applicant") );
assertThat( qnn.getParts().get( 1 ).getText(), is("home address") );
assertThat( qnn.getParts().get( 2 ).getText(), is("street name") );
}

@Test
public void testFunctionDefinition() {
String inputExpression = "{ is minor : function( person's age ) person's age < 21 }";
Expand Down

0 comments on commit bfce0a2

Please sign in to comment.