Package org.apache.camel.language.simple.ast

Examples of org.apache.camel.language.simple.ast.SimpleNode


    protected void parseTokensAndCreateNodes() {
        // we loop the tokens and create a sequence of ast nodes

        // we need to keep a bit of state for keeping track of single and double quotes
        // which need to be balanced and have matching start/end pairs
        SimpleNode lastSingle = null;
        SimpleNode lastDouble = null;
        SimpleNode lastFunction = null;
        AtomicBoolean startSingle = new AtomicBoolean(false);
        AtomicBoolean startDouble = new AtomicBoolean(false);
        AtomicBoolean startFunction = new AtomicBoolean(false);

        LiteralNode imageToken = null;
        for (SimpleToken token : tokens) {
            // break if eol
            if (token.getType().isEol()) {
                break;
            }

            // create a node from the token
            SimpleNode node = createNode(token, startSingle, startDouble, startFunction);
            if (node != null) {
                // keep state of last single/double
                if (node instanceof SingleQuoteStart) {
                    lastSingle = node;
                } else if (node instanceof DoubleQuoteStart) {
View Full Code Here


            return null;
        }

        // okay so far we also want to support quotes
        if (token.getType().isSingleQuote()) {
            SimpleNode answer;
            boolean start = startSingle.get();
            if (!start) {
                answer = new SingleQuoteStart(token);
            } else {
                answer = new SingleQuoteEnd(token);
            }
            // flip state on start/end flag
            startSingle.set(!start);
            return answer;
        } else if (token.getType().isDoubleQuote()) {
            SimpleNode answer;
            boolean start = startDouble.get();
            if (!start) {
                answer = new DoubleQuoteStart(token);
            } else {
                answer = new DoubleQuoteEnd(token);
View Full Code Here

     * graph of nodes which represent the input expression.
     */
    private void prepareBinaryExpressions() {
        Stack<SimpleNode> stack = new Stack<SimpleNode>();

        SimpleNode left = null;
        for (int i = 0; i < nodes.size(); i++) {
            if (left == null) {
                left = i > 0 ? nodes.get(i - 1) : null;
            }
            SimpleNode token = nodes.get(i);
            SimpleNode right = i < nodes.size() - 1 ? nodes.get(i + 1) : null;

            if (token instanceof BinaryExpression) {
                BinaryExpression binary = (BinaryExpression) token;

                // remember the binary operator
                String operator = binary.getOperator().toString();

                if (left == null) {
                    throw new SimpleParserException("Binary operator " + operator + " has no left hand side token", token.getToken().getIndex());
                }
                if (!binary.acceptLeftNode(left)) {
                    throw new SimpleParserException("Binary operator " + operator + " does not support left hand side token " + left.getToken(), token.getToken().getIndex());
                }
                if (right == null) {
                    throw new SimpleParserException("Binary operator " + operator + " has no right hand side token", token.getToken().getIndex());
                }
                if (!binary.acceptRightNode(right)) {
                    throw new SimpleParserException("Binary operator " + operator + " does not support right hand side token " + right.getToken(), token.getToken().getIndex());
                }

                // pop previous as we need to replace it with this binary operator
                stack.pop();
                stack.push(token);
View Full Code Here

     * graph of nodes which represent the input expression.
     */
    private void prepareLogicalExpressions() {
        Stack<SimpleNode> stack = new Stack<SimpleNode>();

        SimpleNode left = null;
        for (int i = 0; i < nodes.size(); i++) {
            if (left == null) {
                left = i > 0 ? nodes.get(i - 1) : null;
            }
            SimpleNode token = nodes.get(i);
            SimpleNode right = i < nodes.size() - 1 ? nodes.get(i + 1) : null;

            if (token instanceof LogicalExpression) {
                LogicalExpression logical = (LogicalExpression) token;

                // remember the logical operator
View Full Code Here

    protected void parseTokensAndCreateNodes() {
        // we loop the tokens and create a sequence of ast nodes

        // we need to keep a bit of state for keeping track of single and double quotes
        // which need to be balanced and have matching start/end pairs
        SimpleNode lastSingle = null;
        SimpleNode lastDouble = null;
        SimpleNode lastFunction = null;
        AtomicBoolean startSingle = new AtomicBoolean(false);
        AtomicBoolean startDouble = new AtomicBoolean(false);
        AtomicBoolean startFunction = new AtomicBoolean(false);

        LiteralNode imageToken = null;
        for (SimpleToken token : tokens) {
            // break if eol
            if (token.getType().isEol()) {
                break;
            }

            // create a node from the token
            SimpleNode node = createNode(token, startSingle, startDouble, startFunction);
            if (node != null) {
                // keep state of last single/double
                if (node instanceof SingleQuoteStart) {
                    lastSingle = node;
                } else if (node instanceof DoubleQuoteStart) {
View Full Code Here

            return null;
        }

        // okay so far we also want to support quotes
        if (token.getType().isSingleQuote()) {
            SimpleNode answer;
            boolean start = startSingle.get();
            if (!start) {
                answer = new SingleQuoteStart(token);
            } else {
                answer = new SingleQuoteEnd(token);
            }
            // flip state on start/end flag
            startSingle.set(!start);
            return answer;
        } else if (token.getType().isDoubleQuote()) {
            SimpleNode answer;
            boolean start = startDouble.get();
            if (!start) {
                answer = new DoubleQuoteStart(token);
            } else {
                answer = new DoubleQuoteEnd(token);
View Full Code Here

     * graph of nodes which represent the input expression.
     */
    private void prepareBinaryExpressions() {
        Stack<SimpleNode> stack = new Stack<SimpleNode>();

        SimpleNode left = null;
        for (int i = 0; i < nodes.size(); i++) {
            if (left == null) {
                left = i > 0 ? nodes.get(i - 1) : null;
            }
            SimpleNode token = nodes.get(i);
            SimpleNode right = i < nodes.size() - 1 ? nodes.get(i + 1) : null;

            if (token instanceof BinaryExpression) {
                BinaryExpression binary = (BinaryExpression) token;

                // remember the binary operator
                String operator = binary.getOperator().toString();

                if (left == null) {
                    throw new SimpleParserException("Binary operator " + operator + " has no left hand side token", token.getToken().getIndex());
                }
                if (!binary.acceptLeftNode(left)) {
                    throw new SimpleParserException("Binary operator " + operator + " does not support left hand side token " + left.getToken(), token.getToken().getIndex());
                }
                if (right == null) {
                    throw new SimpleParserException("Binary operator " + operator + " has no right hand side token", token.getToken().getIndex());
                }
                if (!binary.acceptRightNode(right)) {
                    throw new SimpleParserException("Binary operator " + operator + " does not support right hand side token " + right.getToken(), token.getToken().getIndex());
                }

                // pop previous as we need to replace it with this binary operator
                stack.pop();
                stack.push(token);
View Full Code Here

     * graph of nodes which represent the input expression.
     */
    private void prepareLogicalExpressions() {
        Stack<SimpleNode> stack = new Stack<SimpleNode>();

        SimpleNode left = null;
        for (int i = 0; i < nodes.size(); i++) {
            if (left == null) {
                left = i > 0 ? nodes.get(i - 1) : null;
            }
            SimpleNode token = nodes.get(i);
            SimpleNode right = i < nodes.size() - 1 ? nodes.get(i + 1) : null;

            if (token instanceof LogicalExpression) {
                LogicalExpression logical = (LogicalExpression) token;

                // remember the logical operator
View Full Code Here

            if (token.getType().isEol()) {
                break;
            }

            // create a node from the token
            SimpleNode node = createNode(token);
            if (node != null) {
                // a new token was created so the current image token need to be added first
                if (imageToken != null) {
                    nodes.add(imageToken);
                    imageToken = null;
View Full Code Here

    protected void parseTokensAndCreateNodes() {
        // we loop the tokens and create a sequence of ast nodes

        // we need to keep a bit of state for keeping track of single and double quotes
        // which need to be balanced and have matching start/end pairs
        SimpleNode lastSingle = null;
        SimpleNode lastDouble = null;
        SimpleNode lastFunction = null;
        AtomicBoolean startSingle = new AtomicBoolean(false);
        AtomicBoolean startDouble = new AtomicBoolean(false);
        AtomicBoolean startFunction = new AtomicBoolean(false);

        LiteralNode imageToken = null;
        for (SimpleToken token : tokens) {
            // break if eol
            if (token.getType().isEol()) {
                break;
            }

            // create a node from the token
            SimpleNode node = createNode(token, startSingle, startDouble, startFunction);
            if (node != null) {
                // keep state of last single/double
                if (node instanceof SingleQuoteStart) {
                    lastSingle = node;
                } else if (node instanceof DoubleQuoteStart) {
View Full Code Here

TOP

Related Classes of org.apache.camel.language.simple.ast.SimpleNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.