use of org.antlr.v4.runtime.CommonTokenStream in project nikita-noark5-core by HiOA-ABI.
the class TestODataApp method main.
public static void main(String[] args) throws Exception {
System.out.println("Starting OData parser test");
System.out.println("Picks first line from odata_samples.txt in " + "resources folder.");
try {
AfterApplicationStartup afterApplicationStartup = new AfterApplicationStartup(null);
afterApplicationStartup.populateTranslatedNames();
TestODataApp app = new TestODataApp();
ODataLexer lexer = new ODataLexer(CharStreams.fromStream(app.getInputStreamForParseFile("odata" + File.separator + "odata_samples.txt")));
CommonTokenStream tokens = new CommonTokenStream(lexer);
ODataParser parser = new ODataParser(tokens);
ParseTree tree = parser.odataURL();
ParseTreeWalker walker = new ParseTreeWalker();
// Make the SQL Statement
NikitaODataToSQLWalker sqlWalker = new NikitaODataToSQLWalker();
walker.walk(sqlWalker, tree);
System.out.println(sqlWalker.getSqlStatement());
} catch (RecognitionException e) {
throw new IllegalStateException("Recognition exception");
}
}
use of org.antlr.v4.runtime.CommonTokenStream in project nikita-noark5-core by HiOA-ABI.
the class OdataTest method testOdata.
@RequestMapping(method = RequestMethod.GET, value = "arkivstruktur/{\\w*}")
public ResponseEntity<String> testOdata(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response) throws Exception {
String uqueryString = request.getQueryString();
String decoded = URLDecoder.decode(uqueryString, UTF_8);
StringBuffer originalRequest = request.getRequestURL();
originalRequest.append("?" + decoded);
CharStream stream = CharStreams.fromString(originalRequest.toString());
ODataLexer lexer = new ODataLexer(stream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ODataParser parser = new ODataParser(tokens);
ParseTree tree = parser.odataURL();
ParseTreeWalker walker = new ParseTreeWalker();
// Make the HQL Statement
NikitaODataToHQLWalker hqlWalker = new NikitaODataToHQLWalker();
walker.walk(hqlWalker, tree);
Session session = entityManager.unwrap(org.hibernate.Session.class);
Query query = hqlWalker.getHqlStatment(session);
String queryString = query.getQueryString();
System.out.println(queryString);
List<NoarkEntity> list = query.getResultList();
return ResponseEntity.status(HttpStatus.CREATED).body(list.toString());
}
use of org.antlr.v4.runtime.CommonTokenStream in project grakn by graknlabs.
the class TemplateParser method parseTemplate.
/**
* Parse and resolve a graql template.
* @param templateString a string representing a graql template
* @param data data to use in template
* @return resolved graql query string
*/
public String parseTemplate(String templateString, Map<String, Object> data) {
GraqlErrorListener errorListener = GraqlErrorListener.of(templateString);
CommonTokenStream tokens = lexGraqlTemplate(templateString, errorListener);
ParseTree tree = parseGraqlTemplate(tokens, errorListener);
TemplateVisitor visitor = new TemplateVisitor(tokens, data, macros);
return visitor.visit(tree).toString();
}
use of org.antlr.v4.runtime.CommonTokenStream in project drools by kiegroup.
the class FEELParser method parse.
public static FEEL_1_1Parser parse(FEELEventListenersManager eventsManager, String source, Map<String, Type> inputVariableTypes, Map<String, Object> inputVariables, Collection<FEELFunction> additionalFunctions, List<FEELProfile> profiles) {
ANTLRInputStream input = new ANTLRInputStream(source);
FEEL_1_1Lexer lexer = new FEEL_1_1Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
FEEL_1_1Parser parser = new FEEL_1_1Parser(tokens);
ParserHelper parserHelper = new ParserHelper(eventsManager);
additionalFunctions.forEach(f -> parserHelper.getSymbolTable().getBuiltInScope().define(f.getSymbol()));
profiles.stream().filter(KieExtendedFEELProfile.class::isInstance).forEach(dc -> parserHelper.setFeatDMN12EnhancedForLoopEnabled(true));
parser.setHelper(parserHelper);
parser.setErrorHandler(new FEELErrorHandler());
// removes the error listener that prints to the console
parser.removeErrorListeners();
parser.addErrorListener(new FEELParserErrorListener(eventsManager));
// pre-loads the parser with symbols
defineVariables(inputVariableTypes, inputVariables, parser);
return parser;
}
use of org.antlr.v4.runtime.CommonTokenStream in project JsoupXpath by zhegexiaohuozi.
the class JXDocument method selN.
public List<JXNode> selN(String xpath) throws XpathSyntaxErrorException {
List<JXNode> finalRes = new LinkedList<>();
try {
CharStream input = CharStreams.fromString(xpath);
XpathLexer lexer = new XpathLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
XpathParser parser = new XpathParser(tokens);
parser.setErrorHandler(new DoFailOnErrorHandler());
ParseTree tree = parser.main();
XpathProcessor processor = new XpathProcessor(elements);
XValue calRes = processor.visit(tree);
if (calRes.isElements()) {
for (Element el : calRes.asElements()) {
finalRes.add(JXNode.e(el));
}
} else if (calRes.isList()) {
for (String str : calRes.asList()) {
finalRes.add(JXNode.t(str));
}
}
} catch (Exception e) {
String msg = "Please check the syntax of your xpath expr, ";
throw new XpathSyntaxErrorException(msg + ExceptionUtils.getRootCauseMessage(e), e);
}
return finalRes;
}
Aggregations