Package org.codehaus.jparsec.pattern

Examples of org.codehaus.jparsec.pattern.Pattern


  /**
   * A scanner for non-nested block comment that starts with {@code begin} and ends with
   * {@code end}.
   */
  public static Parser<Void> blockComment(String begin, String end) {
    Pattern opening = Patterns.string(begin).next(Patterns.notString(end).many());
    return pattern(opening, begin).next(string(end));
  }
View Full Code Here


   * @param end ends a block comment
   * @param commented the commented pattern.
   * @return the Scanner for the block comment.
   */
  public static Parser<Void> blockComment(String begin, String end, Pattern commented) {
    Pattern opening = Patterns.string(begin)
        .next(Patterns.string(end).not().next(commented).many());
    return pattern(opening, begin).next(string(end));
  }
View Full Code Here

  /**
   * A scanner for a quoted string that starts with character {@code begin} and ends with character
   * {@code end}.
   */
  public static Parser<String> quoted(char begin, char end) {
    Pattern beforeClosingQuote =
        Patterns.isChar(begin).next(Patterns.many(CharPredicates.notChar(end)));
    return pattern(beforeClosingQuote, Character.toString(begin)).next(isChar(end)).source();
  }
View Full Code Here

   * characters with the first 2 characters not being {@code c1} and {@code c2}.
   *
   * @return the Pattern object.
   */
  private static Pattern notChar2(final char c1, final char c2) {
    return new Pattern() {
      @Override public int match(CharSequence src, int begin, int end) {
        if (begin == end - 1) return 1;
        if (begin >= end) return MISMATCH;
        if (src.charAt(begin) == c1 && src.charAt(begin + 1) == c2) return Pattern.MISMATCH;
        return 1;
View Full Code Here

    assertFalse(predicate.isChar('\n'));
    assertEquals("whitespace", predicate.toString());
  }
 
  public void testLineContinuation() {
    Pattern pattern = Indentation.LINE_CONTINUATION;
    assertEquals(MISMATCH, pattern.match("", 0, 0));
    assertEquals(MISMATCH, pattern.match("a", 0, 1));
    assertEquals(MISMATCH, pattern.match("\\a", 0, 2));
    assertEquals(MISMATCH, pattern.match("\\ \t", 0, 3));
    assertEquals(2, pattern.match("\\\n", 0, 2));
    assertEquals(6, pattern.match("\\  \t\r\n", 0, 6));
  }
View Full Code Here

    assertEquals(2, pattern.match("\\\n", 0, 2));
    assertEquals(6, pattern.match("\\  \t\r\n", 0, 6));
  }
 
  public void testInlineWhitespaces() {
    Pattern pattern = Indentation.INLINE_WHITESPACES;
    assertEquals(MISMATCH, pattern.match("", 0, 0));
    assertEquals(MISMATCH, pattern.match("a", 0, 1));
    assertEquals(MISMATCH, pattern.match("\n", 0, 1));
    assertEquals(1, pattern.match(" ", 0, 1));
    assertEquals(2, pattern.match("  ", 0, 2));
    assertEquals(4, pattern.match("  \t\r", 0, 4));
  }
View Full Code Here

    assertEquals("whitespace", predicate.toString());
  }

  @Test
  public void testLineContinuation() {
    Pattern pattern = Indentation.LINE_CONTINUATION;
    assertEquals(MISMATCH, pattern.match("", 0, 0));
    assertEquals(MISMATCH, pattern.match("a", 0, 1));
    assertEquals(MISMATCH, pattern.match("\\a", 0, 2));
    assertEquals(MISMATCH, pattern.match("\\ \t", 0, 3));
    assertEquals(2, pattern.match("\\\n", 0, 2));
    assertEquals(6, pattern.match("\\  \t\r\n", 0, 6));
  }
View Full Code Here

    assertEquals(6, pattern.match("\\  \t\r\n", 0, 6));
  }

  @Test
  public void testInlineWhitespaces() {
    Pattern pattern = Indentation.INLINE_WHITESPACES;
    assertEquals(MISMATCH, pattern.match("", 0, 0));
    assertEquals(MISMATCH, pattern.match("a", 0, 1));
    assertEquals(MISMATCH, pattern.match("\n", 0, 1));
    assertEquals(1, pattern.match(" ", 0, 1));
    assertEquals(2, pattern.match("  ", 0, 2));
    assertEquals(4, pattern.match("  \t\r", 0, 4));
  }
View Full Code Here

    }

    @Override
    Incremental<Void> parse(ParseContext ctxt) {
      CharSequence src = ctxt.characters();
      Pattern derived = pattern;
      for (int i = 0; i < src.length(); i++) {
        derived = derived.derive(src.charAt(i));
        if (derived == Patterns.ALWAYS) {
          ctxt.next(i);
          ctxt.result = null;
          return new Done<Void>(null);
        } else if (derived == Patterns.NEVER) {
View Full Code Here

  /**
   * A scanner for non-nested block comment that starts with {@code begin} and ends with
   * {@code end}.
   */
  public static Parser<Void> blockComment(String begin, String end) {
    Pattern opening = Patterns.string(begin).next(Patterns.notString(end).many());
    return pattern(opening, begin).next(string(end));
  }
View Full Code Here

TOP

Related Classes of org.codehaus.jparsec.pattern.Pattern

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.