public static <A extends Appendable> A render(RENode re, A appendable) throws IOException, NullPointerException { if (re == null) { throw new NullPointerException("No null disjunction accepted"); } if (appendable == null) { throw new NullPointerException("No null appendable accepted"); } // RERenderer renderer = new RERenderer(appendable); // re.accept(renderer); // return appendable; }
static void assertRender(RENode re, String expected) { try { String rendered; if (re != null) { rendered = RERenderer.render(re, new StringBuilder()).toString(); } else { rendered = ""; } assertEquals(expected, rendered); } catch (IOException e) { AssertionFailedError afe = new AssertionFailedError(); afe.initCause(e); throw afe; } }
static void assertRender(RENode re, String expected) { try { String rendered; if (re != null) { rendered = RERenderer.render(re, new StringBuilder()).toString(); } else { rendered = ""; } assertEquals(expected, rendered); } catch (IOException e) { AssertionFailedError afe = new AssertionFailedError(); afe.initCause(e); throw afe; } }
private void match(String pattern, String test, String expectedValue) throws Exception { REParser parser = new REParser(pattern); CharEscapeTransformation escaper = new CharEscapeTransformation('/', '_'); RENode.Disjunction re = parser.parseDisjunction(); re.accept(escaper); Pattern p = Pattern.compile(RERenderer.render(re, new StringBuilder()).toString()); Matcher matcher = p.matcher(test); assertTrue(matcher.find()); assertEquals(expectedValue, matcher.group()); }
public static <A extends Appendable> A render(RENode re, A appendable) throws IOException, NullPointerException { if (re == null) { throw new NullPointerException("No null disjunction accepted"); } if (appendable == null) { throw new NullPointerException("No null appendable accepted"); } // RERenderer renderer = new RERenderer(appendable); // re.accept(renderer); // return appendable; }
private void match(String pattern, String test, String expectedValue) throws Exception { REParser parser = new REParser(pattern); CharEscapeTransformation escaper = new CharEscapeTransformation('/', '_'); RENode.Disjunction re = parser.parseDisjunction(); re.accept(escaper); Pattern p = Pattern.compile(RERenderer.render(re, new StringBuilder()).toString()); Matcher matcher = p.matcher(test); assertTrue(matcher.find()); assertEquals(expectedValue, matcher.group()); }
@Override protected void visit(RENode.Group expr) throws RuntimeException { if (expr.getType() == GroupType.CAPTURING_GROUP) { try { RERenderer renderer = new RERenderer(current.resolvingExpression); expr.accept(renderer); } catch (IOException e) { // Should not happen throw new AssertionError(e); } try { RERenderer renderer = new RERenderer(current.valueMatcher); expr.accept(renderer); } catch (IOException e) { // Should not happen throw new AssertionError(e); } current.prefix = current.buffer.toString(); current.buffer.setLength(0); } else { super.visit(expr); } }
protected void visit(RENode.Alternative alternative) throws IOException, NullPointerException { alternative.getExpr().accept(this); RENode.Alternative next = alternative.getNext(); if (next != null) { visit(next); } }
private void match(String pattern, String test, String expectedValue) throws Exception { REParser parser = new REParser(pattern); RouteEscaper escaper = new RouteEscaper('/', '_'); RENode.Disjunction re = parser.parseDisjunction(); re.accept(escaper); Pattern p = Pattern.compile(RERenderer.render(re, new StringBuilder()).toString()); Matcher matcher = p.matcher(test); assertTrue(matcher.find()); assertEquals(expectedValue, matcher.group()); }
@Override protected void visit(RENode.Group expr) throws RuntimeException { if (expr.getType() == GroupType.CAPTURING_GROUP) { try { RERenderer renderer = new RERenderer(current.resolvingExpression); expr.accept(renderer); } catch (IOException e) { // Should not happen throw new AssertionError(e); } try { RERenderer renderer = new RERenderer(current.valueMatcher); expr.accept(renderer); } catch (IOException e) { // Should not happen throw new AssertionError(e); } current.prefix = current.buffer.toString(); current.buffer.setLength(0); } else { super.visit(expr); } }
protected void visit(RENode.Alternative alternative) throws IOException, NullPointerException { alternative.getExpr().accept(this); RENode.Alternative next = alternative.getNext(); if (next != null) { visit(next); } }
private void match(String pattern, String test, String expectedValue) throws Exception { REParser parser = new REParser(pattern); RouteEscaper escaper = new RouteEscaper('/', '_'); RENode.Disjunction re = parser.parseDisjunction(); re.accept(escaper); Pattern p = Pattern.compile(RERenderer.render(re, new StringBuilder()).toString()); Matcher matcher = p.matcher(test); assertTrue(matcher.find()); assertEquals(expectedValue, matcher.group()); }
private void assertTransform(String test, String expected, boolean capturing) throws SyntaxException, IOException { RENode node = new REParser(test).parse(); REVisitor<RuntimeException> transformer = capturing ? new CaptureGroupTransformation() : new NonCaptureGroupTransformation(); node.accept(transformer); StringBuilder sb = new StringBuilder(); RERenderer renderer = new RERenderer(sb); node.accept(renderer); assertEquals(expected, sb.toString()); } }
protected void visit(RENode.Group expr) throws IOException { appendable.append(expr.getType().getOpen()); this.visit(expr.getDisjunction()); appendable.append(expr.getType().getClose()); if (expr.getQuantifier() != null) { expr.getQuantifier().toString(appendable); } }
private void assertAnalyse(String expectedPattern, String pattern) { try { RENode.Disjunction disjunction = new REParser(pattern).parseDisjunction(); assertEquals(expectedPattern, RERenderer.render(disjunction, new StringBuilder()).toString()); } catch (Exception e) { fail(e); } }
private void assertTransform(String test, String expected, boolean capturing) throws SyntaxException, IOException { RENode node = new REParser(test).parse(); REVisitor<RuntimeException> transformer = capturing ? new CaptureGroupTransformation() : new NonCaptureGroupTransformation(); node.accept(transformer); StringBuilder sb = new StringBuilder(); RERenderer renderer = new RERenderer(sb); node.accept(renderer); assertEquals(expected, sb.toString()); } }
protected void visit(RENode.Group expr) throws IOException { appendable.append(expr.getType().getOpen()); this.visit(expr.getDisjunction()); appendable.append(expr.getType().getClose()); if (expr.getQuantifier() != null) { expr.getQuantifier().toString(appendable); } }
private void assertAnalyse(String expectedPattern, String pattern) { try { RENode.Disjunction disjunction = new REParser(pattern).parseDisjunction(); assertEquals(expectedPattern, RERenderer.render(disjunction, new StringBuilder()).toString()); } catch (Exception e) { fail(e); } }