示例#1
0
  @Override
  public ParseResult parse(RSyntaxDocument doc, String style) {

    Element root = doc.getDefaultRootElement();
    int lineCount = root.getElementCount();

    if (taskPattern == null || style == null || SyntaxConstants.SYNTAX_STYLE_NONE.equals(style)) {
      result.clearNotices();
      result.setParsedLines(0, lineCount - 1);
      return result;
    }

    // TODO: Pass in parsed line range and just do that
    result.clearNotices();
    result.setParsedLines(0, lineCount - 1);

    for (int line = 0; line < lineCount; line++) {

      Token t = doc.getTokenListForLine(line);
      int offs = -1;
      int start = -1;
      String text = null;

      while (t != null && t.isPaintable()) {
        if (t.isComment()) {

          offs = t.offset;
          text = t.getLexeme();

          Matcher m = taskPattern.matcher(text);
          if (m.find()) {
            start = m.start();
            offs += start;
            break;
          }
        }
        t = t.getNextToken();
      }

      if (start > -1) {
        text = text.substring(start);
        // TODO: Strip off end of MLC's if they're there.
        int len = text.length();
        TaskNotice pn = new TaskNotice(this, text, line, offs, len);
        pn.setLevel(ParserNotice.INFO);
        pn.setShowInEditor(false);
        pn.setColor(COLOR);
        result.addNotice(pn);
      }
    }

    return result;
  }
  /** {@inheritDoc} */
  public ParseResult parse(RSyntaxDocument doc, String style) {

    result.clearNotices();
    Element root = doc.getDefaultRootElement();
    result.setParsedLines(0, root.getElementCount() - 1);

    if (spf == null || doc.getLength() == 0) {
      return result;
    }

    try {
      SAXParser sp = spf.newSAXParser();
      Handler handler = new Handler(doc);
      DocumentReader r = new DocumentReader(doc);
      InputSource input = new InputSource(r);
      sp.parse(input, handler);
      r.close();
    } catch (SAXParseException spe) {
      // A fatal parse error - ignore; a ParserNotice was already created.
    } catch (Exception e) {
      // e.printStackTrace(); // Will print if DTD specified and can't be found
      result.addNotice(
          new DefaultParserNotice(this, "Error parsing XML: " + e.getMessage(), 0, -1, -1));
    }

    return result;
  }