org.parboiled.parserunners.ParseRunner Java Examples
The following examples show how to use
org.parboiled.parserunners.ParseRunner.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JidCorpusParser.java From jxmpp with Apache License 2.0 | 5 votes |
/** * Parse the input. * * @return a list of parsed {@link ValidJid}s. */ public List<J> parse() { final ParseRunner<J> runner; if (enableParserTracing) { runner = getTracingParseRunner(); } else { runner = getReportingParserRunner(); } parsingResult = runner.run(input); parsedJids = getValidJidsFrom(parsingResult); return parsedJids; }
Example #2
Source File: AbstractParserTest.java From jtwig-core with Apache License 2.0 | 4 votes |
protected <T> ParsingResult<T> parse(Rule rule, String input) { ParseRunner<T> handler = new BasicParseRunner<T>(rule); return handler.run(input); }
Example #3
Source File: SQLParserUtils.java From datacollector with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public static Map<String, String> process( SQLParser parser, String sql, int type, // One of OracleCDCOperationCode constants. boolean allowNulls, boolean caseSensitive, Set<String> columnsExpected ) throws UnparseableSQLException { Rule parseRule; switch (type) { case OracleCDCOperationCode.INSERT_CODE: parseRule = parser.Insert(); break; case OracleCDCOperationCode.UPDATE_CODE: case OracleCDCOperationCode.SELECT_FOR_UPDATE_CODE: parseRule = parser.Update(); break; case OracleCDCOperationCode.DELETE_CODE: parseRule = parser.Delete(); break; default: throw new UnparseableSQLException(sql); } ParseRunner<?> runner = new BasicParseRunner<>(parseRule); ParsingResult<?> result = runner.run(sql); if (!result.matched) { throw new UnparseableSQLException(sql); } Collection<Node<Object>> names = new ArrayList<>(); ParseTreeUtils.collectNodes( (Node<Object>) result.parseTreeRoot, input -> input.getLabel().equals(COLUMN_NAME_RULE), names ); Collection<Node<Object>> values = new ArrayList<>(); ParseTreeUtils.collectNodes( (Node<Object>) result.parseTreeRoot, input -> input.getLabel().equals(COLUMN_VALUE_RULE), values ); Map<String, String> colVals = new HashMap<>(); for (int i = 0; i < names.size(); i++) { Node<?> name = ((ArrayList<Node<Object>>) names).get(i); Node<?> val = ((ArrayList<Node<Object>>) values).get(i); final String colName = sql.substring(name.getStartIndex(), name.getEndIndex()); final String key = formatName(colName, caseSensitive); if (!colVals.containsKey(key)) { colVals.put(key, formatValue(sql.substring(val.getStartIndex(), val.getEndIndex()))); } } if (allowNulls && columnsExpected != null) { columnsExpected.forEach(col -> colVals.putIfAbsent(col, null)); } return colVals; }