Fix performance issues with regex
This commit is contained in:
parent
cb100ca571
commit
cf2f200a16
3 changed files with 14 additions and 4 deletions
|
|
@ -53,10 +53,7 @@ proc searchAstForNode(ast: ref Ast, node: TSNode): bool =
|
||||||
return
|
return
|
||||||
|
|
||||||
if ast.children.len != 0:
|
if ast.children.len != 0:
|
||||||
let
|
if childNames.contains(ast.regex):
|
||||||
rstr = ast.getRegexForAstChildren()
|
|
||||||
|
|
||||||
if childNames.contains(rstr.toPattern):
|
|
||||||
if node.getTSNodeNamedChildCountSansComments() != 0:
|
if node.getTSNodeNamedChildCountSansComments() != 0:
|
||||||
var flag = true
|
var flag = true
|
||||||
for i in 0 .. node.tsNodeNamedChildCount()-1:
|
for i in 0 .. node.tsNodeNamedChildCount()-1:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import tables
|
import tables
|
||||||
|
|
||||||
|
import regex
|
||||||
|
|
||||||
type
|
type
|
||||||
Kind* = enum
|
Kind* = enum
|
||||||
exactlyOne
|
exactlyOne
|
||||||
|
|
@ -12,6 +14,7 @@ type
|
||||||
kind*: Kind
|
kind*: Kind
|
||||||
children*: seq[ref Ast]
|
children*: seq[ref Ast]
|
||||||
tonim*: proc () {.closure, locks: 0.}
|
tonim*: proc () {.closure, locks: 0.}
|
||||||
|
regex*: Regex
|
||||||
|
|
||||||
State* = object
|
State* = object
|
||||||
compile*, defines*, headers*, includeDirs*, searchDirs*: seq[string]
|
compile*, defines*, headers*, includeDirs*, searchDirs*: seq[string]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import strformat, tables
|
import strformat, tables
|
||||||
|
|
||||||
|
import regex
|
||||||
|
|
||||||
import "."/[getters, globals, lisp]
|
import "."/[getters, globals, lisp]
|
||||||
|
|
||||||
proc initGrammar() =
|
proc initGrammar() =
|
||||||
|
|
@ -254,6 +256,13 @@ proc initGrammar() =
|
||||||
|
|
||||||
))
|
))
|
||||||
|
|
||||||
|
proc initRegex(ast: ref Ast) =
|
||||||
|
if ast.children.len != 0:
|
||||||
|
for child in ast.children:
|
||||||
|
child.initRegex()
|
||||||
|
|
||||||
|
ast.regex = ast.getRegexForAstChildren().re()
|
||||||
|
|
||||||
proc parseGrammar*() =
|
proc parseGrammar*() =
|
||||||
initGrammar()
|
initGrammar()
|
||||||
|
|
||||||
|
|
@ -263,6 +272,7 @@ proc parseGrammar*() =
|
||||||
ast = gStateRT.grammar[i].grammar.parseLisp()
|
ast = gStateRT.grammar[i].grammar.parseLisp()
|
||||||
|
|
||||||
ast.tonim = gStateRT.grammar[i].call
|
ast.tonim = gStateRT.grammar[i].call
|
||||||
|
ast.initRegex()
|
||||||
if ast.name notin gStateRT.ast:
|
if ast.name notin gStateRT.ast:
|
||||||
gStateRT.ast[ast.name] = @[ast]
|
gStateRT.ast[ast.name] = @[ast]
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue