peggy
Use when writing PEG grammars with Peggy (formerly PEG.js) - parsing expression grammars, parser generation, and syntax definition
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when writing PEG grammars with Peggy (formerly PEG.js) - parsing expression grammars, parser generation, and syntax definition
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Use when writing or editing .omg.md files - the human-first DSL for API specification that compiles to OpenAPI 3.1
Use when building CLI tools with Commander.js - commands, options, arguments, and help text for Node.js command-line applications
Use when parsing or generating Markdown following the CommonMark specification - AST structure, block/inline elements, and extensions
Use when creating GitHub Actions workflows for CI/CD - testing, building, publishing npm packages, and automating repository tasks
Use when working with JSON Schema for validation, OpenAPI schemas, type definitions, and data structure specification
Use when implementing Language Server Protocol features - diagnostics, completions, hover, go-to-definition, and editor integration
| name | peggy |
| description | Use when writing PEG grammars with Peggy (formerly PEG.js) - parsing expression grammars, parser generation, and syntax definition |
// grammar.peggy
Expression = head:Term tail:(_ ("+" / "-") _ Term)* {
return tail.reduce((result, [, op, , term]) => {
return op === "+" ? result + term : result - term;
}, head);
}
Term = Integer / "(" _ expr:Expression _ ")" { return expr; }
Integer = digits:[0-9]+ { return parseInt(digits.join(""), 10); }
_ = [ \t\n\r]*
import * as peggy from 'peggy';
import fs from 'fs';
const grammar = fs.readFileSync('grammar.peggy', 'utf-8');
const parser = peggy.generate(grammar);
const result = parser.parse('2 + 3 * 4'); // 14
| Pattern | Meaning |
|---|---|
"literal" | Match exact string |
[a-z] | Character class |
rule1 / rule2 | Ordered choice (try rule1 first) |
rule* | Zero or more |
rule+ | One or more |
rule? | Optional |
&rule | Positive lookahead |
!rule | Negative lookahead |
label:rule | Capture as variable |
{ code } | Action (return value) |
// Named rule
Identifier = [a-zA-Z_][a-zA-Z0-9_]* { return text(); }
// With semantic action
Number = digits:[0-9]+ { return parseInt(digits.join(""), 10); }
// Choice with labels
BinaryOp = left:Term op:("+" / "-") right:Term {
return { type: "binary", op, left, right };
}
text() - Matched text as stringlocation() - Start/end positionsexpected(desc) - Throw expected errorerror(message) - Throw custom errornpx peggy grammar.peggy -o parser.js
npx peggy --format es grammar.peggy # ES module output
!. for "not end of input"_ rule for optional whitespace@ prefix for pluck: @value:Rule returns just the labeled value