Java Code Examples for org.parboiled.Parboiled#createParser()

The following examples show how to use org.parboiled.Parboiled#createParser() . 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: TestSQLParser.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test
public void testSQL() throws Exception {
  SQLParser parser = Parboiled.createParser(SQLParser.class);
  Map<String, String> colVals;
  int code;
  if (sql.startsWith("insert")) {
    code = OracleCDCOperationCode.INSERT_CODE;
  } else if (sql.startsWith("delete")) {
    code = OracleCDCOperationCode.DELETE_CODE;
  } else {
    code = OracleCDCOperationCode.UPDATE_CODE;
  }
  colVals = SQLParserUtils.process(parser, sql, code, false, false, null);

  Assert.assertEquals(expected, colVals);
}
 
Example 2
Source File: TestSQLParser.java    From datacollector with Apache License 2.0 6 votes vote down vote up
private void doTestSQLWithNulls(String sqlInternal) throws UnparseableSQLException {
  SQLParser parser = Parboiled.createParser(SQLParser.class);
  Map<String, String> colVals;
  int code = OracleCDCOperationCode.UPDATE_CODE;
  Set<String> expectedFields = new HashSet<>(
      Lists.newArrayList("ID", "NAME", "HIREDATE", "SALARY=", "LASTLOGIN", "LASTDATE"));
  colVals = SQLParserUtils.process(parser, sqlInternal, code, true, false, expectedFields);
  Map<String, String> exp = new HashMap<String, String>() {
    {
      put("ID", "1");
      put("SALARY=", null);
      put("NAME", "New Name");
      put("HIREDATE", "TO_DATE('21-11-2016 11:34:09', 'DD-MM-YYYY HH24:MI:SS')");
      put("LASTLOGIN", "TO_TIMESTAMP('2016-11-21 11:34:09.982753')");
      put("ROWID", "AAAAxhdjhjsdhaks");
      put("LASTDATE", null);
    }
  };
  Assert.assertEquals(exp, colVals);
}
 
Example 3
Source File: TestSQLParser.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test (expected = UnparseableSQLException.class)
public void testInvalidSql() throws Exception {
  String sqlInternal = " update \"SYS\".\"MANYCOLS\" set why are we testing this";
  SQLParser parser = Parboiled.createParser(SQLParser.class);
  Map<String, String> colVals;
  int code = OracleCDCOperationCode.UPDATE_CODE;
  Set<String> expectedFields = new HashSet<>(
      Lists.newArrayList("ID", "NAME", "HIREDATE", "SALARY=", "LASTLOGIN", "LASTDATE"));
  colVals = SQLParserUtils.process(parser, sqlInternal, code, true, false, expectedFields);
  Map<String, String> exp = new HashMap<String, String>() {
    {
      put("ID", "1");
      put("SALARY=", null);
      put("NAME", "New Name");
      put("HIREDATE", "TO_DATE('21-11-2016 11:34:09', 'DD-MM-YYYY HH24:MI:SS')");
      put("LASTLOGIN", "TO_TIMESTAMP('2016-11-21 11:34:09.982753')");
      put("ROWID", "AAAAxhdjhjsdhaks");
      put("LASTDATE", null);
    }
  };
  Assert.assertEquals(exp, colVals);
}
 
Example 4
Source File: RunParser.java    From immutables with Apache License 2.0 6 votes vote down vote up
public static void main(String... args) {

    Parser templateParser = Parboiled.createParser(Parser.class);
    ParsingResult<Object> result = new ReportingParseRunner<>(templateParser.Unit()).run(input2);

    ImmutableList<Object> copy = ImmutableList.copyOf(result.valueStack.iterator());

    if (!copy.isEmpty()) {
      Unit unit = (Unit) copy.get(0);

      Unit balance = Balancing.balance(unit);
      System.out.println(balance);
    }

    if (result.hasErrors()) {
      System.err.println(ErrorUtils.printParseErrors(result.parseErrors));
    }
    // System.out.println(ParseTreeUtils.printNodeTree(result));
  }
 
