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

net.intelie.pipes.generated.PipesTokenManager Maven / Gradle / Ivy

There is a newer version: 0.25.5
Show newest version
package net.intelie.pipes.generated;

import net.intelie.pipes.ast.SourceLocation;
import net.intelie.pipes.util.PipesCharStream;

public interface PipesTokenManager {
    class Token extends net.intelie.pipes.generated.Token {
        public String fullCode;
        public int beginPos, endPos;

        public Token(String fullCode) {
            this.fullCode = fullCode;
        }
    }

    PipesCharStream stream();

    default Token copyToken(net.intelie.pipes.generated.Token token) {
        PipesCharStream stream = stream();
        Token myToken = new Token(stream.getInput());
        myToken.fullCode = stream.getInput();
        myToken.beginPos = stream.getBeginIndex();
        myToken.endPos = stream.getIndex();
        myToken.next = token.next;
        myToken.image = token.image;
        myToken.kind = token.kind;
        myToken.beginColumn = token.beginColumn;
        myToken.beginLine = token.beginLine;
        myToken.endColumn = token.endColumn;
        myToken.endLine = token.endLine;
        myToken.specialToken = token.specialToken;
        return myToken;
    }

    class Pipe extends PipeParserCoreTokenManager implements PipesTokenManager {
        private final PipesCharStream stream;

        public Pipe(PipesCharStream stream) {
            super(stream);
            this.stream = stream;
        }

        @Override
        public PipesCharStream stream() {
            return stream;
        }

        @Override
        protected Token jjFillToken() {
            return copyToken(super.jjFillToken());
        }
    }

    class Filter extends FilterParserCoreTokenManager implements PipesTokenManager {
        private final PipesCharStream stream;

        public Filter(PipesCharStream stream) {
            super(stream);
            this.stream = stream;
        }

        @Override
        public PipesCharStream stream() {
            return stream;
        }

        @Override
        protected Token jjFillToken() {
            return copyToken(super.jjFillToken());
        }
    }

    class Span extends TimeSpanParserCoreTokenManager implements PipesTokenManager {
        private final PipesCharStream stream;

        public Span(PipesCharStream stream) {
            super(stream);
            this.stream = stream;
        }

        @Override
        public PipesCharStream stream() {
            return stream;
        }

        @Override
        protected Token jjFillToken() {
            return copyToken(super.jjFillToken());
        }
    }

    static SourceLocation toFullLocation(Token token) {
        if ("".equals(token.image)) {
            return toLocation(token);
        } else {
            return new SourceLocation(toLocation(token), toLocationEnd(token));
        }
    }

    static SourceLocation toLocation(Token token) {
        return new SourceLocation(token.fullCode, token.beginPos, token.beginLine, token.beginColumn);
    }

    static SourceLocation toLocationBegin(Token token) {
        return toLocation((Token) token.next);
    }


    static SourceLocation toLocationEnd(Token token) {
        return new SourceLocation(token.fullCode, token.endPos + 1,
                token.endLine, token.endColumn);
    }

    static SourceLocation toLocationPoint(Token token) {
        return new SourceLocation(token.fullCode, token.endPos,
                token.endLine, token.endColumn);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy