Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Use OnigString API to allow caching of RegExp matches
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed Apr 19, 2017
1 parent 96dbce0 commit c0fe228
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"event-kit": "^2.2.0",
"fs-plus": "^3.0.0",
"grim": "^2.0.1",
"oniguruma": "^6.1.0",
"oniguruma": "6.2.0-0",
"season": "^6.0.0",
"underscore-plus": "^1"
},
Expand Down
2 changes: 1 addition & 1 deletion spec/grammar-registry-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
path = require 'path'
GrammarRegistry = require '../lib/grammar-registry'
GrammarRegistry = require '../src/grammar-registry'

describe "GrammarRegistry", ->
registry = null
Expand Down
4 changes: 2 additions & 2 deletions spec/grammar-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
path = require 'path'
_ = require 'underscore-plus'
fs = require 'fs-plus'
GrammarRegistry = require '../lib/grammar-registry'
Grammar = require '../lib/grammar'
GrammarRegistry = require '../src/grammar-registry'
Grammar = require '../src/grammar'

describe "Grammar tokenization", ->
[grammar, registry] = []
Expand Down
8 changes: 5 additions & 3 deletions src/grammar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ path = require 'path'

_ = require 'underscore-plus'
fs = require 'fs-plus'
{OnigRegExp} = require 'oniguruma'
{OnigRegExp, OnigString} = require 'oniguruma'
{Emitter} = require 'event-kit'
Grim = require 'grim'

Expand Down Expand Up @@ -103,11 +103,13 @@ class Grammar

truncatedLine = false
if inputLine.length > @maxLineLength
line = inputLine.slice(0, @maxLineLength)
truncatedLine = true
line = inputLine.slice(0, @maxLineLength)
else
line = inputLine

string = new OnigString(inputLine + '\n')

if ruleStack?
ruleStack = ruleStack.slice()
if compatibilityMode
Expand Down Expand Up @@ -137,7 +139,7 @@ class Grammar
truncatedLine = true
break

if match = _.last(ruleStack).rule.getNextTags(ruleStack, line, position, firstLine)
if match = _.last(ruleStack).rule.getNextTags(ruleStack, string, position, firstLine)
{nextTags, tagsStart, tagsEnd} = match

# Unmatched text before next tags
Expand Down
2 changes: 1 addition & 1 deletion src/pattern.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Pattern
beginCaptures = []

for {start, end} in beginCaptureIndices
beginCaptures.push(line[start...end])
beginCaptures.push(line.substring(start, end))

resolvedMatch = @match.replace AllDigitsRegex, (match) ->
index = parseInt(match[1..])
Expand Down
3 changes: 1 addition & 2 deletions src/rule.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class Rule
capture.start = Math.min(capture.start, lineLength)
return

findNextMatch: (ruleStack, line, position, firstLine) ->
lineWithNewline = "#{line}\n"
findNextMatch: (ruleStack, lineWithNewline, position, firstLine) ->
baseGrammar = ruleStack[0].rule.grammar
results = []

Expand Down

0 comments on commit c0fe228

Please sign in to comment.