Search in sources :

Example 1 with PragmaNode

use of st.gravel.support.compiler.ast.PragmaNode in project gravel by gravel-st.

the class SourcePrinter method printPragmas_.

public SourcePrinter printPragmas_(final PragmaNode[] _pragmas) {
    for (final PragmaNode _each : _pragmas) {
        SourcePrinter.this.crtab_(_indentation);
        SourcePrinter.this.visit_(_each);
    }
    return this;
}
Also used : PragmaNode(st.gravel.support.compiler.ast.PragmaNode)

Example 2 with PragmaNode

use of st.gravel.support.compiler.ast.PragmaNode in project gravel by gravel-st.

the class MethodNode method primitiveIn_.

public String[] primitiveIn_(final String _className) {
    final PragmaNode _pragma;
    final Expression _argument;
    final ArrayLiteralNode _arrayNode;
    _pragma = this.primitivePragma();
    if (_pragma == null) {
        return null;
    }
    _argument = _pragma.expression().argument();
    if (_argument.isStringLiteralNode()) {
        return MethodNode.this.localPrimitiveIn_nameNode_(_className, ((StringLiteralNode) _argument));
    }
    if (!_argument.isArrayLiteralNode()) {
        return null;
    }
    _arrayNode = ((ArrayLiteralNode) _argument);
    return st.gravel.support.jvm.ArrayExtensions.collect_(_arrayNode.value(), ((st.gravel.support.jvm.Block1<String, Object>) (new st.gravel.support.jvm.Block1<String, Object>() {

        @Override
        public String value_(final Object _e) {
            final String _str;
            _str = ((String) _e);
            return (String) _str;
        }
    })));
}
Also used : PragmaNode(st.gravel.support.compiler.ast.PragmaNode) Expression(st.gravel.support.compiler.ast.Expression) ArrayLiteralNode(st.gravel.support.compiler.ast.ArrayLiteralNode) StringLiteralNode(st.gravel.support.compiler.ast.StringLiteralNode)

Example 3 with PragmaNode

use of st.gravel.support.compiler.ast.PragmaNode in project gravel by gravel-st.

the class MethodNode method pragmaPropertyAt_ifAbsent_.

public Object pragmaPropertyAt_ifAbsent_(final st.gravel.core.Symbol _aKey, final st.gravel.support.jvm.Block0<Object> _aBlock) {
    final Object _temp1 = new Object();
    try {
        final PragmaNode _pr;
        _pr = ((PragmaNode) st.gravel.support.jvm.ArrayExtensions.detect_ifNone_(_pragmas, new st.gravel.support.jvm.Predicate1<PragmaNode>() {

            @Override
            public boolean value_(final PragmaNode _each) {
                return _each.isPropertyPragmaAt_(_aKey);
            }
        }, ((st.gravel.support.jvm.Block0<PragmaNode>) (new st.gravel.support.jvm.Block0<PragmaNode>() {

            @Override
            public PragmaNode value() {
                throw new NonLocalReturn(_aBlock.value(), _temp1);
            }
        }))));
        return ((LiteralNode) _pr.expression().arguments()[1]).value();
    } catch (NonLocalReturn nlr) {
        if (nlr.marker == _temp1) {
            return (Object) nlr.returnValue;
        } else {
            throw nlr;
        }
    }
}
Also used : NilLiteralNode(st.gravel.support.compiler.ast.NilLiteralNode) LiteralNode(st.gravel.support.compiler.ast.LiteralNode) SymbolLiteralNode(st.gravel.support.compiler.ast.SymbolLiteralNode) StringLiteralNode(st.gravel.support.compiler.ast.StringLiteralNode) ArrayLiteralNode(st.gravel.support.compiler.ast.ArrayLiteralNode) PragmaNode(st.gravel.support.compiler.ast.PragmaNode) NonLocalReturn(st.gravel.support.jvm.NonLocalReturn)

Example 4 with PragmaNode

use of st.gravel.support.compiler.ast.PragmaNode in project gravel by gravel-st.

