use of st.gravel.support.compiler.ast.Statement in project gravel by gravel-st.
the class VariableToHolderRewriter method visitSequenceNode_.
@Override
public SequenceNode visitSequenceNode_(final SequenceNode _anObject) {
final List<VariableDeclarationNode>[] _found;
Statement[] _stmts;
final VariableDeclarationNode[] _temporaries;
_found = new List[1];
_found[0] = new java.util.ArrayList();
_stmts = st.gravel.support.jvm.ArrayExtensions.collect_(_anObject.statements(), ((st.gravel.support.jvm.Block1<Statement, Statement>) (new st.gravel.support.jvm.Block1<Statement, Statement>() {
@Override
public Statement value_(final Statement _each) {
return (Statement) VariableToHolderRewriter.this.visit_(_each);
}
})));
_temporaries = st.gravel.support.jvm.ArrayExtensions.collect_(_anObject.temporaries(), ((st.gravel.support.jvm.Block1<VariableDeclarationNode, VariableDeclarationNode>) (new st.gravel.support.jvm.Block1<VariableDeclarationNode, VariableDeclarationNode>() {
@Override
public VariableDeclarationNode value_(final VariableDeclarationNode _each) {
VariableDeclarationNode _newDecl;
if (st.gravel.support.jvm.StringExtensions.equals_(_each.name(), _varName)) {
_found[0].add(_each);
_newDecl = HolderDeclarationNode.factory.name_type_(_each.name(), ((TypeNode) VariableToHolderRewriter.this.visit_(_each.type())));
} else {
_newDecl = ((VariableDeclarationNode) VariableToHolderRewriter.this.visit_(_each));
}
return (VariableDeclarationNode) _newDecl;
}
})));
if (_found[0].size() != 0) {
_stmts = st.gravel.support.jvm.ArrayExtensions.copyWithFirst_(_stmts, AssignmentNode.factory.variable_value_(VariableNode.factory.name_(_varName), CreateHolderNode.factory.basicNew()));
}
return SequenceNode.factory.temporaries_statements_(_temporaries, _stmts);
}
use of st.gravel.support.compiler.ast.Statement in project gravel by gravel-st.
the class ParserTest method testParseKeywordBinaryUnaryExpression2.
@Test
public void testParseKeywordBinaryUnaryExpression2() {
final Statement _node;
_node = Parser.factory.source_("2 bar foo: 7 bar: 4 baz foo: 2 + 1 boo: 3 foo + 2 roo: 3 + 2 foo noo: 3 hoo + 2 joo").parseExpression();
assertTrue(st.gravel.support.jvm.ObjectExtensions.equals_(_node.factory(), KeywordMessageNode.factory));
assertEquals((String) "2 bar\n\tfoo: 7\n\tbar: 4 baz\n\tfoo: 2 + 1\n\tboo: 3 foo + 2\n\troo: 3 + 2 foo\n\tnoo: 3 hoo + 2 joo", (String) _node.prettySourceString());
}
use of st.gravel.support.compiler.ast.Statement in project gravel by gravel-st.
the class ParserTest method testParseBinaryExpression.
@Test
public void testParseBinaryExpression() {
final Statement _node;
_node = Parser.factory.source_(" 3 + 7 ").parseExpression();
assertTrue(st.gravel.support.jvm.ObjectExtensions.equals_(_node.factory(), BinaryMessageNode.factory));
assertEquals((String) "3 + 7", (String) _node.prettySourceString());
}
use of st.gravel.support.compiler.ast.Statement in project gravel by gravel-st.
the class ParserTest method testParseReturn.
@Test
public void testParseReturn() {
final Statement _node;
_node = Parser.factory.source_("[:a | ^a]").parseExpression();
assertTrue(st.gravel.support.jvm.ObjectExtensions.equals_(_node.factory(), BlockNode.factory));
assertEquals((String) "[:a | ^a]", (String) _node.prettySourceString());
}
use of st.gravel.support.compiler.ast.Statement in project gravel by gravel-st.
the class ParserTest method testParseNestedExpression.
@Test
public void testParseNestedExpression() {
final Statement _node;
_node = Parser.factory.source_(" 3 + (4 + 5) ").parseExpression();
assertTrue(st.gravel.support.jvm.ObjectExtensions.equals_(_node.factory(), BinaryMessageNode.factory));
assertEquals((String) "3 + (4 + 5)", (String) _node.prettySourceString());
}
Aggregations