Example 5
Source File: GroupWildcard.java    From batfish with Apache License 2.0 5 votes vote down vote up
public static String toJavaRegex(String wildcard) {
  GroupWildcard parser = Parboiled.createParser(GroupWildcard.class);
  BasicParseRunner<String> runner = new BasicParseRunner<>(parser.TopLevel());
  ParsingResult<String> result = runner.run(wildcard);
  if (!result.matched) {
    throw new IllegalArgumentException("Unhandled input: " + wildcard);
  }
  return result.resultValue;
}
 
Example 6
Source File: GroupWildcard.java    From batfish with Apache License 2.0 5 votes vote down vote up
/** Like {@link #toJavaRegex(String)}, but for debugging. */
@SuppressWarnings("unused") // leaving here for future debugging.
@Nonnull
static String debugToJavaRegex(String regex) {
  GroupWildcard parser = Parboiled.createParser(GroupWildcard.class);
  TracingParseRunner<String> runner =
      new TracingParseRunner<String>(parser.TopLevel()).withLog(new StringBuilderSink());
  ParsingResult<String> result = runner.run(regex);
  if (!result.matched) {
    throw new IllegalArgumentException("Unhandled input: " + regex + "\n" + runner.getLog());
  }
  return result.resultValue;
}
 
Example 7
Source File: AsPathRegex.java    From batfish with Apache License 2.0 5 votes vote down vote up
/** Converts the given Juniper AS Path regular expression to a Java regular expression. */
@Nonnull
public static String convertToJavaRegex(String regex) {
  AsPathRegex parser = Parboiled.createParser(AsPathRegex.class);
  BasicParseRunner<String> runner = new BasicParseRunner<>(parser.TopLevel());
  ParsingResult<String> result = runner.run(regex);
  if (!result.matched) {
    throw new IllegalArgumentException("Unhandled input: " + regex);
  }
  return result.resultValue;
}
 
Example 8
Source File: AsPathRegex.java    From batfish with Apache License 2.0 5 votes vote down vote up
/** Like {@link #convertToJavaRegex(String)}, but for debugging. */
@SuppressWarnings("unused") // leaving here for future debugging.
@Nonnull
static String debugConvertToJavaRegex(String regex) {
  AsPathRegex parser = Parboiled.createParser(AsPathRegex.class);
  TracingParseRunner<String> runner =
      new TracingParseRunner<String>(parser.TopLevel()).withLog(new StringBuilderSink());
  ParsingResult<String> result = runner.run(regex);
  if (!result.matched) {
    throw new IllegalArgumentException("Unhandled input: " + regex + "\n" + runner.getLog());
  }
  return result.resultValue;
}
 
Example 9
Source File: CfgPropsParser.java    From nb-springboot with Apache License 2.0 4 votes vote down vote up
public CfgPropsParser() {
    parboiled = Parboiled.createParser(CfgPropsParboiled.class);
}
 
Example 10
Source File: TestBase.java    From nb-springboot with Apache License 2.0 4 votes vote down vote up
TestBase() {
    parser = Parboiled.createParser(CfgPropsParboiled.class);
    tracingRunner = new TracingParseRunner(parser.cfgProps());
    reportingRunner = new ReportingParseRunner(parser.cfgProps());
}
 
Example 11
Source File: CommonParser.java    From batfish with Apache License 2.0 4 votes vote down vote up
static CommonParser instance() {
  return Parboiled.createParser(CommonParser.class);
}
 
Example 12
Source File: Parser.java    From batfish with Apache License 2.0 4 votes vote down vote up
static Parser instance() {
  return Parboiled.createParser(Parser.class);
}
 
Example 13
Source File: TestParser.java    From batfish with Apache License 2.0 4 votes vote down vote up
static TestParser instance() {
  return Parboiled.createParser(TestParser.class);
}