-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
defs #6
defs #6
Conversation
@@ -134,6 +134,18 @@ Rule MultiplyExpression() { | |||
); | |||
} | |||
|
|||
Rule Program() { | |||
return Sequence(push(nodeFactory.emptyDeclarationsList()), Declarations(), Expression(), push(nodeFactory.program(pop(1), pop()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hopefully fixed
import static pl.allegro.tech.opel.OpelEngineBuilder.create | ||
import static pl.allegro.tech.opel.TestUtil.functions | ||
|
||
class OpelEngineDefinitionsIntegrationSpec extends Specification { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice tests
@@ -19,7 +19,7 @@ | |||
} | |||
|
|||
Rule ParsingUnit() { | |||
return Sequence(WhiteSpace(), Expression(), EOI); | |||
return Sequence(WhiteSpace(), Program(), EOI); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First step towards something more than simple expression language :) +1
|
||
class OpelEngineDefinitionsIntegrationSpec extends Specification { | ||
|
||
def "should parse and evaluate expression with definitions (#input)"() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add @Unroll
here and below or remove #input
.
@@ -66,6 +66,7 @@ opel supports: | |||
- simple list element access (i.e. `list[index]`) | |||
- object method calls (i.e. `'Hello, World!'.length()`) | |||
- if expressions (i.e. `if (2 > 3) 'a' else 'b'`) | |||
- defining local final variables (i.e. `def x = 2+2*2; x * x`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"local final variables" sounds like value, what about val instead of def?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def
sound good for me (because of Groovy :)
@@ -66,6 +66,7 @@ opel supports: | |||
- simple list element access (i.e. `list[index]`) | |||
- object method calls (i.e. `'Hello, World!'.length()`) | |||
- if expressions (i.e. `if (2 > 3) 'a' else 'b'`) | |||
- defining local final variables (i.e. `def x = 2+2*2; x * x`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change is in conflict with "What opel can't do?" section of this readme :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's my biggest gripe, do we change the vision?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should, each non-braking feature - MINOR ++
http://semver.org/
} | ||
|
||
Rule Declaration() { | ||
return Sequence("def ", Identifier(), "= ", Expression(), "; ", push(nodeFactory.declarationsList(pop(2), pop(1), pop()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about new line instead semicolon?
} | ||
|
||
@Override | ||
public CompletableFuture<?> getValue(EvalContext context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in grammar you add Declarations beside Expression so DeclarationExpressionNode should not implements ExpressionNode (Declaration is not an Expression) and problem with this UnsupportedOperationException disappear :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that parser needs a single node type to work with, and not all nodes will have values. I will try to improve it.
where: | ||
input || expResult | ||
"def one=1;one" || 1 | ||
"def two=1+1;two + 1" || 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expResult is 1, 3, 4, 5. Where is 2 :)
"def two=1+1; def three = two +1; three + 1" || 4 | ||
"def condition=1==1; if(condition) 5 else 6" || 5 | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add empty line
"def condition=1==1; if(condition) 5 else 6" || 5 | ||
|
||
} | ||
def "should end with error when circular definitions are found in #input"() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this test you check circular definitions. Where is test of declaration order:
def a = b;
def b = 1;
a + b
is it ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undefined variable b (in line 1). It's the same case as circular dependency
import java.util.*; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class ProgramExpressionNode implements ExpressionNode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the question is whether the program is an expression or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, I think I will intruduce OpelNode instead
"def condition=1==1; if(condition) 5 else 6" || 5 | ||
|
||
} | ||
def "should end with error when circular definitions are found in #input"() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and add specification of conflict case when some value is defined in context and manually by def keyword. It is an error or which declaration has higher priority?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that def's override registered variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few things to improve and discuss
Defs -> vals
Refactor updatedContext method in ProgramNode class
No description provided.