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

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

This project contains all the logic for processing filtering in EPCC. This document provides an introduction into how this conceptually works.

原始使用文档

Filtering Introduction.

This project contains all the logic for processing filtering in EPCC. This document provides an introduction into how this conceptually works.

A problem we often have is that we have a string, and want to classify it as being valid or invalid. For instance here are some things you might care about strings:

  1. Does a string start with a capital letter.
  2. Is a string a valid email address.
  3. Is a string a palindrome (written the same forwards and backwards like redivider, civic, radar, level)
  4. Is a string a valid Java program.

There are different techniques that can be used to check the above, including writing code directly and using a regular expression. But some things are more complicated, like case #3 and #4.

In the case of the last one, you would likely define a grammar which is a set of rules that say what a valid string looks like. A common technique is to proceed in two phases:

  1. Lexing - Converting the string into chunks of things called tokens, each token representing a some part of the string (e.g., in a java program you might have a token for each keyword). More details are in the lexer.js file
  2. Parsing - Write rules for checking the output of the lexer. We use a recursive decent parser, which means that each grammar rule calls a function that checks for a match and may recursively call other functions.

The grammar that we are attempting to parse in Augmented Backus-Naur Form (https://www.rfc-editor.org/rfc/rfc5234) is the following:

(Some of the way this is structured is to make the code easier to read)

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

A more interested reader is encouraged to read: Domain-Specific Languages, by Fowler, the two techniques we use here are: (Regex Table Lexer p.239-244, Recursive Descent Parser p.245-255).

Released Package

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 是什么?

This project contains all the logic for processing filtering in EPCC. This document provides an introduction into how this conceptually works.

如何安装 @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 和提交记录判断。