From: niemisto Date: Tue, 12 Jan 2010 15:21:05 +0000 (+0000) Subject: collecting references in expression parser X-Git-Tag: simantics-1.0~104 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=da08fe0f75c62e3ff87de0562a63c27d5a87dcb9;p=simantics%2Fsysdyn.git collecting references in expression parser git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13487 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj index a4495209..285bfafb 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj @@ -10,6 +10,11 @@ import java.util.List; import java.util.ArrayList; public class ExpressionParser { + List> references = new ArrayList>(); + + public List> getReferences() { + return references; + } } PARSER_END(ExpressionParser) @@ -126,8 +131,10 @@ void primary() : { | | "false" | "true" - | LOOKAHEAD(2) name() function_call_args() - | component_reference() + | LOOKAHEAD( name() "(" ) name() function_call_args() + | { List reference = new ArrayList(); } + component_reference(reference) + { references.add(reference); } // | "(" output_expression_list() ")" // | "[" expression_list() { ";" expression_list() } "]" //| "{" function_arguments() "}" @@ -139,10 +146,11 @@ void name() : { ( "." name() )? } -void component_reference() : { +void component_reference(List reference) : { } { //IDENT [ array_subscripts ] [ "." component_reference ] - ( "." component_reference() )? + { reference.add(token.image); } + ( "." component_reference(reference) )? } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/TestExpressionParser.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/TestExpressionParser.java index 0eefa89b..91a3d247 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/TestExpressionParser.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/TestExpressionParser.java @@ -1,6 +1,7 @@ package org.simantics.sysdyn.expressionParser; import java.io.StringReader; +import java.util.List; public class TestExpressionParser { @@ -10,6 +11,9 @@ public class TestExpressionParser { ); try { parser.expr(); + for(List ref : parser.getReferences()) { + System.out.println(ref); + } } catch (ParseException e) { System.out.println("While parsing " + string + ":"); // TODO Auto-generated catch block