Permalink
Browse files

Primitive in expressions

  • Loading branch information...
1 parent eec63b3 commit b399ddadac77867767c7a12fe27a03b46a34c23c @ajlopez committed Jun 24, 2012
@@ -70,18 +70,35 @@ public Node parseExpressionNode() throws ParserException, IOException, LexerExce
Node node = this.parseKeywordExpression();
List<Node> list = null;
- for (token = this.nextToken(); token != null && token.getType() == TokenType.SEPARATOR && token.getValue().equals("."); token = this.nextToken()) {
+ while (node != null && node instanceof PrimitiveNode) {
if (list == null) {
list = new ArrayList<Node>();
list.add(node);
}
node = this.parseKeywordExpression();
-
- if (node == null)
- break;
-
+ }
+
+ if (node == null && list.size() == 1)
+ return list.get(0);
+
+ if (list != null && node != null)
list.add(node);
+
+ if (node != null) {
+ for (token = this.nextToken(); token != null && token.getType() == TokenType.SEPARATOR && token.getValue().equals("."); token = this.nextToken()) {
+ if (list == null) {
+ list = new ArrayList<Node>();
+ list.add(node);
+ }
+
+ node = this.parseKeywordExpression();
+
+ if (node == null)
+ break;
+
+ list.add(node);
+ }
}
this.pushToken(token);
@@ -448,4 +448,24 @@ public void primitiveNode() throws ParserException, IOException, LexerException
assertNull(parser.parseExpressionNode());
}
+
+ @Test
+ public void primitiveNodeAndExpression() throws ParserException, IOException, LexerException {
+ Parser parser = new Parser("<primitive: 60> ^2");
+
+ Node node = parser.parseExpressionNode();
+
+ assertNotNull(node);
+ assertTrue(node instanceof CompositeExpressionNode);
+
+ CompositeExpressionNode cenode = (CompositeExpressionNode)node;
+
+ assertNotNull(cenode.getExpressions());
+ assertEquals(2, cenode.getExpressions().length);
+ assertTrue(cenode.getExpressions()[0] instanceof PrimitiveNode);
+
+ assertEquals(60, ((PrimitiveNode)cenode.getExpressions()[0]).getValue());
+
+ assertNull(parser.parseExpressionNode());
+ }
}

0 comments on commit b399dda

Please sign in to comment.