use of org.antlr.v4.runtime.CharStream in project jaybird by FirebirdSQL.
the class TestGrammar method createParser.
// TODO Add more testcases for grammar
protected JaybirdSqlParser createParser(String testString) {
CharStream stream = CharStreams.fromString(testString);
JaybirdSqlLexer lexer = new JaybirdSqlLexer(stream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
return new JaybirdSqlParser(tokenStream);
}
use of org.antlr.v4.runtime.CharStream in project ballerina by ballerina-lang.
the class ManifestProcessor method getManifest.
/**
* Get the manifest object by passing the ballerina toml file.
*
* @param charStream toml file content as a char stream
* @return manifest object
*/
private static Manifest getManifest(CharStream charStream) {
Manifest manifest = new Manifest();
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(new ManifestBuildListener(manifest), TomlProcessor.parseTomlContent(charStream));
return manifest;
}
use of org.antlr.v4.runtime.CharStream in project ballerina by ballerina-lang.
the class TomlProcessor method parseTomlContent.
/**
* Generate the proxy object by passing in the toml file.
*
* @param stream charstream object containing the content
* @return proxy object
*/
public static ParseTree parseTomlContent(CharStream stream) {
TomlLexer lexer = new TomlLexer(stream);
// Get a list of matched tokens
CommonTokenStream tokens = new CommonTokenStream(lexer);
// Pass the tokens to the parser
TomlParser parser = new TomlParser(tokens);
return parser.toml();
}
use of org.antlr.v4.runtime.CharStream in project titan.EclipsePlug-ins by eclipse.
the class ASN1ReferenceParser method parseReference.
private Reference parseReference(final IFile file, final String input, final int line, final int offset) {
Reference reference = null;
StringReader reader = new StringReader(input);
CharStream charStream = new UnbufferedCharStream(reader);
Asn1Lexer lexer = new Asn1Lexer(charStream);
lexer.setTokenFactory(new TokenWithIndexAndSubTokensFactory(true));
ASN1Listener lexerListener = new ASN1Listener();
// remove ConsoleErrorListener
lexer.removeErrorListeners();
lexer.addErrorListener(lexerListener);
ModuleLevelTokenStreamTracker tracker = new ModuleLevelTokenStreamTracker(lexer);
tracker.discard(Asn1Lexer.WS);
tracker.discard(Asn1Lexer.MULTILINECOMMENT);
tracker.discard(Asn1Lexer.SINGLELINECOMMENT);
Asn1Parser parser = new Asn1Parser(tracker);
parser.setProject(file.getProject());
parser.setActualFile(file);
parser.setLine(line);
parser.setOffset(offset);
parser.setBuildParseTree(false);
ASN1Listener parserListener = new ASN1Listener();
// remove ConsoleErrorListener
parser.removeErrorListeners();
parser.addErrorListener(parserListener);
reference = parser.pr_parseReference().reference;
return reference;
}
use of org.antlr.v4.runtime.CharStream in project titan.EclipsePlug-ins by eclipse.
the class ASN1Analyzer method parse.
@Override
public void parse(final IFile file, final String code) throws FileNotFoundException {
Reader reader = null;
if (code != null) {
reader = new StringReader(code);
} else if (file != null) {
try {
reader = new BufferedReader(new InputStreamReader(file.getContents(), file.getCharset()));
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace("Could not get the contents of `" + file.getName() + "'", e);
return;
}
} else {
return;
}
final CharStream charStream = new UnbufferedCharStream(reader);
final Asn1Lexer lexer = new Asn1Lexer(charStream);
lexer.setTokenFactory(new TokenWithIndexAndSubTokensFactory(true));
lexer.setActualFile(file);
lexerListener = new ASN1Listener();
// remove ConsoleErrorListener
lexer.removeErrorListeners();
lexer.addErrorListener(lexerListener);
final ModuleLevelTokenStreamTracker tracker = new ModuleLevelTokenStreamTracker(lexer);
tracker.discard(Asn1Lexer.WS);
tracker.discard(Asn1Lexer.MULTILINECOMMENT);
tracker.discard(Asn1Lexer.SINGLELINECOMMENT);
tracker.setActualFile(file);
final Asn1Parser parser = new Asn1Parser(tracker);
parser.setProject(file.getProject());
parser.setActualFile(file);
parser.setBuildParseTree(false);
parserListener = new ASN1Listener(parser);
// remove ConsoleErrorListener
parser.removeErrorListeners();
parser.addErrorListener(parserListener);
parser.pr_ASN1ModuleDefinition();
actualAsn1Module = parser.getModule();
warnings = parser.getWarnings();
unsupportedConstructs = parser.getUnsupportedConstructs();
try {
reader.close();
} catch (IOException e) {
}
}
Aggregations