Search in sources :

Example 1 with NotNull

use of org.antlr.v4.runtime.misc.NotNull in project scheduler by btrplace.

the class MyCstrSpecVisitor method visitCall.

@Override
public FunctionCall visitCall(@NotNull CstrSpecParser.CallContext ctx) {
    List<Term> ps = ctx.term().stream().map(t -> (Term<?>) visit(t)).collect(Collectors.toList());
    Function f = resolveFunction(ctx.ID().getSymbol(), ps);
    FunctionCall.Moment m = FunctionCall.Moment.ANY;
    if (ctx.BEGIN() != null) {
        m = FunctionCall.Moment.BEGIN;
    }
    return new FunctionCall(f, ps, m);
}
Also used : FunctionCall(org.btrplace.safeplace.spec.term.func.FunctionCall) org.btrplace.safeplace.spec.term(org.btrplace.safeplace.spec.term) CstrSpecParser(org.btrplace.safeplace.spec.antlr.CstrSpecParser) Function(org.btrplace.safeplace.spec.term.func.Function) Token(org.antlr.v4.runtime.Token) NotNull(org.antlr.v4.runtime.misc.NotNull) org.btrplace.safeplace.spec.prop(org.btrplace.safeplace.spec.prop) Collectors(java.util.stream.Collectors) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) ArrayList(java.util.ArrayList) List(java.util.List) org.btrplace.safeplace.spec.type(org.btrplace.safeplace.spec.type) ValueAt(org.btrplace.safeplace.spec.term.func.ValueAt) ParseTree(org.antlr.v4.runtime.tree.ParseTree) CstrSpecBaseVisitor(org.btrplace.safeplace.spec.antlr.CstrSpecBaseVisitor) Function(org.btrplace.safeplace.spec.term.func.Function) FunctionCall(org.btrplace.safeplace.spec.term.func.FunctionCall)

Example 2 with NotNull

use of org.antlr.v4.runtime.misc.NotNull in project scheduler by btrplace.

the class MyCstrSpecVisitor method visitTypedef.

@Override
public List<UserVar<?>> visitTypedef(@NotNull CstrSpecParser.TypedefContext ctx) {
    Term<?> parent = (Term<?>) visit(ctx.term());
    if (parent.type() instanceof Atomic) {
        throw new SpecException(filename, ctx.op.getCharPositionInLine(), "The right-hand side must be a collection");
    }
    List<UserVar<?>> vars = new ArrayList<>();
    for (TerminalNode n : ctx.ID()) {
        String lbl = n.getText();
        UserVar v = new UserVar(lbl, ctx.op.getText(), parent);
        symbols.put(v);
        vars.add(v);
    }
    return vars;
}
Also used : ArrayList(java.util.ArrayList) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode)

Example 3 with NotNull

use of org.antlr.v4.runtime.misc.NotNull in project redsnake by Taken0711.

the class TestUtils method parseProgram.

public static Program parseProgram(@NotNull String... s) {
    StringBuilder str = new StringBuilder();
    Arrays.stream(s).forEach(st -> str.append(st).append(System.lineSeparator()));
    CharStream inputStream = CharStreams.fromString(str.toString());
    RedsnakeLexer redsnakeLexer = new RedsnakeLexer(inputStream);
    TokenStream commonTokenStream = new CommonTokenStream(redsnakeLexer);
    RedsnakeParser parser = new RedsnakeParser(commonTokenStream);
    ParseTree t = parser.program();
    return (Program) new ASTBuilder().visit(t);
}
Also used : RedsnakeLexer(net.taken.redsnake.parser.RedsnakeLexer) RedsnakeParser(net.taken.redsnake.parser.RedsnakeParser) ASTBuilder(net.taken.redsnake.parser.visitors.ASTBuilder) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 4 with NotNull

use of org.antlr.v4.runtime.misc.NotNull in project vespa by vespa-engine.

the class ProgramParser method prepareParser.

private yqlplusParser prepareParser(String programName, CharStream input) {
    yqlplusLexer lexer = new yqlplusLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(new BaseErrorListener() {

        @Override
        public void syntaxError(@NotNull Recognizer<?, ?> recognizer, @Nullable Object offendingSymbol, int line, int charPositionInLine, @NotNull String msg, @Nullable RecognitionException e) {
            throw new ProgramCompileException(new Location(programName, line, charPositionInLine), msg);
        }
    });
    TokenStream tokens = new CommonTokenStream(lexer);
    yqlplusParser parser = new yqlplusParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(new BaseErrorListener() {

        @Override
        public void syntaxError(@NotNull Recognizer<?, ?> recognizer, @Nullable Object offendingSymbol, int line, int charPositionInLine, @NotNull String msg, @Nullable RecognitionException e) {
            throw new ProgramCompileException(new Location(programName, line, charPositionInLine), msg);
        }
    });
    parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
    return parser;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) TokenStream(org.antlr.v4.runtime.TokenStream) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) BaseErrorListener(org.antlr.v4.runtime.BaseErrorListener) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 5 with NotNull

use of org.antlr.v4.runtime.misc.NotNull in project titan.EclipsePlug-ins by eclipse.

the class TitanListener method syntaxError.

@Override
public void syntaxError(@NotNull final Recognizer<?, ?> recognizer, @Nullable final Object offendingSymbol, final int line, final int charPositionInLine, @NotNull final String msg, @Nullable final RecognitionException e) {
    SyntacticErrorStorage errorStorage;
    if (offendingSymbol instanceof CommonToken) {
        final CommonToken token = (CommonToken) offendingSymbol;
        errorStorage = new SyntacticErrorStorage(line, token.getStartIndex(), token.getStopIndex() + 1, msg, e);
    } else {
        errorStorage = new SyntacticErrorStorage(line, charPositionInLine, charPositionInLine + 1, msg, e);
    }
    errorsStored.add(errorStorage);
}
Also used : CommonToken(org.antlr.v4.runtime.CommonToken)

Aggregations

NotNull (org.antlr.v4.runtime.misc.NotNull)40 ATNState (org.antlr.v4.runtime.atn.ATNState)14 IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)14 DFAState (org.antlr.v4.runtime.dfa.DFAState)12 ParseTree (org.antlr.v4.runtime.tree.ParseTree)9 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)8 ArrayList (java.util.ArrayList)7 Token (org.antlr.v4.runtime.Token)7 RuleTransition (org.antlr.v4.runtime.atn.RuleTransition)4 DFA (org.antlr.v4.runtime.dfa.DFA)4 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)4 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)4 QuantifierAST (org.antlr.v4.tool.ast.QuantifierAST)4 List (java.util.List)3 ATN (org.antlr.v4.runtime.atn.ATN)3 BlockEndState (org.antlr.v4.runtime.atn.BlockEndState)3 Transition (org.antlr.v4.runtime.atn.Transition)3 WildcardTransition (org.antlr.v4.runtime.atn.WildcardTransition)3 Interval (org.antlr.v4.runtime.misc.Interval)3 Nullable (org.antlr.v4.runtime.misc.Nullable)3