Add associative map constraints and range refinement

This commit is contained in:
2026-08-14 06:26:15 +09:00
parent 8198b615a8
commit cc6ab40807
52 changed files with 8951 additions and 6918 deletions
+18 -2
View File
@@ -2,6 +2,7 @@
// doc/manual/souce/language/grammar.md.
const PREC = {
AS: 0,
DEFAULT: 1,
PATCH: 2,
COMPOSE: 3,
@@ -53,6 +54,7 @@ module.exports = grammar({
$.identifier,
$.regex_literal,
$.comparison_constraint,
$.map_constraint,
$.object,
$.array_constraint,
$.array,
@@ -66,6 +68,7 @@ module.exports = grammar({
$.unary_expression,
$.binary_expression,
$.default_expression,
$.as_expression,
),
literal: $ => choice(
@@ -100,6 +103,13 @@ module.exports = grammar({
'}',
),
map_constraint: $ => seq(
'{',
'...',
field('value', $._expression),
'}',
),
field_definition: $ => seq(
field('path', $.field_path),
'=',
@@ -125,12 +135,12 @@ module.exports = grammar({
']',
),
let_expression: $ => seq(
let_expression: $ => prec.right(seq(
'let',
repeat(seq($.field_definition, ';')),
'in',
field('body', $._expression),
),
)),
function_expression: $ => prec.right(seq(
'(',
@@ -237,5 +247,11 @@ module.exports = grammar({
'default',
field('fallback', $._expression),
)),
as_expression: $ => prec.left(PREC.AS, seq(
field('narrower', $._expression),
'as',
field('wider', $._expression),
)),
},
});