the class Parser method parseSequenceNode_.

public SequenceNode parseSequenceNode_(final st.gravel.support.jvm.Block1<Object, PragmaNode[]> _extraPragmaBlock) {
    VariableDeclarationNode[] _temporaries;
    Statement[] _statements;
    Statement _statement;
    final int _start;
    final PragmaNode[] _pragmas;
    _start = st.gravel.support.jvm.ReadStreamExtensions.position(_stream);
    this.eatWhitespace();
    _temporaries = new VariableDeclarationNode[] {};
    if (st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '|')) {
        Parser.this.eatWhitespace();
        boolean _temp1 = false;
        while (!_temp1) {
            _temp1 = st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '|');
            if (!_temp1) {
                Parser.this.eatWhitespace();
                _temporaries = st.gravel.support.jvm.ArrayExtensions.copyWith_(_temporaries, Parser.this.parseVariableDeclaration());
                Parser.this.eatWhitespace();
            }
        }
    }
    _pragmas = this.readPragmas();
    if (_pragmas.length != 0) {
        _extraPragmaBlock.value_(_pragmas);
    }
    _statements = new Statement[] {};
    _statement = this.parseStatement();
    this.eatWhitespace();
    boolean _temp2 = false;
    while (!_temp2) {
        _temp2 = _statement == null;
        if (!_temp2) {
            _statements = st.gravel.support.jvm.ArrayExtensions.copyWith_(_statements, _statement);
            st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '.');
            _statement = Parser.this.parseStatement();
            Parser.this.eatWhitespace();
        }
    }
    return ((SequenceNode) this.setSourcePosition_node_(_start, SequenceNode.factory.temporaries_statements_(_temporaries, _statements)));
}
Also used : PragmaNode(st.gravel.support.compiler.ast.PragmaNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) Statement(st.gravel.support.compiler.ast.Statement)

Example 5 with PragmaNode

use of st.gravel.support.compiler.ast.PragmaNode in project gravel by gravel-st.

the class UnaryMethodNode method returnTypeAndBodySourceOn_.

@Override
public UnaryMethodNode returnTypeAndBodySourceOn_(final StringBuilder _aStream) {
    if (_returnType != null) {
        _aStream.append(' ');
        _aStream.append("{^");
        _returnType.sourceOn_(_aStream);
        _aStream.append('}');
    }
    for (final PragmaNode _each : _pragmas) {
        _aStream.append('\n');
        _aStream.append(' ');
        _each.sourceOn_(_aStream);
    }
    _body.methodSourceOn_(_aStream);
    return this;
}
Also used : PragmaNode(st.gravel.support.compiler.ast.PragmaNode)

Aggregations

PragmaNode (st.gravel.support.compiler.ast.PragmaNode)12 BlockTypeNode (st.gravel.support.compiler.ast.BlockTypeNode)4 InstanceTypeNode (st.gravel.support.compiler.ast.InstanceTypeNode)4 SelfTypeNode (st.gravel.support.compiler.ast.SelfTypeNode)4 TypeNode (st.gravel.support.compiler.ast.TypeNode)4 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 SequenceNode (st.gravel.support.compiler.ast.SequenceNode)3 TypeCast (st.gravel.support.compiler.ast.TypeCast)3 ArrayLiteralNode (st.gravel.support.compiler.ast.ArrayLiteralNode)2 StringLiteralNode (st.gravel.support.compiler.ast.StringLiteralNode)2 BlockNode (st.gravel.support.compiler.ast.BlockNode)1 Expression (st.gravel.support.compiler.ast.Expression)1 LiteralNode (st.gravel.support.compiler.ast.LiteralNode)1 NilLiteralNode (st.gravel.support.compiler.ast.NilLiteralNode)1 Statement (st.gravel.support.compiler.ast.Statement)1 SymbolLiteralNode (st.gravel.support.compiler.ast.SymbolLiteralNode)1 NonLocalReturn (st.gravel.support.jvm.NonLocalReturn)1