Search in sources :

Example 31 with Match

use of org.rstudio.core.client.regex.Match in project rstudio by rstudio.

the class RMarkdownChunkHeaderParser method consumeUntilRegex.

private static final boolean consumeUntilRegex(TextCursor cursor, String regex, Consumer consumer) {
    Pattern pattern = Pattern.create(regex);
    Match match = pattern.match(cursor.getData(), cursor.getIndex());
    if (match == null)
        return false;
    int startIdx = cursor.getIndex();
    int endIdx = match.getIndex();
    if (consumer != null) {
        String value = cursor.getData().substring(startIdx, endIdx);
        consumer.consume(value);
    }
    cursor.setIndex(endIdx);
    return true;
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) Match(org.rstudio.core.client.regex.Match)

Example 32 with Match

use of org.rstudio.core.client.regex.Match in project rstudio by rstudio.

the class CppCompletionRequest method getRangeForSpecializedDiagnostic.

private static Range getRangeForSpecializedDiagnostic(CppDiagnostic diagnostic) {
    String message = diagnostic.getMessage();
    Match match;
    match = RE_NO_MEMBER_NAMED.match(message, 0);
    if (match != null)
        return createRangeFromMatch(diagnostic, match);
    match = RE_USE_UNDECLARED_IDENTIFIER.match(message, 0);
    if (match != null)
        return createRangeFromMatch(diagnostic, match);
    return null;
}
Also used : Match(org.rstudio.core.client.regex.Match)

Example 33 with Match

use of org.rstudio.core.client.regex.Match in project rstudio by rstudio.

the class SVNDiffParser method nextFilePair.

@Override
public DiffFileHeader nextFilePair() {
    pendingDiffChunks_.clear();
    if (sections_.size() == 0)
        return null;
    ArrayList<Section> sectionsToUse = new ArrayList<Section>();
    sectionsToUse.add(sections_.remove(0));
    String filename = sectionsToUse.get(0).filename;
    while (sections_.size() > 0 && sections_.get(0).filename.equals(filename)) {
        sectionsToUse.add(sections_.remove(0));
    }
    // Put the properties above the item diffs.
    Collections.sort(sectionsToUse, new Comparator<Section>() {

        @Override
        public int compare(Section a, Section b) {
            return a.isProperty == b.isProperty ? 0 : a.isProperty ? -1 : 1;
        }
    });
    Section lastSection = null;
    for (Section section : sectionsToUse) {
        if (section.isProperty) {
            String trimmed = StringUtil.trimBlankLines(section.data);
            pendingDiffChunks_.add(createInfoChunk(StringUtil.getLineIterator(trimmed)));
        } else {
            UnifiedParser parser = new UnifiedParser(section.data, diffIndex_);
            DiffFileHeader filePair = parser.nextFilePair();
            if (filePair == null) {
                // Although "Index: <filename>" appeared, no diff was actually
                // generated (e.g. binary file)
                Pattern hrule = Pattern.create("^=+$");
                Match m = hrule.match(section.data, 0);
                int startAt = (m != null) ? m.getIndex() + m.getValue().length() : 0;
                Iterable<String> lines = StringUtil.getLineIterator(StringUtil.trimBlankLines(section.data.substring(startAt)));
                DiffChunk chunk = createInfoChunk(lines);
                if (lastSection != null && lastSection.isProperty) {
                    // This is to work around special case where a binary file is
                    // initially checked in. If we do nothing, in the history it
                    // will appear as the property changes, then without a break,
                    // the message that this file can't be displayed. That's the
                    // correct content, but we want it in the order of the message
                    // that the file can't be displayed, then a blank line, then
                    // the property changes.
                    pendingDiffChunks_.add(0, chunk);
                    pendingDiffChunks_.add(1, createInfoChunk(StringUtil.getLineIterator("\n")));
                } else {
                    pendingDiffChunks_.add(chunk);
                }
            }
            DiffChunk chunk;
            while (null != (chunk = parser.nextChunk())) {
                pendingDiffChunks_.add(chunk);
            }
            diffIndex_ = parser.getDiffIndex();
        }
        lastSection = section;
    }
    return new DiffFileHeader(new ArrayList<String>(), filename, filename);
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) ArrayList(java.util.ArrayList) Match(org.rstudio.core.client.regex.Match)

Aggregations

Match (org.rstudio.core.client.regex.Match)33 Pattern (org.rstudio.core.client.regex.Pattern)22 JsArrayString (com.google.gwt.core.client.JsArrayString)10 ArrayList (java.util.ArrayList)5 Point (org.rstudio.core.client.Point)3 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)2 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)2 JsArrayInteger (com.google.gwt.core.client.JsArrayInteger)1 Iterator (java.util.Iterator)1 Pair (org.rstudio.core.client.Pair)1 TextCursor (org.rstudio.core.client.TextCursor)1 ReplaceOperation (org.rstudio.core.client.regex.Pattern.ReplaceOperation)1 ImageResource2x (org.rstudio.core.client.resources.ImageResource2x)1 InputEditorPosition (org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition)1 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)1