mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
Zero-length start patterns work.
Add zero-length captures back into OnigRegEx.BuildCaptureIndices to see zero length captures. Handle zero-length captures by continuing to scan line. Does not handle infinite loop possibility yet.
This commit is contained in:
parent
7f8531d10f
commit
10c36191ec
@ -58,7 +58,7 @@ public:
|
||||
for (int index = 0; index < resultCount; index++) {
|
||||
int captureLength = [result lengthAt:index];
|
||||
int captureStart = [result locationAt:index];
|
||||
if (captureLength == 0) continue;
|
||||
|
||||
array->SetValue(i++, CefV8Value::CreateInt(index));
|
||||
array->SetValue(i++, CefV8Value::CreateInt(captureStart));
|
||||
array->SetValue(i++, CefV8Value::CreateInt(captureStart + captureLength));
|
||||
@ -104,7 +104,7 @@ bool OnigRegExp::Execute(const CefString& name,
|
||||
if (captureIndices->IsNull()) continue;
|
||||
|
||||
if (bestIndex == -1 || captureIndices->GetValue(1)->GetIntValue() < captureIndicesForBestIndex->GetValue(1)->GetIntValue()) {
|
||||
bestIndex = i;
|
||||
bestIndex = i;
|
||||
captureIndicesForBestIndex = captureIndices;
|
||||
if (captureIndices->GetValue(1)->GetIntValue() == 0) break; // If the match starts at 0, just use it!
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class TextMateGrammar
|
||||
|
||||
tokens.push(nextTokens...)
|
||||
position = tokensEndPosition
|
||||
else
|
||||
else if tokensEndPosition - tokensStartPosition != 0 # break unless it was a zero length match
|
||||
tokens.push
|
||||
value: line[position...line.length]
|
||||
scopes: scopes
|
||||
@ -147,14 +147,12 @@ class Pattern
|
||||
scopes.push(@scopeName) unless @popRule
|
||||
|
||||
if @captures
|
||||
parentCapture = captureIndices[0..2]
|
||||
childCaptures = captureIndices[3..]
|
||||
tokens = @getTokensForCaptureIndices(line, captureIndices, scopes)
|
||||
else
|
||||
[start, end] = captureIndices[1..2]
|
||||
zeroLengthMatch = end == start
|
||||
if zeroLengthMatch
|
||||
tokens = []
|
||||
tokens = null
|
||||
else
|
||||
tokens = [{ value: line[start...end], scopes: scopes }]
|
||||
|
||||
@ -176,6 +174,10 @@ class Pattern
|
||||
while captureIndices.length and captureIndices[1] < parentCaptureEnd
|
||||
[childCaptureIndex, childCaptureStart, childCaptureEnd] = captureIndices
|
||||
|
||||
if childCaptureEnd - childCaptureStart == 0 # An empty capture, so it can't contain any tokens
|
||||
shiftCapture(captureIndices)
|
||||
continue
|
||||
|
||||
if childCaptureStart > previousChildCaptureEnd
|
||||
tokens.push
|
||||
value: line[previousChildCaptureEnd...childCaptureStart]
|
||||
|
Loading…
Reference in New Issue
Block a user