Skip to content
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

Merged
merged 7 commits into from
Sep 23, 2016
Merged

defs #6

merged 7 commits into from
Sep 23, 2016

Conversation

rzukow
Copy link
Contributor

@rzukow rzukow commented Sep 20, 2016

No description provided.

@@ -134,6 +134,18 @@ Rule MultiplyExpression() {
);
}

Rule Program() {
return Sequence(push(nodeFactory.emptyDeclarationsList()), Declarations(), Expression(), push(nodeFactory.program(pop(1), pop())));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks confusing

Copy link
Contributor Author

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 {

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);

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)"() {

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`)
Copy link
Contributor

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?

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`)
Copy link
Contributor

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 :)

Copy link
Contributor

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?

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())));
Copy link
Contributor

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) {
Copy link
Contributor

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 :)

Copy link
Contributor Author

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
Copy link
Contributor

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

}
Copy link
Contributor

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"() {
Copy link
Contributor

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?

Copy link
Contributor Author

@rzukow rzukow Sep 21, 2016

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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"() {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@tfij tfij left a 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

@rzukow rzukow changed the base branch from master to defining_values September 23, 2016 12:13
@rzukow rzukow merged commit 6077b06 into allegro:defining_values Sep 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants