All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kaazing.robot.lang.ast.builder.AstReadNodeBuilder Maven / Gradle / Ivy

/*
 * Copyright (c) 2014 "Kaazing Corporation," (www.kaazing.com)
 *
 * This file is part of Robot.
 *
 * Robot is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see .
 */

package org.kaazing.robot.lang.ast.builder;

import javax.el.ValueExpression;

import org.kaazing.robot.lang.ast.AstReadValueNode;
import org.kaazing.robot.lang.ast.AstStreamNode;
import org.kaazing.robot.lang.ast.matcher.AstExactBytesMatcher;
import org.kaazing.robot.lang.ast.matcher.AstExactTextMatcher;
import org.kaazing.robot.lang.ast.matcher.AstExpressionMatcher;
import org.kaazing.robot.lang.ast.matcher.AstFixedLengthBytesMatcher;
import org.kaazing.robot.lang.ast.matcher.AstRegexMatcher;
import org.kaazing.robot.lang.ast.matcher.AstVariableLengthBytesMatcher;
import org.kaazing.robot.lang.regex.NamedGroupPattern;

public class AstReadNodeBuilder extends AbstractAstStreamableNodeBuilder {

    private int line;

    public AstReadNodeBuilder() {
        this(new AstReadValueNode());
    }

    @Override
    public AstReadNodeBuilder setLocationInfo(int line, int column) {
        node.setLocationInfo(line, column);
        internalSetLineInfo(line);
        return this;
    }

    @Override
    public AstReadNodeBuilder setNextLineInfo(int linesToSkip, int column) {
        internalSetNextLineInfo(linesToSkip, column);
        return this;
    }

    public AstReadNodeBuilder addExactBytes(byte[] exactBytes) {
        node.addMatcher(new AstExactBytesMatcher(exactBytes));
        return this;
    }

    public AstReadNodeBuilder addExactText(String exactText) {
        node.addMatcher(new AstExactTextMatcher(exactText));
        return this;
    }

    public AstReadNodeBuilder addExpression(ValueExpression value) {
        node.addMatcher(new AstExpressionMatcher(value));
        return this;
    }

    public AstReadNodeBuilder addFixedLengthBytes(int length) {
        node.addMatcher(new AstFixedLengthBytesMatcher(length));
        return this;
    }

    public AstReadNodeBuilder addFixedLengthBytes(int length, String captureName) {
        node.addMatcher(new AstFixedLengthBytesMatcher(length, captureName));
        return this;
    }

    public AstReadNodeBuilder addRegex(NamedGroupPattern pattern) {
        node.addMatcher(new AstRegexMatcher(pattern));
        return this;
    }

    public AstReadNodeBuilder addVariableLengthBytes(ValueExpression length) {
        node.addMatcher(new AstVariableLengthBytesMatcher(length));
        return this;
    }

    public AstReadNodeBuilder addVariableLengthBytes(ValueExpression length, String captureName) {
        node.addMatcher(new AstVariableLengthBytesMatcher(length, captureName));
        return this;
    }

    @Override
    public AstReadValueNode done() {
        return result;
    }

    @Override
    protected int line() {
        return line;
    }

    @Override
    protected int line(int line) {
        this.line = line;
        return line;
    }

    private AstReadNodeBuilder(AstReadValueNode node) {
        super(node, node);
    }

    public static class StreamNested> extends
            AbstractAstStreamableNodeBuilder {

        public StreamNested(R builder) {
            super(new AstReadValueNode(), builder);
        }

        @Override
        public StreamNested setLocationInfo(int line, int column) {
            node.setLocationInfo(line, column);
            internalSetLineInfo(line);
            return this;
        }

        @Override
        public StreamNested setNextLineInfo(int linesToSkip, int column) {
            internalSetNextLineInfo(linesToSkip, column);
            return this;
        }

        public StreamNested addExactBytes(byte[] exactBytes) {
            node.addMatcher(new AstExactBytesMatcher(exactBytes));
            return this;
        }

        public StreamNested addExactText(String exactText) {
            node.addMatcher(new AstExactTextMatcher(exactText));
            return this;
        }

        public StreamNested addExpression(ValueExpression value) {
            node.addMatcher(new AstExpressionMatcher(value));
            return this;
        }

        public StreamNested addFixedLengthBytes(int length) {
            node.addMatcher(new AstFixedLengthBytesMatcher(length));
            return this;
        }

        public StreamNested addFixedLengthBytes(int length, String captureName) {
            node.addMatcher(new AstFixedLengthBytesMatcher(length, captureName));
            return this;
        }

        public StreamNested addRegex(NamedGroupPattern pattern) {
            node.addMatcher(new AstRegexMatcher(pattern));
            return this;
        }

        public StreamNested addVariableLengthBytes(ValueExpression length) {
            node.addMatcher(new AstVariableLengthBytesMatcher(length));
            return this;
        }

        public StreamNested addVariableLengthBytes(ValueExpression length, String captureName) {
            node.addMatcher(new AstVariableLengthBytesMatcher(length, captureName));
            return this;
        }

        @Override
        public R done() {
            AstStreamNode streamNode = result.node;
            streamNode.getStreamables().add(node);
            return result;
        }

        @Override
        protected int line() {
            return result.line();
        }

        @Override
        protected int line(int line) {
            return result.line(line);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy