Search in sources :

Example 1 with Pr_UnifiedReferenceParserContext

use of org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Parser.Pr_UnifiedReferenceParserContext in project titan.EclipsePlug-ins by eclipse.

the class TTCN3ReferenceAnalyzer method parse.

/**
 * @return the parsed reference or null if the text can not form a reference
 */
public Reference parse(final IFile file, final String code, final boolean reportErrors, final int aLine, final int aOffset) {
    Reference reference = null;
    Reader reader = new StringReader(code);
    CharStream charStream = new UnbufferedCharStream(reader);
    Ttcn3Lexer lexer = new Ttcn3Lexer(charStream);
    lexer.setTokenFactory(new CommonTokenFactory(true));
    lexer.initRootInterval(code.length());
    lexer.removeErrorListeners();
    final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    Ttcn3Parser parser = new Ttcn3Parser(tokenStream);
    ParserUtilities.setBuildParseTree(parser);
    lexer.setActualFile(file);
    parser.setActualFile(file);
    parser.setProject(file.getProject());
    parser.setLine(aLine);
    parser.setOffset(aOffset);
    parser.removeErrorListeners();
    final Pr_UnifiedReferenceParserContext root = parser.pr_UnifiedReferenceParser();
    ParserUtilities.logParseTree(root, parser);
    reference = root.reference;
    return reference;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) CommonTokenFactory(org.antlr.v4.runtime.CommonTokenFactory) Pr_UnifiedReferenceParserContext(org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Parser.Pr_UnifiedReferenceParserContext) Reference(org.eclipse.titan.designer.AST.Reference) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream)

Example 2 with Pr_UnifiedReferenceParserContext

use of org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Parser.Pr_UnifiedReferenceParserContext in project titan.EclipsePlug-ins by eclipse.

the class TTCN3ReferenceAnalyzer method parseForCompletion.

/**
 * Parses the provided elements. If the contents of an editor are to be parsed,
 *  than the file parameter is only used to report the errors to.
 *
 * @param file the file to parse, and report the errors to
 * @param code the contents of an editor, or null.
 */
public Reference parseForCompletion(final IFile file, final String code) {
    Reference reference = null;
    Reader reader = new StringReader(code);
    CharStream charStream = new UnbufferedCharStream(reader);
    Ttcn3KeywordlessLexer lexer = new Ttcn3KeywordlessLexer(charStream);
    lexer.setTokenFactory(new CommonTokenFactory(true));
    lexer.initRootInterval(code.length());
    lexer.removeErrorListeners();
    final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    Ttcn3Parser parser = new Ttcn3Parser(tokenStream);
    ParserUtilities.setBuildParseTree(parser);
    lexer.setActualFile(file);
    parser.setActualFile(file);
    parser.setProject(file.getProject());
    parser.removeErrorListeners();
    final Pr_UnifiedReferenceParserContext root = parser.pr_UnifiedReferenceParser();
    ParserUtilities.logParseTree(root, parser);
    reference = root.reference;
    return reference;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) CommonTokenFactory(org.antlr.v4.runtime.CommonTokenFactory) Pr_UnifiedReferenceParserContext(org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Parser.Pr_UnifiedReferenceParserContext) Reference(org.eclipse.titan.designer.AST.Reference) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream)

Aggregations

Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 CharStream (org.antlr.v4.runtime.CharStream)2 CommonTokenFactory (org.antlr.v4.runtime.CommonTokenFactory)2 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)2 UnbufferedCharStream (org.antlr.v4.runtime.UnbufferedCharStream)2 Reference (org.eclipse.titan.designer.AST.Reference)2 Pr_UnifiedReferenceParserContext (org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Parser.Pr_UnifiedReferenceParserContext)2