diff --git a/crates/frontend/src/ast.rs b/crates/frontend/src/ast.rs index 4881bad..62b2d4c 100644 --- a/crates/frontend/src/ast.rs +++ b/crates/frontend/src/ast.rs @@ -23,8 +23,6 @@ use strum::{EnumDiscriminants, EnumIter}; use crate::prelude::*; -// TODO: rename all `atom` references to `apply` - /// Retrieves, but does not parse, all top-level items in a file. // TODO: is `Vec` the most efficient to incrementally update here? #[salsa::tracked] @@ -231,7 +229,7 @@ pub fn expr(db: &dyn Database, ast: AstNode) -> Expr { } else if let Some(var) = ast.get_field(db, "variable") { let name = var.contents(db).to_string(); Extra(Arc::new(ExprExtra::VariableName(name))) - } else if let Some(ast) = ast.get_field(db, "atom") { + } else if let Some(ast) = ast.get_field(db, "apply") { Extra(Arc::new(ExprExtra::Apply(apply(db, ast)))) } else if let Some(tuple) = ast.get_field(db, "tuple") { let els = tuple.get_fields(db, "el").map(|el| expr(db, el)).collect(); @@ -280,7 +278,7 @@ pub fn aggregate(db: &dyn Database, ast: AstNode) -> Aggregate { .map(|ast| ast.with_contents(db)) .collect(); - let body = if let Some(ast) = ast.get_field(db, "atom") { + let body = if let Some(ast) = ast.get_field(db, "apply") { AggregateBody::Apply(apply(db, ast)) } else { let clauses = ast.get_fields(db, "clause").map(|ast| expr(db, ast)); diff --git a/tree-sitter-kerolox/grammar.js b/tree-sitter-kerolox/grammar.js index b850c1c..1318f0a 100644 --- a/tree-sitter-kerolox/grammar.js +++ b/tree-sitter-kerolox/grammar.js @@ -112,7 +112,7 @@ export default grammar({ field("variable", $.variable), // composites - field("atom", $.atom), + field("apply", $.apply), field("tuple", $.tuple), field("aggregate", $.aggregate), @@ -130,8 +130,7 @@ export default grammar({ seq('(', field("parens", $.expr), ')'), ), - // TODO: rename to "apply" - atom: $ => prec.right(2, seq(field("head", $.symbol), field("body", $.expr))), + apply: $ => prec.right(2, seq(field("head", $.symbol), field("body", $.expr))), tuple: $ => parenListComma(field("el", $.expr)), @@ -139,7 +138,7 @@ export default grammar({ field("op", $.aggregate_op), optional(seq(list(field("witness", $.variable)), ":")), choice( - field("atom", $.atom), + field("apply", $.apply), seq("{", field("body", $.rule_body ), "}"), ), ), diff --git a/tree-sitter-kerolox/queries/highlights.scm b/tree-sitter-kerolox/queries/highlights.scm index 82394d3..5f7705a 100644 --- a/tree-sitter-kerolox/queries/highlights.scm +++ b/tree-sitter-kerolox/queries/highlights.scm @@ -10,7 +10,7 @@ (rule relation: (symbol) @constructor) (definition relation: (symbol) @function) -(atom head: (symbol) @function) +(apply head: _ @function) [ ":-" "," "." ":" ] @punctuation.delimiter [ "(" ")" "{" "}" ] @punctuation.bracket diff --git a/tree-sitter-kerolox/src/grammar.json b/tree-sitter-kerolox/src/grammar.json index 5ed75f1..379fd1e 100644 --- a/tree-sitter-kerolox/src/grammar.json +++ b/tree-sitter-kerolox/src/grammar.json @@ -545,10 +545,10 @@ }, { "type": "FIELD", - "name": "atom", + "name": "apply", "content": { "type": "SYMBOL", - "name": "atom" + "name": "apply" } }, { @@ -638,7 +638,7 @@ } ] }, - "atom": { + "apply": { "type": "PREC_RIGHT", "value": 2, "content": { @@ -784,10 +784,10 @@ "members": [ { "type": "FIELD", - "name": "atom", + "name": "apply", "content": { "type": "SYMBOL", - "name": "atom" + "name": "apply" } }, { diff --git a/tree-sitter-kerolox/src/node-types.json b/tree-sitter-kerolox/src/node-types.json index ea603b2..3da8ffd 100644 --- a/tree-sitter-kerolox/src/node-types.json +++ b/tree-sitter-kerolox/src/node-types.json @@ -3,12 +3,12 @@ "type": "aggregate", "named": true, "fields": { - "atom": { + "apply": { "multiple": false, "required": false, "types": [ { - "type": "atom", + "type": "apply", "named": true } ] @@ -45,6 +45,32 @@ } } }, + { + "type": "apply", + "named": true, + "fields": { + "body": { + "multiple": false, + "required": true, + "types": [ + { + "type": "expr", + "named": true + } + ] + }, + "head": { + "multiple": false, + "required": true, + "types": [ + { + "type": "symbol", + "named": true + } + ] + } + } + }, { "type": "assumption", "named": true, @@ -71,32 +97,6 @@ } } }, - { - "type": "atom", - "named": true, - "fields": { - "body": { - "multiple": false, - "required": true, - "types": [ - { - "type": "expr", - "named": true - } - ] - }, - "head": { - "multiple": false, - "required": true, - "types": [ - { - "type": "symbol", - "named": true - } - ] - } - } - }, { "type": "binary_expr", "named": true, @@ -267,12 +267,12 @@ } ] }, - "atom": { + "apply": { "multiple": false, "required": false, "types": [ { - "type": "atom", + "type": "apply", "named": true } ] diff --git a/tree-sitter-kerolox/src/parser.c b/tree-sitter-kerolox/src/parser.c index 8f35598..1faee5b 100644 --- a/tree-sitter-kerolox/src/parser.c +++ b/tree-sitter-kerolox/src/parser.c @@ -72,7 +72,7 @@ enum ts_symbol_identifiers { sym_assumption = 50, sym_rule_body = 51, sym_expr = 52, - sym_atom = 53, + sym_apply = 53, sym_tuple = 54, sym_aggregate = 55, sym_unary_expr = 56, @@ -141,7 +141,7 @@ static const char * const ts_symbol_names[] = { [sym_assumption] = "assumption", [sym_rule_body] = "rule_body", [sym_expr] = "expr", - [sym_atom] = "atom", + [sym_apply] = "apply", [sym_tuple] = "tuple", [sym_aggregate] = "aggregate", [sym_unary_expr] = "unary_expr", @@ -210,7 +210,7 @@ static const TSSymbol ts_symbol_map[] = { [sym_assumption] = sym_assumption, [sym_rule_body] = sym_rule_body, [sym_expr] = sym_expr, - [sym_atom] = sym_atom, + [sym_apply] = sym_apply, [sym_tuple] = sym_tuple, [sym_aggregate] = sym_aggregate, [sym_unary_expr] = sym_unary_expr, @@ -438,7 +438,7 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { .visible = true, .named = true, }, - [sym_atom] = { + [sym_apply] = { .visible = true, .named = true, }, @@ -494,7 +494,7 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { enum ts_field_identifiers { field_aggregate = 1, - field_atom = 2, + field_apply = 2, field_binary = 3, field_body = 4, field_clause = 5, @@ -530,7 +530,7 @@ enum ts_field_identifiers { static const char * const ts_field_names[] = { [0] = NULL, [field_aggregate] = "aggregate", - [field_atom] = "atom", + [field_apply] = "apply", [field_binary] = "binary", [field_body] = "body", [field_clause] = "clause", @@ -639,7 +639,7 @@ static const TSFieldMapEntry ts_field_map_entries[] = { [5] = {field_integer, 0}, [6] = - {field_atom, 0}, + {field_apply, 0}, [7] = {field_tuple, 0}, [8] = @@ -654,7 +654,7 @@ static const TSFieldMapEntry ts_field_map_entries[] = { {field_body, 1}, {field_head, 0}, [14] = - {field_atom, 1}, + {field_apply, 1}, {field_op, 0}, [16] = {field_head, 1}, @@ -721,7 +721,7 @@ static const TSFieldMapEntry ts_field_map_entries[] = { [57] = {field_witness, 1}, [58] = - {field_atom, 3}, + {field_apply, 3}, {field_op, 0}, {field_witness, 1}, [61] = @@ -754,7 +754,7 @@ static const TSFieldMapEntry ts_field_map_entries[] = { {field_relation, 3}, {field_type, 4}, [83] = - {field_atom, 4}, + {field_apply, 4}, {field_op, 0}, {field_witness, 1}, {field_witness, 2, .inherited = true}, @@ -1711,7 +1711,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [sym_comment] = STATE(2), [sym_integer] = STATE(46), [sym_expr] = STATE(37), - [sym_atom] = STATE(28), + [sym_apply] = STATE(28), [sym_tuple] = STATE(30), [sym_aggregate] = STATE(24), [sym_unary_expr] = STATE(27), @@ -1783,7 +1783,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -1829,7 +1829,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -1877,7 +1877,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -1921,7 +1921,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -1967,7 +1967,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2013,7 +2013,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2059,7 +2059,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2105,7 +2105,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2151,7 +2151,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2195,7 +2195,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2235,7 +2235,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2282,7 +2282,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2326,7 +2326,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2372,7 +2372,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2414,7 +2414,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2458,7 +2458,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2502,7 +2502,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2546,7 +2546,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2590,7 +2590,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -2634,7 +2634,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(27), 1, sym_unary_expr, STATE(28), 1, - sym_atom, + sym_apply, STATE(29), 1, sym_binary_expr, STATE(30), 1, @@ -4074,7 +4074,7 @@ static const uint16_t ts_small_parse_table[] = { ACTIONS(276), 1, anon_sym_LBRACE, STATE(26), 1, - sym_atom, + sym_apply, STATE(84), 1, sym_comment, [3084] = 6, @@ -4237,7 +4237,7 @@ static const uint16_t ts_small_parse_table[] = { ACTIONS(313), 1, anon_sym_LBRACE, STATE(41), 1, - sym_atom, + sym_apply, STATE(96), 1, sym_comment, [3321] = 6, @@ -4428,7 +4428,7 @@ static const uint16_t ts_small_parse_table[] = { ACTIONS(346), 1, anon_sym_LBRACE, STATE(45), 1, - sym_atom, + sym_apply, STATE(111), 1, sym_comment, [3598] = 6, @@ -5145,8 +5145,8 @@ static const TSParseActionEntry ts_parse_actions[] = { [103] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_expr, 3, 0, 21), [105] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), [107] = {.entry = {.count = 1, .reusable = false}}, SHIFT(16), - [109] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_atom, 2, 0, 13), - [111] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_atom, 2, 0, 13), + [109] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_apply, 2, 0, 13), + [111] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_apply, 2, 0, 13), [113] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tuple, 4, 0, 33), [115] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_tuple, 4, 0, 33), [117] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_tuple, 4, 0, 34),