Search in sources :

Example 21 with Statement

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);
}
Also used : Statement(st.gravel.support.compiler.ast.Statement) ArrayList(java.util.ArrayList) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) ArrayList(java.util.ArrayList) List(java.util.List) TypeNode(st.gravel.support.compiler.ast.TypeNode)

Example 22 with Statement

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());
}
Also used : Statement(st.gravel.support.compiler.ast.Statement) Test(org.junit.Test)

Example 23 with Statement

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());
}
Also used : Statement(st.gravel.support.compiler.ast.Statement) Test(org.junit.Test)

Example 24 with Statement

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());
}
Also used : Statement(st.gravel.support.compiler.ast.Statement) Test(org.junit.Test)

Example 25 with Statement

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());
}
Also used : Statement(st.gravel.support.compiler.ast.Statement) Test(org.junit.Test)

Aggregations

Statement (st.gravel.support.compiler.ast.Statement)34 Test (org.junit.Test)21 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)5 BinaryMessageNode (st.gravel.support.compiler.ast.BinaryMessageNode)3 Expression (st.gravel.support.compiler.ast.Expression)3 KeywordMessageNode (st.gravel.support.compiler.ast.KeywordMessageNode)3 MessageNode (st.gravel.support.compiler.ast.MessageNode)3 UnaryMessageNode (st.gravel.support.compiler.ast.UnaryMessageNode)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SequenceNode (st.gravel.support.compiler.ast.SequenceNode)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IntermediateStatement (st.gravel.support.compiler.ast.IntermediateStatement)1 PragmaNode (st.gravel.support.compiler.ast.PragmaNode)1 TypeNode (st.gravel.support.compiler.ast.TypeNode)1 VariableNode (st.gravel.support.compiler.ast.VariableNode)1 VariableScopeAnalyzerState (st.gravel.support.compiler.ast.VariableScopeAnalyzerState)1