From 993ee75d8c70335e16a95e29c9235648c84aa056 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Wed, 7 Feb 2024 07:10:51 -0500 Subject: [PATCH 1/2] fix: don't add extraneous exports to the json and add missing rules to the schema --- cli/src/generate/dsl.js | 4 ++-- cli/src/generate/grammar-schema.json | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cli/src/generate/dsl.js b/cli/src/generate/dsl.js index 22286329..fc640a69 100644 --- a/cli/src/generate/dsl.js +++ b/cli/src/generate/dsl.js @@ -385,7 +385,7 @@ function grammar(baseGrammar, options) { throw new Error("Grammar must have at least one rule."); } - return { name, word, rules, extras, conflicts, precedences, externals, inline, supertypes }; + return { grammar: { name, word, rules, extras, conflicts, precedences, externals, inline, supertypes } }; } function checkArguments(ruleCount, caller, callerName, suffix = '') { @@ -419,4 +419,4 @@ global.grammar = grammar; global.field = field; const result = require(process.env.TREE_SITTER_GRAMMAR_PATH); -process.stdout.write(JSON.stringify(result, null, null)); +process.stdout.write(JSON.stringify(result.grammar, null, null)); diff --git a/cli/src/generate/grammar-schema.json b/cli/src/generate/grammar-schema.json index 952aac80..f6f2a4c0 100644 --- a/cli/src/generate/grammar-schema.json +++ b/cli/src/generate/grammar-schema.json @@ -31,6 +31,16 @@ } }, + "precedences": { + "type": "array", + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/rule" + } + } + }, + "externals": { "type": "array", "items": { @@ -240,7 +250,10 @@ "pattern": "^(PREC|PREC_LEFT|PREC_RIGHT|PREC_DYNAMIC)$" }, "value": { - "type": "integer" + "oneof": [ + { "type": "integer" }, + { "type": "string" } + ] }, "content": { "$ref": "#/definitions/rule" From 767db311144f2d5326eb62c4d57ede6ee79220f5 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Wed, 7 Feb 2024 07:13:03 -0500 Subject: [PATCH 2/2] fix: remove redundant code --- cli/src/generate/mod.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cli/src/generate/mod.rs b/cli/src/generate/mod.rs index cf8206e9..44f8b6e5 100644 --- a/cli/src/generate/mod.rs +++ b/cli/src/generate/mod.rs @@ -213,17 +213,13 @@ fn load_js_grammar_file(grammar_path: &Path, js_runtime: Option<&str>) -> Result let stdout = String::from_utf8(output.stdout).with_context(|| "Got invalid UTF8 from node")?; - let mut node_output = ""; let mut grammar_json = &stdout[..]; if let Some(pos) = stdout.rfind('\n') { // If there's a newline, split the last line from the rest of the output - node_output = &stdout[..pos]; + let node_output = &stdout[..pos]; grammar_json = &stdout[pos + 1..]; - } - // If we got any output from the node process that isn't the grammar JSON - if !node_output.is_empty() { let mut stdout = std::io::stdout().lock(); stdout.write_all(node_output.as_bytes())?; stdout.write_all(b"\n")?;