use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class AceEditorBackgroundLinkHighlighter method onWebLinkHighlight.
private void onWebLinkHighlight(AceEditor editor, String line, int row) {
// use a regex that captures all non-space characters within
// a web link, and then fix up the captured link by removing
// trailing punctuation, etc. as required
Pattern reWebLink = createWebLinkPattern();
for (Match match = reWebLink.match(line, 0); match != null; match = match.nextMatch()) {
// compute start, end index for discovered URL
int startIdx = match.getIndex();
int endIdx = match.getIndex() + match.getValue().length();
// ensure that the discovered url is not within a string
Token token = editor_.getTokenAt(Position.create(row, startIdx));
if (token.hasType("string"))
continue;
String url = match.getValue();
// trim off enclosing brackets
if (!url.matches(reWebLink())) {
startIdx++;
endIdx--;
url = url.substring(1, url.length() - 1);
}
// trim off trailing punctuation (characters unlikely
// to be found at the end of a url)
String trimmed = url.replaceAll("[,.?!@#$%^&*;:-]+$", "");
endIdx -= (url.length() - trimmed.length());
url = trimmed;
// perform highlighting
highlight(editor, row, startIdx, endIdx);
}
}
use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class AceEditorBackgroundLinkHighlighter method onTestthatErrorHighlight.
private void onTestthatErrorHighlight(AceEditor editor, String line, int row) {
Pattern reTestthatError = Pattern.create("\\(@[^#]+#\\d+\\)");
for (Match match = reTestthatError.match(line, 0); match != null; match = match.nextMatch()) {
int startIdx = match.getIndex() + 1;
int endIdx = match.getIndex() + match.getValue().length() - 1;
highlight(editor, row, startIdx, endIdx);
}
}
use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class AceEditorBackgroundLinkHighlighter method onMarkdownLinkHighlight.
private void onMarkdownLinkHighlight(AceEditor editor, String line, int row) {
Pattern reMarkdownLink = Pattern.create("(\\[[^\\]]+\\])(\\([^\\)]+\\))");
for (Match match = reMarkdownLink.match(line, 0); match != null; match = match.nextMatch()) {
int startIdx = match.getIndex() + match.getGroup(1).length() + 1;
int endIdx = match.getIndex() + match.getValue().length() - 1;
highlight(editor, row, startIdx, endIdx);
}
}
use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class CppCompletionUtils method getCompletionPosition.
public static CompletionPosition getCompletionPosition(DocDisplay docDisplay, boolean explicit, boolean alwaysComplete, int autoChars) {
// get the current line of code
String line = docDisplay.getCurrentLine();
// is this an '#include' line?
Pattern reInclude = Pattern.create("^\\s*#+\\s*include", "");
boolean isInclude = reInclude.test(line);
// get the cursor position
Position position = docDisplay.getCursorPosition();
// if so then bail
if ((position.getColumn() < line.length()) && CppCompletionUtils.isCppIdentifierChar(line.charAt(position.getColumn()))) {
return null;
}
// determine the column right before this one
int inputCol = position.getColumn() - 1;
// walk backwards across C++ identifer symbols
int col = inputCol;
if (isInclude) {
while (col >= 0 && !StringUtil.isOneOf(line.charAt(col), '/', '<', '"')) {
col--;
}
} else {
while ((col >= 0) && CppCompletionUtils.isCppIdentifierChar(line.charAt(col))) {
col--;
}
}
// record source position
Position startPos = Position.create(position.getRow(), col + 1);
// check for a completion triggering sequence
char ch = line.charAt(col);
char prefixCh = line.charAt(col - 1);
// member
if (ch == '.' || (prefixCh == '-' && ch == '>')) {
return new CompletionPosition(startPos, // no user text (get all completions)
"", CompletionPosition.Scope.Member);
} else // scope
if (prefixCh == ':' && ch == ':') {
return new CompletionPosition(startPos, // no user text (get all completions)
"", CompletionPosition.Scope.Namespace);
} else // directory
if (isInclude && ch == '/') {
return new CompletionPosition(startPos, // no user test (get all completions)
"", CompletionPosition.Scope.File);
} else // minimum character threshold
if (// either always completing or explicit
(alwaysComplete || explicit) && // meets the character threshold
((inputCol - col) >= (explicit ? 1 : autoChars)) && // not a quote character
(isInclude || ch != '"')) {
// calculate user text (up to two characters of additional
// server side filter)
String userText = line.substring(col + 1, Math.min(col + 3, position.getColumn()));
CompletionPosition.Scope scope = isInclude ? CompletionPosition.Scope.File : CompletionPosition.Scope.Global;
return new CompletionPosition(startPos, userText, scope);
} else {
return null;
}
}
use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class TextEditingTargetCompilePdfHelper method getRnwOptionsStart.
@Override
public int getRnwOptionsStart(String line, int cursorPos) {
Pattern pattern = docDisplay_.getFileType().getRnwStartPatternBegin();
if (pattern == null)
return -1;
String linePart = line.substring(0, cursorPos);
Match match = pattern.match(linePart, 0);
if (match == null)
return -1;
// See if the cursor is already past the end of the chunk header,
// for example <<foo>>=[CURSOR].
Pattern patternEnd = docDisplay_.getFileType().getRnwStartPatternEnd();
if (patternEnd != null && patternEnd.match(linePart, 0) != null)
return -1;
return match.getValue().length();
}
Aggregations