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
|
||||
|
||||
if ast.children.len != 0:
|
||||
let
|
||||
rstr = ast.getRegexForAstChildren()
|
||||
|
||||
if childNames.contains(rstr.toPattern):
|
||||
if childNames.contains(ast.regex):
|
||||
if node.getTSNodeNamedChildCountSansComments() != 0:
|
||||
var flag = true
|
||||
for i in 0 .. node.tsNodeNamedChildCount()-1:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import tables
|
||||
|
||||
import regex
|
||||
|
||||
type
|
||||
Kind* = enum
|
||||
exactlyOne
|
||||
|
|
@ -12,6 +14,7 @@ type
|
|||
kind*: Kind
|
||||
children*: seq[ref Ast]
|
||||
tonim*: proc () {.closure, locks: 0.}
|
||||
regex*: Regex
|
||||
|
||||
State* = object
|
||||
compile*, defines*, headers*, includeDirs*, searchDirs*: seq[string]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import strformat, tables
|
||||
|
||||
import regex
|
||||
|
||||
import "."/[getters, globals, lisp]
|
||||
|
||||
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*() =
|
||||
initGrammar()
|
||||
|
||||
|
|
@ -263,6 +272,7 @@ proc parseGrammar*() =
|
|||
ast = gStateRT.grammar[i].grammar.parseLisp()
|
||||
|
||||
ast.tonim = gStateRT.grammar[i].call
|
||||
ast.initRegex()
|
||||
if ast.name notin gStateRT.ast:
|
||||
gStateRT.ast[ast.name] = @[ast]
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue