regexppECMAScript 的正则表达式解析器
regexpp 是一个适用于 ECMAScript 的正则表达式解析器。
安装
$ npm install regexpp
- 需要 Node.js 8 或更新版本。
用法
import { AST, RegExpParser, RegExpValidator, RegExpVisitor, parseRegExpLiteral, validateRegExpLiteral, visitRegExpAST } from "regexpp"
parseRegExpLiteral
解析给定的正则表达式文字,然后生成 AST 对象。
这相当于new RegExpParser(options).parseLiteral(source).
-  参数: 
  -  source(string | RegExp) 要解析的源代码。
-  options?(RegExpParser.Options) 要解析的选项。
 
-  
-  返回: 
  - 正则表达式的 AST。
 
validateRegExpLiteral
验证给定的正则表达式。
这相当于new RegExpValidator(options).validateLiteral(source).
-  参数: 
  -  source(string) 要验证的源代码。
-  options?(RegExpValidator.Options) 要验证的选项。
 
-  
访问 RegExpAST
访问给定 AST 的每个节点。
这相当于new RegExpVisitor(handlers).visit(ast).
-  参数: 
  -  ast(AST.Node) 要访问的 AST。
-  handlers(RegExpVisitor.Handlers) 回调。
 
-  
正则解析器
新的 RegExpParser
-  参数: 
  -  options?(RegExpParser.Options) 要解析的选项。
 
-  
parser.parseLiteral
解析正则表达式文字。
-  参数: 
  -  source(string) 要解析的源代码。例如"/abc/g"。
-  start?(number) 源代码中的起始索引。默认为0。
-  end?(number) 源代码中的结束索引。默认为source.length。
 
-  
-  返回: 
  - 正则表达式的 AST。
 
parser.parsePattern
解析正则表达式模式。
-  参数: 
  -  source(string) 要解析的源代码。例如"abc"。
-  start?(number) 源代码中的起始索引。默认为0。
-  end?(number) 源代码中的结束索引。默认为source.length。
-  uFlag?(boolean) 启用 Unicode 模式的标志。
 
-  
-  返回: 
  - 正则表达式模式的 AST。
 
parser.parseFlags
解析正则表达式标志。
-  参数: 
  -  source(string) 要解析的源代码。例如"gim"。
-  start?(number) 源代码中的起始索引。默认为0。
-  end?(number) 源代码中的结束索引。默认为source.length。
 
-  
-  返回: 
  - 正则表达式标志的 AST。
 
评论
