@elasticpath/epcc-search-ast-generator-js

中文文档
1.8.0发布于 2025/11/10MITTypeScriptCommonJS零依赖近 30 天下载 2809

此工程包含处理的全部逻辑 在 EPCC 中过滤该文件介绍了这一概念如何运作.

中文使用文档

过滤介绍.

此工程包含处理的全部逻辑 在 EPCC 中过滤。本文件提供 介绍这个概念是如何运作的.

我们经常遇到的一个问题是,我们有一个字符串,想要把它归类为有效或无效. 例如,这里有些事情你可能关心弦:

  1. 字符串以大写字母开头 .
  2. 字符串是有效的电子邮件地址 .
  3. 是弦是平面(写出相同的前向和后向,像再生机,公民,雷达,水平)
  4. 字符串是一个有效的 Java 程序 .

可以使用不同的技术来检查上面的内容,包括直接写出代码和使用正则表达式. 但有些事情比较复杂,比如案例3和案例4.

如果是最后一个,你可能会定义一个语法,那就是一套规则,说一个有效的字符串是什么样子的。 一个共同的技术是分两个阶段进行:

  1. Lexing - 将字符串转换成被称作符号的东西块,每个符号代表了字符串的某个部分(例如,在java程序中,您可能为每个关键词有一个符号). 更多细节载于 lexer.js 文件
  2. 解析 - 为检查出出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出自出 我们使用一个递归式的正方形解析器,这意味着每个语法规则都会调用一个功能来检查一个匹配,并可能递归调用其他函数.

我们试图分析的语法 在增强后背-瑙尔形式(https://www.rfc-editor.org/rfc/rfc5234 (中文(简体) ))如下:

(这种结构的一些方式是使代码更容易被读取)

root = or_expression eof

# Or support
or_expression = and_expression *( "|" and_expression )  

# And support
and_expression = group_expression  *( ":" group_expression )
and_expression =/ group_expression  *( "," group_expression ) // Legacy chaining operator

# Parenthesis support
group_expression =/ search_term
group_expression =/ "(" or_expression ")"


search_term = binary_term 
search_term =/ unary_term 
search_term =/ vararg_term 

binary_term = binary_operator "(" literal "," literal ")"
unary_term = unary_operator "(" literal ")"

# The code slightly deviates from this to handle weird cases for backwards compatability reasons, I hate
vararg_term = vararg_operator "(" literal "," literal *( "," literal ) ")"

# Everything below is largely handled as a function of the lexer
binary_operator = "eq" / "like" / "gt" / "ge " / "lt" / "le" / "text"
unary_operator = "is_null"
vararg_operator = "in"

; these literal represent standard unencoded literals.
literal = 1*(ALPHA / DIGIT / "$" / "-" / "_" / "*" / "." / " " / "{" / "}" / "@" / "|")

; we treat binary, unary & vararg operators as literals in cases where people want to do something like eq(foo, ne).
literal =/ binary_operator
literal =/ unary_operator
literal =/ vararg_operator

; 0x22 is a quotation mark
literal =/ 0x22 *string_characters 0x22
; there is probably a better way to write this in ABNF involving hex like 0x01-0x21 0x23-0x5B 0x5D-0x7E
string_character = any_character but not " or \
string_character =/ escape_sequence
escape_sequence = "\" 0x22

鼓励更多感兴趣的读者阅读: 域-特定语言,由Fowler编写,我们在此使用的两种技术是: (Regex Table Lexer p.239-244, Recursive Economic Parser p.245-255).

已发布软件包

https://www.npmjs.com/package/@elasticpath/epcc-search-ast-generator-js (中文(简体) )

版本与发布记录

@elasticpath/epcc-search-ast-generator-js 共发布 15 个版本,首次发布于 2024/02/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.8.0latest2025/11/101 年前
1.7.32025/01/281.8 年前
1.7.22025/01/241.8 年前
1.7.12025/01/241.8 年前
1.7.02024/07/192 年前
1.6.02024/04/232 年前

关于 @elasticpath/epcc-search-ast-generator-js 的常见问题

@elasticpath/epcc-search-ast-generator-js 是什么?

此工程包含处理的全部逻辑 在 EPCC 中过滤该文件介绍了这一概念如何运作.

如何安装 @elasticpath/epcc-search-ast-generator-js?

在项目目录运行 npm install @elasticpath/epcc-search-ast-generator-js,或使用 pnpm add / yarn add / bun add。

@elasticpath/epcc-search-ast-generator-js 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elasticpath/epcc-search-ast-generator-js 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@elasticpath/epcc-search-ast-generator-js 可以商用吗?

@elasticpath/epcc-search-ast-generator-js 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@elasticpath/epcc-search-ast-generator-js 的下载量有多少?

根据 npm 官方下载统计,@elasticpath/epcc-search-ast-generator-js 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,809 次,日均约 94 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elasticpath/epcc-search-ast-generator-js 还在维护吗?

最新版本 1.8.0 发布于 2025/11/10(1 年前);至今共发布 15 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/02/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。