assemblyscript-regex
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -23,4 +23,5 @@ { | ||
"options": { | ||
"transform": [] | ||
"transform": [], | ||
"exportRuntime": true | ||
} | ||
} |
@@ -27,5 +27,7 @@ import { | ||
let _stateId: u32 = 0; | ||
/* eslint @typescript-eslint/no-empty-function: ["error", { "allow": ["constructors", "methods"] }] */ | ||
export class State { | ||
constructor(public transitions: State[] = []) {} | ||
constructor(public transitions: State[] = [], public id: u32 = _stateId++) {} | ||
@@ -44,3 +46,3 @@ matches(input: string, position: u32): MatchResult { | ||
constructor(next: State, public id: i32) { | ||
constructor(next: State, public groupId: i32) { | ||
super(); | ||
@@ -47,0 +49,0 @@ this.transitions.push(next); |
@@ -12,10 +12,12 @@ import { State, Automata, GroupStartMarkerState, MatchResult } from "./nfa/nfa"; | ||
input: string, | ||
visited: State[] = [], | ||
visited: u32[] = [], | ||
position: i32 = 0 | ||
): string | null { | ||
// prevent endless loops when following epsilon transitions | ||
if (visited.includes(state)) { | ||
return null; | ||
for (let i = 0, len = visited.length; i < len; i++) { | ||
if (visited[i] == state.id) { | ||
return null; | ||
} | ||
} | ||
visited.push(state); | ||
visited.push(state.id); | ||
@@ -96,7 +98,7 @@ const matches = state.matches(input, position); | ||
const values = [first(groupMarkers).capture]; | ||
let currrentId = first(groupMarkers).id; | ||
let currrentId = first(groupMarkers).groupId; | ||
for (let i = 0; i < groupMarkers.length; i++) { | ||
const gm = groupMarkers[i]; | ||
if (gm.id != currrentId) { | ||
currrentId = gm.id; | ||
if (gm.groupId != currrentId) { | ||
currrentId = gm.groupId; | ||
values.push(gm.capture); | ||
@@ -103,0 +105,0 @@ } else { |
global.TextDecoder = require("text-encoding").TextDecoder; | ||
const fs = require("fs"); | ||
const loader = require("@assemblyscript/loader/umd/index"); | ||
const loader = require("@assemblyscript/loader"); | ||
@@ -13,6 +13,4 @@ const Benchmark = require("benchmark"); | ||
log: () => { | ||
const { __getString, __release } = wasmModule.exports; | ||
str = __getString(strPtr); | ||
console.log(str); | ||
__release(strPtr); | ||
const { __getString } = wasmModule.exports; | ||
console.log(__getString(strPtr)); | ||
}, | ||
@@ -25,15 +23,9 @@ }, | ||
function executeRegex(regexStr, valueStr, untilNull = false) { | ||
const { | ||
executeRegExp, | ||
__newString, | ||
__retain, | ||
__release, | ||
} = wasmModule.exports; | ||
const { executeRegExp, __newString, __pin, __unpin } = wasmModule.exports; | ||
// create the regexp | ||
const regexPtr = __retain(__newString(regexStr)); | ||
const strPtr = __retain(__newString(valueStr)); | ||
const regexPtr = __pin(__newString(regexStr)); | ||
const strPtr = __newString(valueStr); | ||
executeRegExp(regexPtr, strPtr, untilNull ? -1 : 5); | ||
__release(regexPtr); | ||
__release(strPtr); | ||
__unpin(regexPtr); | ||
} | ||
@@ -40,0 +32,0 @@ |
{ | ||
"name": "assemblyscript-regex", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "A regex engine built with AssemblyScript", | ||
@@ -24,4 +24,4 @@ "ascMain": "assembly/index.ts", | ||
"devDependencies": { | ||
"@as-pect/cli": "^5.0.1", | ||
"@assemblyscript/loader": "^0.17.5", | ||
"@as-pect/cli": "^6.0.0", | ||
"@assemblyscript/loader": "^0.18.0", | ||
"@types/node": "^14.14.13", | ||
@@ -31,3 +31,3 @@ "@typescript-eslint/eslint-plugin": "^4.14.1", | ||
"asbuild": "0.0.10", | ||
"assemblyscript": "0.17.5", | ||
"assemblyscript": "^0.18.0", | ||
"benchmark": "^2.1.4", | ||
@@ -34,0 +34,0 @@ "eslint": "^7.18.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
252677
4461