Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

regexp-tree

Package Overview
Dependencies
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexp-tree - npm Package Compare versions

Comparing version 0.0.85 to 0.0.86

35

dist/interpreter/finite-automaton/nfa/builders.js

@@ -173,3 +173,3 @@ /**

*/
function rep(fragment) {
function repExplicit(fragment) {
var inState = new NFAState();

@@ -191,2 +191,30 @@ var outState = new NFAState({

/**
* Optimized Kleene-star: just adds ε-transitions from
* input to the output, and back.
*/
function rep(fragment) {
fragment.in.addTransition(EPSILON, fragment.out);
fragment.out.addTransition(EPSILON, fragment.in);
return fragment;
}
/**
* Optimized Plus: just adds ε-transitions from
* the output to the input.
*/
function plusRep(fragment) {
fragment.out.addTransition(EPSILON, fragment.in);
return fragment;
}
/**
* Optimized ? repetition: just adds ε-transitions from
* the input to the output.
*/
function questionRep(fragment) {
fragment.in.addTransition(EPSILON, fragment.out);
return fragment;
}
module.exports = {

@@ -197,3 +225,6 @@ alt: alt,

or: or,
rep: rep
rep: rep,
repExplicit: repExplicit,
plusRep: plusRep,
questionRep: questionRep
};

33

dist/interpreter/finite-automaton/nfa/nfa-from-regexp.js

@@ -12,5 +12,2 @@ /**

var transform = require('../../../transform');
var desugaringTransforms = require('../transforms');
var _require = require('./builders'),

@@ -20,3 +17,5 @@ alt = _require.alt,

or = _require.or,
rep = _require.rep;
rep = _require.rep,
plusRep = _require.plusRep,
questionRep = _require.questionRep;

@@ -55,9 +54,12 @@ /**

Repetition: function Repetition(node) {
// Desugaring transforms should already convert
// `a+` to `aa*`, so handle only `*` here.
if (node.quantifier.kind !== '*') {
throw new Error('NFA/DFA: Only * quantifier is supported yet.');
switch (node.quantifier.kind) {
case '*':
return rep(gen(node.expression));
case '+':
return plusRep(gen(node.expression));
case '?':
return questionRep(gen(node.expression));
default:
throw new Error('Unknown repeatition: ' + node.quantifier.kind + '.');
}
return rep(gen(node.expression));
},

@@ -76,11 +78,2 @@ Char: function Char(node) {

function desugar(ast) {
var result = void 0;
desugaringTransforms.forEach(function (transformer) {
result = transform.transform(ast, transformer);
ast = result.getAST();
});
return ast;
}
module.exports = {

@@ -103,4 +96,4 @@ /**

return gen(desugar(ast));
return gen(ast);
}
};

@@ -1,2 +0,15 @@

declare namespace Node {
declare module 'regexp-tree/ast' {
export type AstClass =
| 'Char'
| 'ClassRange'
| 'CharacterClass'
| 'Alternative'
| 'Disjunction'
| 'Group'
| 'Backreference'
| 'Repetition'
| 'Quantifier'
| 'Assertion'
| 'RegExp';
interface Base<T> {

@@ -11,3 +24,3 @@ type: T;

interface SimpleChar extends Base<'Char'> {
export interface SimpleChar extends Base<'Char'> {
value: string;

@@ -18,3 +31,3 @@ kind: 'simple';

interface SpecialChar extends Base<'Char'> {
export interface SpecialChar extends Base<'Char'> {
value: string;

@@ -24,5 +37,5 @@ kind: 'meta' | 'control' | 'hex' | 'decimal' | 'oct' | 'unicode';

type Char = SimpleChar | SpecialChar;
export type Char = SimpleChar | SpecialChar;
interface ClassRange extends Base<'ClassRange'> {
export interface ClassRange extends Base<'ClassRange'> {
from: Char;

@@ -32,3 +45,3 @@ to: Char;

interface CharacterClass extends Base<'CharacterClass'> {
export interface CharacterClass extends Base<'CharacterClass'> {
negative?: true;

@@ -38,11 +51,11 @@ expressions: (Char | ClassRange)[];

interface Alternative extends Base<'Alternative'> {
export interface Alternative extends Base<'Alternative'> {
expressions: Expression[];
}
interface Disjunction extends Base<'Disjunction'> {
export interface Disjunction extends Base<'Disjunction'> {
expressions: (Expression | null)[];
}
interface CapturingGroup extends Base<'Group'> {
export interface CapturingGroup extends Base<'Group'> {
capturing: true;

@@ -54,3 +67,3 @@ number: number;

interface NoncapturingGroup extends Base<'Group'> {
export interface NoncapturingGroup extends Base<'Group'> {
capturing: false;

@@ -60,5 +73,5 @@ expression: Expression | null;

type Group = CapturingGroup | NoncapturingGroup;
export type Group = CapturingGroup | NoncapturingGroup;
interface NumericBackreference extends Base<'Backreference'> {
export interface NumericBackreference extends Base<'Backreference'> {
kind: 'number';

@@ -69,3 +82,3 @@ number: number;

interface NamedBackreference extends Base<'Backreference'> {
export interface NamedBackreference extends Base<'Backreference'> {
kind: 'name';

@@ -76,5 +89,5 @@ number: number;

type Backreference = NumericBackreference | NamedBackreference;
export type Backreference = NumericBackreference | NamedBackreference;
interface Repetition extends Base<'Repetition'> {
export interface Repetition extends Base<'Repetition'> {
expression: Expression;

@@ -84,21 +97,21 @@ quantifier: Quantifier;

interface SimpleQuantifier extends Base<'Quantifier'> {
kind: '+' | '*';
export interface SimpleQuantifier extends Base<'Quantifier'> {
kind: '+' | '*' | '?';
greedy: boolean;
}
interface RangeQuantifier extends Base<'Quantifier'> {
export interface RangeQuantifier extends Base<'Quantifier'> {
kind: 'Range';
from: number;
to: number;
to?: number;
greedy: boolean;
}
type Quantifier = SimpleQuantifier | RangeQuantifier;
export type Quantifier = SimpleQuantifier | RangeQuantifier;
interface SimpleAssertion extends Base<'Assertion'> {
export interface SimpleAssertion extends Base<'Assertion'> {
kind: '^' | '$' | '\\b' | '\\B';
}
interface LookaroundAssertion extends Base<'Assertion'> {
export interface LookaroundAssertion extends Base<'Assertion'> {
kind: 'Lookahead' | 'Lookbehind';

@@ -109,5 +122,5 @@ negative?: true;

type Assertion = SimpleAssertion | LookaroundAssertion;
export type Assertion = SimpleAssertion | LookaroundAssertion;
type Expression =
export type Expression =
| Char

@@ -122,3 +135,3 @@ | CharacterClass

interface RegExp extends Base<'RegExp'> {
export interface AstRegExp extends Base<'RegExp'> {
body: Expression | null;

@@ -129,6 +142,13 @@ flags: string;

interface ParserOptions {
captureLocations?: boolean;
}
declare module 'regexp-tree' {
import { AstRegExp } from 'regexp-tree/ast'
interface ParserOptions {
captureLocations?: boolean;
}
export function parse(s: string | RegExp, options?: ParserOptions): Node.RegExp;
export function parse(s: string | RegExp, options?: ParserOptions): AstRegExp;
export function generate(ast: AstRegExp): string;
export function toRegExp(regexp: string): RegExp;
}
{
"name": "regexp-tree",
"version": "0.0.85",
"version": "0.0.86",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Regular Expressions parser in JavaScript",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc