Skip to content

Commit

Permalink
Merge pull request #20 from hildjj/update-grammar
Browse files Browse the repository at this point in the history
Update grammar to match peggy 4.0.0
  • Loading branch information
hildjj authored Feb 15, 2024
2 parents 3c9d08c + c0bc450 commit 1886c1f
Show file tree
Hide file tree
Showing 15 changed files with 453 additions and 170 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ trim_trailing_whitespace = true
charset = utf-8
indent_style = space
indent_size = 2

[Makefile]
indent_style = tab
indent_size = 4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ lib/
node_modules/
pnpm-lock.yaml
src/parser.js
test/fixtures/*.js
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = [
"node_modules/**",
"src/parser.d.ts",
"src/parser.js",
"test/fixtures/*.js",
],
},
require("@peggyjs/eslint-config/flat/js"),
Expand Down
142 changes: 45 additions & 97 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 58 additions & 1 deletion src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import type * as EStree from "estree";
*/
export const visitorKeys = {
Program: ["body", "comments"],
grammar: ["topLevelInitializer", "initializer", "rules"],
grammar: ["imports", "topLevelInitializer", "initializer", "rules"],
grammar_import: ["what", "from"],
binding: [],
import_binding: ["binding"],
import_binding_all: ["binding"],
import_binding_default: ["binding"],
import_binding_rename: ["rename", "binding"],
import_module_specifier: ["before", "after"],
module_export_name: ["before", "after"],
top_level_initializer: ["open", "code", "close", "semi"],
initializer: ["code", "semi"],
rule: ["name", "equals", "expression", "semi"],
Expand All @@ -31,6 +39,7 @@ export const visitorKeys = {
group: ["open", "expression", "close"],
semantic_and: ["operator", "code"],
semantic_not: ["operator", "code"],
library_ref: ["name", "library"],
rule_ref: ["name"],
literal: ["before", "after"],
display: ["before", "after"],
Expand Down Expand Up @@ -82,11 +91,47 @@ export interface Program extends BaseNode<"Program"> {
}

export interface Grammar extends BaseNode<"grammar"> {
imports: Import[];
topLevelInitializer?: TopLevelInitializer;
initializer?: Initializer;
rules: Rule[];
}

export interface Import extends BaseNode<"grammar_import"> {
what: (
| ImportBinding
| ImportBindingAll
| ImportBindingDefault
| ImportBindingRename
)[];
from: ImportModuleSpecifier;
}

export interface ImportBinding extends BaseNode<"import_binding"> {
binding: Binding;
}

export interface ImportBindingAll extends BaseNode<"import_binding_all"> {
binding: Binding;
}

export interface ImportBindingDefault extends BaseNode<"import_binding_default"> {
binding: Binding;
}

export interface ImportBindingRename extends BaseNode<"import_binding_rename"> {
rename: string;
binding: Binding;
}

export interface Binding extends BaseNode<"binding"> {
id?: string;
}

export type ImportModuleSpecifier = QuotedString<"import_module_specifier">;

export type ModuleExportName = QuotedString<"module_export_name">;

export type TopLevelInitializer = BaseNode<"top_level_initializer">
& Bracketed & Coded & Terminated;
export type Initializer = BaseNode<"initializer"> & Coded & Terminated;
Expand Down Expand Up @@ -177,6 +222,7 @@ interface QuotedString<T extends NodeTypes> extends ValueExpression<T> {
before: Punctuation;
after: Punctuation;
raw: string;
value: string;
}

export interface LiteralExpression extends QuotedString<"literal"> {
Expand Down Expand Up @@ -256,6 +302,16 @@ export type Expression
| SequenceExpression
| SuffixedExpression;

export type ImportDtails
= Binding
| Import
| ImportBinding
| ImportBindingAll
| ImportBindingDefault
| ImportBindingRename
| ImportModuleSpecifier
| ModuleExportName;

export type Node
= Boundaries
| Boundary
Expand All @@ -268,6 +324,7 @@ export type Node
| DisplayName
| Expression
| Grammar
| ImportDtails
| Initializer
| Name
| Program
Expand Down
Loading

0 comments on commit 1886c1f

Please sign in to comment.