diff --git a/src/v4/extdeps/languages/ecmascript.dag b/src/v4/extdeps/languages/ecmascript.dag new file mode 100644 index 00000000000..4f6025749f6 --- /dev/null +++ b/src/v4/extdeps/languages/ecmascript.dag @@ -0,0 +1,1732 @@ +// src/v4/extdeps/languages/ecmascript.dag +// Scope: ECMAScript ES2022 (ECMA-262 13th Edition) primitive fact-bundles + T-11 MVP-1 grammar-data target model. +// Owns: EcmascriptSingletonKind, EcmascriptScalar, EcmascriptCost, EcmascriptConcreteSyntaxToken, +// EcmascriptGrammarRelationRow, EcmascriptLanguageModel, EcmascriptNumberPrimitiveFacts, +// EcmascriptBigIntPrimitiveFacts, EcmascriptBooleanPrimitiveFacts, EcmascriptStringPrimitiveFacts, +// EcmascriptSingletonPrimitiveFacts, ecmascript_language_model_wave1 (+ supporting fns). +// Consumes: v4.std.model_core, v4.std.collection, v4.std.node, v4.std.logic, v4.std.algebra, +// v4.std.lexing, v4.std.grammar, v4.std.target_model, v4.std.witness, v4.std.text. +// Status: T-4.17 ecmascript slice (NEW) โ€” ECMA-262 ES2022 primitives; ModelCore inhabitance for +// number/bigint/boolean; string inhabitance deferred; laws/effects/partiality empty (wave-2b); +// ๐ŸŸก gated feature:T-6-token-layout-trivia-policy + feature:ecmascript-wave2a-decimal-int-literal +// (decimal `0` | [1-9][0-9]* only; not 0b/0o/0x/numeric-separators); canonical_symbols via catalog +// + wave-1 lex/grammar/MVP; bool canonical-B decl-ref โ€” ๐ŸŸก E-6(b) staging. NO TypeScript type +// annotations โ€” base ES surface only; `typescript.dag` is the TS surface authority. +// Anchor: https://tc39.es/ecma262/2022/ (ECMA-262, 13th Edition, June 2022). +// Ledger: CP-3229-GREEN-TERMINAL, SL-T11-GRAMMAR-FROM-TOKEN-ROW. +// ๐ŸŸก + +module v4.extdeps.languages.ecmascript + +import v4.std.algebra { Empty, fold_list, list_append, list_snoc_item } +import v4.std.grammar { + ParseGrammar, + GrammarExpr, + GrammarProduction, + GrammarRoot, + ModeledGrammar, + Choice, + grammar_formal_terminal, + grammar_formal_nonterminal_occurrence, + grammar_formal_production, + FormalGrammarSymbol, + FormalNonterminal, + FormalNonterminalOccurrence, + FormalProduction, + FormalTerminal, + FormalTerminalOccurrence, + Nonterminal, + Optional, + Sequence, + Terminal, + grammar_carries_symbol, + grammar_empty_sync_tokens, + formal_production_to_node +} +import v4.std.lexing { + CharClassPattern, + CharPattern, + ChoicePattern, + DigitChar, + IdentContinueChar, + IdentStartChar, + LexPattern, + LexRule, + LexRuleSet, + LexRules, + LiteralPattern, + ModeledLexRules, + RepeatPattern, + SequencePattern, + TokenRule, + lex_rule_set_token_class_member +} +import v4.std.target_model { TargetModel } +import v4.std.collection { List, Map, Set, empty_map, map_insert } +import v4.std.model_core { + AlgebraInhabitanceDecl, + EffectSemanticsDecl, + ModelCore, + PartialitySemanticsDecl, + PrimitiveFactBundle, + primitive_fact_axis_encoding, + primitive_fact_axis_surface_spelling, + primitive_fact_axis_unbound_diagnostic +} +import v4.std.witness { Holds, Violates } +import v4.std.node { + Arrow, + Atom, + Conj, + Edge, + Named, + Node, + Positional, + Symbol, + TypeNode +} +import v4.std.target_model { + concrete_syntax_token_field_binding, + concrete_syntax_token_field_class, + concrete_syntax_token_field_kind, + concrete_syntax_token_kind_bound, + concrete_syntax_token_kind_fixed, + grammar_relation_field_emitted, + grammar_relation_field_production, + grammar_relation_field_tokens, + serialize_source_field_source_grammar, + serialize_source_field_source_text, + target_model_edge_declared_inhabitants, + target_model_edge_selection_policy, + target_model_edge_translation_rules, + target_model_edge_serialize_source +} +import v4.std.logic { Bool, bool_boolean_algebra } +import v4.std.algebra { + BooleanAlgebra, + approximate_field_node, + boolean_algebra_node, + ordered_ring_node +} +import v4.std.text { String } + +// ๐ŸŸข coproduct dissolution โ€” CP-3229-GREEN-TERMINAL. ES2022 ยง4.4: Undefined and Null types each have +// a sole inhabitant (`undefined`, `null`); they are primitive value types in ยง6.1. +type EcmascriptSingletonKind + = UndefinedT | NullT + +// ๐ŸŸข coproduct dissolution โ€” CP-3229-GREEN-TERMINAL. ECMA-262 ยง6.1 primitive value types, +// in spec order: Undefined, Null, Boolean, String, Symbol, Number, BigInt. All seven are +// declared variants of the closed coproduct (Undefined/Null collapse into Singleton). Symbol +// (ยง6.1.5) carries a wave-1 fact-bundle alongside the others; wave-2b deepening (algebra +// inhabitance / unique-identity laws) is deferred, parallel to `python.dag` deferring Complex +// laws while still declaring `ComplexScalar` in `PythonScalar`. +type EcmascriptScalar + = NumberScalar | BigIntScalar | BooleanScalar | StringScalar | SymbolScalar | Singleton { kind: EcmascriptSingletonKind } + +// ๐ŸŸข grounded. +type EcmascriptCost { + operation_cost: Int + allocation_cost: Int +} + +// ๐ŸŸข coproduct dissolution ยท CP-3229-GREEN-TERMINAL. +type EcmascriptConcreteSyntaxToken + = EcmascriptFixedToken { token_class: Symbol } + | EcmascriptBoundToken { token_class: Symbol, binding: Symbol } + +// ๐ŸŸข grounded. +type EcmascriptGrammarRelationRow { + production: FormalProduction + emitted: Node + tokens: List +} + +// ๐ŸŸก gated โ€” feature:language-model-lex-grammar-bundle โ€” per-language lex/grammar/core +// authoring record; compiler ingest authority is `v4.compiler.target_carriers` `LanguageModel = Node` +// (TASKS.md Theme-A #9: LexRules/Grammar are projections, not parallel authorities). Peer: +// `PythonLanguageModel`, `TsLanguageModel`, `KotlinLanguageModel`. dissolve-on: wave-1 bundle +// projects to `Node` at the ingest boundary (cf. `python_mvp1_target_model_node`). +type EcmascriptLanguageModel { + lex: LexRules + grammar: ParseGrammar + language_identity: Symbol + canonical_symbols: Set + core: ModelCore +} + +// ๐ŸŸข grounded. ECMA-262 ยง6.1.6.1 Number type โ€” IEEE 754-2019 binary64. +type EcmascriptNumberPrimitiveFacts { + surface_spelling: Symbol + machine_representation: Symbol + std_projection: Symbol +} + +// ๐ŸŸข grounded. ECMA-262 ยง6.1.6.2 BigInt type โ€” arbitrary-precision signed integers. +type EcmascriptBigIntPrimitiveFacts { + surface_spelling: Symbol + encoding: Symbol + std_projection: Symbol +} + +// ๐ŸŸข grounded. ECMA-262 ยง6.1.3 Boolean type โ€” two inhabitants `true`, `false`. +type EcmascriptBooleanPrimitiveFacts { + surface_spelling: Symbol + encoding: Symbol + std_projection: Symbol +} + +// ๐ŸŸข grounded. ECMA-262 ยง6.1.4 String type โ€” finite ordered sequence of 16-bit unsigned +// integer code units (UTF-16, no enforced well-formedness). +type EcmascriptStringPrimitiveFacts { + surface_spelling: Symbol + encoding: Symbol + std_projection: Symbol +} + +// ๐ŸŸข grounded. ECMA-262 ยง6.1.5 Symbol type โ€” unique, immutable, non-String property keys. +// Wave-1 fact-bundle only; wave-2b algebra inhabitance (unique-identity equivalence laws) +// is deferred, parallel to `python.dag` Complex deferring algebra laws while still landing +// a primitive-fact bundle. +type EcmascriptSymbolPrimitiveFacts { + surface_spelling: Symbol + encoding: Symbol + std_projection: Symbol +} + +// ๐ŸŸข grounded. +type EcmascriptSingletonPrimitiveFacts { + surface_spelling: Symbol + kind: EcmascriptSingletonKind + std_projection: Symbol +} + +data ecmascript_language_model_surface_id: Symbol = ecmascript_language_model_surface_id + +data ecmascript_surface_spelling_number: Symbol = ecmascript_surface_spelling_number +data ecmascript_surface_spelling_bigint: Symbol = ecmascript_surface_spelling_bigint +data ecmascript_surface_spelling_boolean: Symbol = ecmascript_surface_spelling_boolean +data ecmascript_surface_spelling_string: Symbol = ecmascript_surface_spelling_string +data ecmascript_surface_spelling_symbol: Symbol = ecmascript_surface_spelling_symbol +data ecmascript_surface_spelling_undefined: Symbol = ecmascript_surface_spelling_undefined +data ecmascript_surface_spelling_null: Symbol = ecmascript_surface_spelling_null + +data ecmascript_std_projection_number: Symbol = ecmascript_std_projection_number +data ecmascript_std_projection_bigint: Symbol = ecmascript_std_projection_bigint +data ecmascript_std_projection_boolean: Symbol = ecmascript_std_projection_boolean +data ecmascript_std_projection_string: Symbol = ecmascript_std_projection_string +data ecmascript_std_projection_symbol: Symbol = ecmascript_std_projection_symbol +data ecmascript_std_projection_undefined: Symbol = ecmascript_std_projection_undefined +data ecmascript_std_projection_null: Symbol = ecmascript_std_projection_null + +data ecmascript_repr_number_ieee754_binary64: Symbol = ecmascript_repr_number_ieee754_binary64 +data ecmascript_repr_bigint_arbitrary_precision: Symbol = ecmascript_repr_bigint_arbitrary_precision +data ecmascript_repr_boolean_ecma_boolean: Symbol = ecmascript_repr_boolean_ecma_boolean +data ecmascript_repr_string_utf16_code_unit_sequence: Symbol = ecmascript_repr_string_utf16_code_unit_sequence +data ecmascript_repr_symbol_unique_identity: Symbol = ecmascript_repr_symbol_unique_identity +data ecmascript_repr_singleton_sole_inhabitant: Symbol = ecmascript_repr_singleton_sole_inhabitant + +data ecmascript_facts_field_surface_spelling: Symbol = ecmascript_facts_field_surface_spelling +data ecmascript_facts_field_encoding: Symbol = ecmascript_facts_field_encoding +data ecmascript_facts_field_machine_representation: Symbol = ecmascript_facts_field_machine_representation +data ecmascript_facts_field_std_projection: Symbol = ecmascript_facts_field_std_projection +data ecmascript_facts_field_singleton_kind: Symbol = ecmascript_facts_field_singleton_kind + +data ecmascript_inhabitant_number: Symbol = ecmascript_inhabitant_number +data ecmascript_inhabitant_bigint: Symbol = ecmascript_inhabitant_bigint +data ecmascript_inhabitant_field_atom: Symbol = ecmascript_inhabitant_field_atom +data ecmascript_inhabitant_field_facts: Symbol = ecmascript_inhabitant_field_facts +data ecmascript_inhabitant_field_number: Symbol = ecmascript_inhabitant_field_number +data ecmascript_inhabitant_field_bigint: Symbol = ecmascript_inhabitant_field_bigint + +data ecmascript_witness_number_approximate_field: Symbol = ecmascript_witness_number_approximate_field +data ecmascript_witness_bigint_ordered_ring: Symbol = ecmascript_witness_bigint_ordered_ring +data ecmascript_witness_bool_boolean_algebra: Symbol = ecmascript_witness_bool_boolean_algebra + +data ecmascript_tag_singleton_undefined: Symbol = ecmascript_tag_singleton_undefined +data ecmascript_tag_singleton_null: Symbol = ecmascript_tag_singleton_null + +data ecmascript_token_kw_function: Symbol = ecmascript_token_kw_function +data ecmascript_token_kw_return: Symbol = ecmascript_token_kw_return +data ecmascript_token_kw_if: Symbol = ecmascript_token_kw_if +data ecmascript_token_kw_let: Symbol = ecmascript_token_kw_let +data ecmascript_token_ident: Symbol = ecmascript_token_ident +data ecmascript_token_int_literal: Symbol = ecmascript_token_int_literal +data ecmascript_token_lparen: Symbol = ecmascript_token_lparen +data ecmascript_token_rparen: Symbol = ecmascript_token_rparen +data ecmascript_token_lbrace: Symbol = ecmascript_token_lbrace +data ecmascript_token_rbrace: Symbol = ecmascript_token_rbrace +data ecmascript_token_comma: Symbol = ecmascript_token_comma +data ecmascript_token_equal: Symbol = ecmascript_token_equal +data ecmascript_token_plus: Symbol = ecmascript_token_plus +data ecmascript_token_greater: Symbol = ecmascript_token_greater +data ecmascript_token_semicolon: Symbol = ecmascript_token_semicolon +// Layout-baked composite tokens (๐ŸŸก feature:T-6-token-layout-trivia-policy โ€” see lex header). +data ecmascript_token_rparen_lbrace_open: Symbol = ecmascript_token_rparen_lbrace_open +data ecmascript_token_semicolon_rbrace_close: Symbol = ecmascript_token_semicolon_rbrace_close +data ecmascript_token_if_open: Symbol = ecmascript_token_if_open +data ecmascript_token_rparen_lbrace_inner_open: Symbol = ecmascript_token_rparen_lbrace_inner_open +data ecmascript_token_semicolon_rbrace_inner_close: Symbol = ecmascript_token_semicolon_rbrace_inner_close +data ecmascript_token_let_assign_semicolon: Symbol = ecmascript_token_let_assign_semicolon +data ecmascript_token_return_inner: Symbol = ecmascript_token_return_inner +data ecmascript_token_return_outer: Symbol = ecmascript_token_return_outer + +data ecmascript_production_mvp1_fn_add: Symbol = ecmascript_production_mvp1_fn_add +data ecmascript_production_fn_decl: Symbol = ecmascript_production_fn_decl +data ecmascript_production_block: Symbol = ecmascript_production_block +data ecmascript_production_stmt: Symbol = ecmascript_production_stmt +data ecmascript_production_assign_stmt: Symbol = ecmascript_production_assign_stmt +data ecmascript_production_if_stmt: Symbol = ecmascript_production_if_stmt +data ecmascript_production_return_stmt: Symbol = ecmascript_production_return_stmt +data ecmascript_production_comparison: Symbol = ecmascript_production_comparison +data ecmascript_production_additive: Symbol = ecmascript_production_additive +data ecmascript_production_primary: Symbol = ecmascript_production_primary +data ecmascript_production_additive_tail: Symbol = ecmascript_production_additive_tail +data ecmascript_production_comparison_tail: Symbol = ecmascript_production_comparison_tail + +// ๐ŸŸก gated โ€” feature:ecmascript-formal-epsilon-shim-terminal โ€” bind TASKS.md T-7 / CP-1b โ€” +// dissolve-on: std/grammar canonical epsilon carrier; empty FormalProduction.rhs lowers +// without fabricated parse-only token_class. +data ecmascript_formal_epsilon_shim_terminal: Symbol = ecmascript_formal_epsilon_shim_terminal + +data ecmascript_surface_fn_item: Symbol = ecmascript_surface_fn_item +data ecmascript_surface_block: Symbol = ecmascript_surface_block +data ecmascript_surface_stmt: Symbol = ecmascript_surface_stmt +data ecmascript_surface_assign_stmt: Symbol = ecmascript_surface_assign_stmt +data ecmascript_surface_if_stmt: Symbol = ecmascript_surface_if_stmt +data ecmascript_surface_return_stmt: Symbol = ecmascript_surface_return_stmt +data ecmascript_surface_comparison: Symbol = ecmascript_surface_comparison +data ecmascript_surface_additive: Symbol = ecmascript_surface_additive +data ecmascript_surface_primary: Symbol = ecmascript_surface_primary +data ecmascript_surface_additive_tail: Symbol = ecmascript_surface_additive_tail +data ecmascript_surface_comparison_tail: Symbol = ecmascript_surface_comparison_tail + +data ecmascript_mvp1_parse_fixture_file: Symbol = ecmascript_mvp1_parse_fixture_file +data ecmascript_binding_fn_add: Symbol = ecmascript_binding_fn_add +data ecmascript_binding_param_x: Symbol = ecmascript_binding_param_x +data ecmascript_binding_param_y: Symbol = ecmascript_binding_param_y +data ecmascript_relation_rule_mvp1_fn_add: Symbol = ecmascript_relation_rule_mvp1_fn_add +data ecmascript_mvp1_source_literal: Symbol = ecmascript_mvp1_source_literal +data ecmascript_mvp1_source_text_field: Symbol = serialize_source_field_source_text +data ecmascript_mvp1_source_grammar_field: Symbol = serialize_source_field_source_grammar +data ecmascript_mvp1_source_text: String = "function add(x, y) { return x + y; }" + +fn ecmascript_mvp1_concrete_tokens() -> List { + [ + EcmascriptFixedToken { token_class: ecmascript_token_kw_function }, + EcmascriptBoundToken { token_class: ecmascript_token_ident, binding: ecmascript_binding_fn_add }, + EcmascriptFixedToken { token_class: ecmascript_token_lparen }, + EcmascriptBoundToken { token_class: ecmascript_token_ident, binding: ecmascript_binding_param_x }, + EcmascriptFixedToken { token_class: ecmascript_token_comma }, + EcmascriptBoundToken { token_class: ecmascript_token_ident, binding: ecmascript_binding_param_y }, + EcmascriptFixedToken { token_class: ecmascript_token_rparen_lbrace_open }, + EcmascriptFixedToken { token_class: ecmascript_token_kw_return }, + EcmascriptBoundToken { token_class: ecmascript_token_ident, binding: ecmascript_binding_param_x }, + EcmascriptFixedToken { token_class: ecmascript_token_plus }, + EcmascriptBoundToken { token_class: ecmascript_token_ident, binding: ecmascript_binding_param_y }, + EcmascriptFixedToken { token_class: ecmascript_token_semicolon_rbrace_close } + ] +} + +data ecmascript_facts_number: EcmascriptNumberPrimitiveFacts = EcmascriptNumberPrimitiveFacts { + surface_spelling: ecmascript_surface_spelling_number, + machine_representation: ecmascript_repr_number_ieee754_binary64, + std_projection: ecmascript_std_projection_number +} + +data ecmascript_facts_bigint: EcmascriptBigIntPrimitiveFacts = EcmascriptBigIntPrimitiveFacts { + surface_spelling: ecmascript_surface_spelling_bigint, + encoding: ecmascript_repr_bigint_arbitrary_precision, + std_projection: ecmascript_std_projection_bigint +} + +data ecmascript_facts_boolean: EcmascriptBooleanPrimitiveFacts = EcmascriptBooleanPrimitiveFacts { + surface_spelling: ecmascript_surface_spelling_boolean, + encoding: ecmascript_repr_boolean_ecma_boolean, + std_projection: ecmascript_std_projection_boolean +} + +data ecmascript_facts_string: EcmascriptStringPrimitiveFacts = EcmascriptStringPrimitiveFacts { + surface_spelling: ecmascript_surface_spelling_string, + encoding: ecmascript_repr_string_utf16_code_unit_sequence, + std_projection: ecmascript_std_projection_string +} + +data ecmascript_facts_symbol: EcmascriptSymbolPrimitiveFacts = EcmascriptSymbolPrimitiveFacts { + surface_spelling: ecmascript_surface_spelling_symbol, + encoding: ecmascript_repr_symbol_unique_identity, + std_projection: ecmascript_std_projection_symbol +} + +data ecmascript_facts_undefined: EcmascriptSingletonPrimitiveFacts = EcmascriptSingletonPrimitiveFacts { + surface_spelling: ecmascript_surface_spelling_undefined, + kind: UndefinedT, + std_projection: ecmascript_std_projection_undefined +} + +data ecmascript_facts_null: EcmascriptSingletonPrimitiveFacts = EcmascriptSingletonPrimitiveFacts { + surface_spelling: ecmascript_surface_spelling_null, + kind: NullT, + std_projection: ecmascript_std_projection_null +} + +data ecmascript_number_facts_catalog: List = [ + ecmascript_facts_number +] + +data ecmascript_bigint_facts_catalog: List = [ + ecmascript_facts_bigint +] + +data ecmascript_boolean_facts_catalog: List = [ + ecmascript_facts_boolean +] + +data ecmascript_string_facts_catalog: List = [ + ecmascript_facts_string +] + +data ecmascript_symbol_facts_catalog: List = [ + ecmascript_facts_symbol +] + +data ecmascript_singleton_facts_catalog: List = [ + ecmascript_facts_undefined, + ecmascript_facts_null +] + +// ๐ŸŸก canonical-B decl-ref ยท E-6(b) bounded-exception ยท scaffold feature:canonical-b-grounding-consumer ยท dissolve-on: B1-CANON+zip-fold consume (ledger: B1ยทT-9/C1 ยท grounding-worked-examples.md ยง0) +data ecmascript_bool_grounding: BooleanAlgebra = bool_boolean_algebra + +fn ecmascript_inhabitant_atom(id: Symbol) -> Node { + Node { + kind: TypeNode { connective: Atom { identity: id } }, + children: [] + } +} + +fn ecmascript_named_edge(name: Symbol, target: Node) -> Edge { + Edge { label: Named { name: name }, target: target } +} + +fn ecmascript_singleton_kind_tag(kind: EcmascriptSingletonKind) -> Symbol { + match kind { + UndefinedT => ecmascript_tag_singleton_undefined + NullT => ecmascript_tag_singleton_null + } +} + +fn ecmascript_number_facts_node(facts: EcmascriptNumberPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge( + name: ecmascript_facts_field_surface_spelling, + target: ecmascript_inhabitant_atom(id: facts.surface_spelling) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_machine_representation, + target: ecmascript_inhabitant_atom(id: facts.machine_representation) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_std_projection, + target: ecmascript_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn ecmascript_bigint_facts_node(facts: EcmascriptBigIntPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge( + name: ecmascript_facts_field_surface_spelling, + target: ecmascript_inhabitant_atom(id: facts.surface_spelling) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_encoding, + target: ecmascript_inhabitant_atom(id: facts.encoding) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_std_projection, + target: ecmascript_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn ecmascript_boolean_facts_node(facts: EcmascriptBooleanPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge( + name: ecmascript_facts_field_surface_spelling, + target: ecmascript_inhabitant_atom(id: facts.surface_spelling) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_encoding, + target: ecmascript_inhabitant_atom(id: facts.encoding) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_std_projection, + target: ecmascript_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn ecmascript_symbol_facts_node(facts: EcmascriptSymbolPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge( + name: ecmascript_facts_field_surface_spelling, + target: ecmascript_inhabitant_atom(id: facts.surface_spelling) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_encoding, + target: ecmascript_inhabitant_atom(id: facts.encoding) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_std_projection, + target: ecmascript_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn ecmascript_string_facts_node(facts: EcmascriptStringPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge( + name: ecmascript_facts_field_surface_spelling, + target: ecmascript_inhabitant_atom(id: facts.surface_spelling) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_encoding, + target: ecmascript_inhabitant_atom(id: facts.encoding) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_std_projection, + target: ecmascript_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn ecmascript_singleton_facts_node(facts: EcmascriptSingletonPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge( + name: ecmascript_facts_field_surface_spelling, + target: ecmascript_inhabitant_atom(id: facts.surface_spelling) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_singleton_kind, + target: ecmascript_inhabitant_atom(id: ecmascript_singleton_kind_tag(kind: facts.kind)) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_std_projection, + target: ecmascript_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn ecmascript_number_spec_facts(facts: EcmascriptNumberPrimitiveFacts) -> Map { + Map { + lookup: fn(axis) { + match axis { + primitive_fact_axis_surface_spelling => + Holds { value: ecmascript_inhabitant_atom(id: facts.surface_spelling) } + primitive_fact_axis_encoding => + Holds { value: ecmascript_inhabitant_atom(id: facts.machine_representation) } + _ => + Violates { + diagnostic: primitive_fact_axis_unbound_diagnostic(axis: axis) + } + } + } + } +} + +fn ecmascript_bigint_spec_facts(facts: EcmascriptBigIntPrimitiveFacts) -> Map { + Map { + lookup: fn(axis) { + match axis { + primitive_fact_axis_surface_spelling => + Holds { value: ecmascript_inhabitant_atom(id: facts.surface_spelling) } + primitive_fact_axis_encoding => + Holds { value: ecmascript_inhabitant_atom(id: facts.encoding) } + _ => + Violates { + diagnostic: primitive_fact_axis_unbound_diagnostic(axis: axis) + } + } + } + } +} + +fn ecmascript_boolean_spec_facts(facts: EcmascriptBooleanPrimitiveFacts) -> Map { + Map { + lookup: fn(axis) { + match axis { + primitive_fact_axis_surface_spelling => + Holds { value: ecmascript_inhabitant_atom(id: facts.surface_spelling) } + primitive_fact_axis_encoding => + Holds { value: ecmascript_inhabitant_atom(id: facts.encoding) } + _ => + Violates { + diagnostic: primitive_fact_axis_unbound_diagnostic(axis: axis) + } + } + } + } +} + +fn ecmascript_symbol_spec_facts(facts: EcmascriptSymbolPrimitiveFacts) -> Map { + Map { + lookup: fn(axis) { + match axis { + primitive_fact_axis_surface_spelling => + Holds { value: ecmascript_inhabitant_atom(id: facts.surface_spelling) } + primitive_fact_axis_encoding => + Holds { value: ecmascript_inhabitant_atom(id: facts.encoding) } + _ => + Violates { + diagnostic: primitive_fact_axis_unbound_diagnostic(axis: axis) + } + } + } + } +} + +fn ecmascript_string_spec_facts(facts: EcmascriptStringPrimitiveFacts) -> Map { + Map { + lookup: fn(axis) { + match axis { + primitive_fact_axis_surface_spelling => + Holds { value: ecmascript_inhabitant_atom(id: facts.surface_spelling) } + primitive_fact_axis_encoding => + Holds { value: ecmascript_inhabitant_atom(id: facts.encoding) } + _ => + Violates { + diagnostic: primitive_fact_axis_unbound_diagnostic(axis: axis) + } + } + } + } +} + +fn ecmascript_singleton_spec_facts(facts: EcmascriptSingletonPrimitiveFacts) -> Map { + Map { + lookup: fn(axis) { + match axis { + primitive_fact_axis_surface_spelling => + Holds { value: ecmascript_inhabitant_atom(id: facts.surface_spelling) } + primitive_fact_axis_encoding => + Holds { value: ecmascript_inhabitant_atom(id: ecmascript_repr_singleton_sole_inhabitant) } + _ => + Violates { + diagnostic: primitive_fact_axis_unbound_diagnostic(axis: axis) + } + } + } + } +} + +fn ecmascript_primitive_bundle_from_number_facts( + facts: EcmascriptNumberPrimitiveFacts +) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: ecmascript_number_facts_node(facts: facts), + spec_facts: ecmascript_number_spec_facts(facts: facts) + } +} + +fn ecmascript_primitive_bundle_from_bigint_facts( + facts: EcmascriptBigIntPrimitiveFacts +) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: ecmascript_bigint_facts_node(facts: facts), + spec_facts: ecmascript_bigint_spec_facts(facts: facts) + } +} + +fn ecmascript_primitive_bundle_from_boolean_facts( + facts: EcmascriptBooleanPrimitiveFacts +) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: ecmascript_boolean_facts_node(facts: facts), + spec_facts: ecmascript_boolean_spec_facts(facts: facts) + } +} + +fn ecmascript_primitive_bundle_from_symbol_facts( + facts: EcmascriptSymbolPrimitiveFacts +) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: ecmascript_symbol_facts_node(facts: facts), + spec_facts: ecmascript_symbol_spec_facts(facts: facts) + } +} + +fn ecmascript_primitive_bundle_from_string_facts( + facts: EcmascriptStringPrimitiveFacts +) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: ecmascript_string_facts_node(facts: facts), + spec_facts: ecmascript_string_spec_facts(facts: facts) + } +} + +fn ecmascript_primitive_bundle_from_singleton_facts( + facts: EcmascriptSingletonPrimitiveFacts +) -> PrimitiveFactBundle { + PrimitiveFactBundle { + substrate_carrier: ecmascript_singleton_facts_node(facts: facts), + spec_facts: ecmascript_singleton_spec_facts(facts: facts) + } +} + +fn ecmascript_primitive_bundles_from_number_catalog() -> List { + fold_list( + xs: ecmascript_number_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: ecmascript_primitive_bundle_from_number_facts(facts: facts) + ) + } + ) +} + +fn ecmascript_primitive_bundles_from_bigint_catalog() -> List { + fold_list( + xs: ecmascript_bigint_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: ecmascript_primitive_bundle_from_bigint_facts(facts: facts) + ) + } + ) +} + +fn ecmascript_primitive_bundles_from_boolean_catalog() -> List { + fold_list( + xs: ecmascript_boolean_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: ecmascript_primitive_bundle_from_boolean_facts(facts: facts) + ) + } + ) +} + +fn ecmascript_primitive_bundles_from_symbol_catalog() -> List { + fold_list( + xs: ecmascript_symbol_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: ecmascript_primitive_bundle_from_symbol_facts(facts: facts) + ) + } + ) +} + +fn ecmascript_primitive_bundles_from_string_catalog() -> List { + fold_list( + xs: ecmascript_string_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: ecmascript_primitive_bundle_from_string_facts(facts: facts) + ) + } + ) +} + +fn ecmascript_primitive_bundles_from_singleton_catalog() -> List { + fold_list( + xs: ecmascript_singleton_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item( + xs: acc, + item: ecmascript_primitive_bundle_from_singleton_facts(facts: facts) + ) + } + ) +} + +fn ecmascript_wave1_primitive_fact_bundles() -> List { + list_append( + left: list_append( + left: list_append( + left: list_append( + left: list_append( + left: ecmascript_primitive_bundles_from_number_catalog(), + right: ecmascript_primitive_bundles_from_bigint_catalog() + ), + right: ecmascript_primitive_bundles_from_boolean_catalog() + ), + right: ecmascript_primitive_bundles_from_string_catalog() + ), + right: ecmascript_primitive_bundles_from_symbol_catalog() + ), + right: ecmascript_primitive_bundles_from_singleton_catalog() + ) +} + +fn ecmascript_number_algebra_witness_node(facts: EcmascriptNumberPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge( + name: ecmascript_witness_number_approximate_field, + target: ecmascript_inhabitant_atom(id: ecmascript_witness_number_approximate_field) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_machine_representation, + target: ecmascript_inhabitant_atom(id: facts.machine_representation) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_std_projection, + target: ecmascript_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn ecmascript_bigint_algebra_witness_node(facts: EcmascriptBigIntPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge( + name: ecmascript_witness_bigint_ordered_ring, + target: ecmascript_inhabitant_atom(id: ecmascript_witness_bigint_ordered_ring) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_encoding, + target: ecmascript_inhabitant_atom(id: facts.encoding) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_std_projection, + target: ecmascript_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn ecmascript_boolean_algebra_witness_node(facts: EcmascriptBooleanPrimitiveFacts) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge( + name: ecmascript_witness_bool_boolean_algebra, + target: ecmascript_inhabitant_atom(id: ecmascript_witness_bool_boolean_algebra) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_encoding, + target: ecmascript_inhabitant_atom(id: facts.encoding) + ), + ecmascript_named_edge( + name: ecmascript_facts_field_std_projection, + target: ecmascript_inhabitant_atom(id: facts.std_projection) + ) + ] + } +} + +fn ecmascript_number_algebra_inhabitance(facts: EcmascriptNumberPrimitiveFacts) -> AlgebraInhabitanceDecl { + let inhabitant = ecmascript_number_facts_node(facts: facts) + AlgebraInhabitanceDecl { + algebra: approximate_field_node(inhabitant: inhabitant), + inhabitant: inhabitant, + witness: ecmascript_number_algebra_witness_node(facts: facts) + } +} + +fn ecmascript_bigint_algebra_inhabitance(facts: EcmascriptBigIntPrimitiveFacts) -> AlgebraInhabitanceDecl { + let inhabitant = ecmascript_bigint_facts_node(facts: facts) + AlgebraInhabitanceDecl { + algebra: ordered_ring_node(inhabitant: inhabitant), + inhabitant: inhabitant, + witness: ecmascript_bigint_algebra_witness_node(facts: facts) + } +} + +fn ecmascript_boolean_algebra_inhabitance(facts: EcmascriptBooleanPrimitiveFacts) -> AlgebraInhabitanceDecl { + let inhabitant = ecmascript_boolean_facts_node(facts: facts) + AlgebraInhabitanceDecl { + algebra: boolean_algebra_node(inhabitant: inhabitant), + inhabitant: inhabitant, + witness: ecmascript_boolean_algebra_witness_node(facts: facts) + } +} + +fn ecmascript_number_algebra_inhabitance_decls() -> List { + fold_list( + xs: ecmascript_number_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item(xs: acc, item: ecmascript_number_algebra_inhabitance(facts: facts)) + } + ) +} + +fn ecmascript_bigint_algebra_inhabitance_decls() -> List { + fold_list( + xs: ecmascript_bigint_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item(xs: acc, item: ecmascript_bigint_algebra_inhabitance(facts: facts)) + } + ) +} + +fn ecmascript_boolean_algebra_inhabitance_decls() -> List { + fold_list( + xs: ecmascript_boolean_facts_catalog, + empty: Empty, + cons: fn(acc, facts) { + list_snoc_item(xs: acc, item: ecmascript_boolean_algebra_inhabitance(facts: facts)) + } + ) +} + +fn ecmascript_model_core_inhabitance_decls() -> List { + list_append( + left: list_append( + left: ecmascript_number_algebra_inhabitance_decls(), + right: ecmascript_bigint_algebra_inhabitance_decls() + ), + right: ecmascript_boolean_algebra_inhabitance_decls() + ) +} + +fn ecmascript_model_core_wave1() -> ModelCore { + ModelCore { + primitives: ecmascript_wave1_primitive_fact_bundles(), + inhabitance: ecmascript_model_core_inhabitance_decls(), + laws: [], + effects: EffectSemanticsDecl { operations: [] }, + partiality: PartialitySemanticsDecl { operations: [] } + } +} + +fn ecmascript_inhabitant_node(id: Symbol, facts: Node) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge(name: ecmascript_inhabitant_field_atom, target: ecmascript_inhabitant_atom(id: id)), + ecmascript_named_edge(name: ecmascript_inhabitant_field_facts, target: facts) + ] + } +} + +fn ecmascript_number_inhabitant_node() -> Node { + ecmascript_inhabitant_node( + id: ecmascript_inhabitant_number, + facts: ecmascript_number_facts_node(facts: ecmascript_facts_number) + ) +} + +fn ecmascript_bigint_inhabitant_node() -> Node { + ecmascript_inhabitant_node( + id: ecmascript_inhabitant_bigint, + facts: ecmascript_bigint_facts_node(facts: ecmascript_facts_bigint) + ) +} + +fn ecmascript_declared_inhabitants_root() -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge(name: ecmascript_inhabitant_field_number, target: ecmascript_number_inhabitant_node()), + ecmascript_named_edge(name: ecmascript_inhabitant_field_bigint, target: ecmascript_bigint_inhabitant_node()) + ] + } +} + +fn ecmascript_mvp1_selection_policy_node() -> Node { + ecmascript_number_inhabitant_node() +} + +fn ecmascript_mvp1_emitted_add_fn_node() -> Node { + Node { + kind: TypeNode { connective: Arrow }, + children: [ + Edge { label: Positional, target: ecmascript_number_inhabitant_node() }, + Edge { label: Positional, target: ecmascript_number_inhabitant_node() }, + Edge { label: Positional, target: ecmascript_number_inhabitant_node() } + ] + } +} + +fn ecmascript_concrete_token_class(token: EcmascriptConcreteSyntaxToken) -> Symbol { + match token { + EcmascriptFixedToken { token_class: c } => c + EcmascriptBoundToken { token_class: c, binding: _ } => c + } +} + +fn ecmascript_concrete_token_node(token: EcmascriptConcreteSyntaxToken) -> Node { + match token { + EcmascriptFixedToken { token_class: c } => + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge(name: concrete_syntax_token_field_kind, target: ecmascript_inhabitant_atom(id: concrete_syntax_token_kind_fixed)), + ecmascript_named_edge(name: concrete_syntax_token_field_class, target: ecmascript_inhabitant_atom(id: c)) + ] + } + EcmascriptBoundToken { token_class: c, binding: b } => + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge(name: concrete_syntax_token_field_kind, target: ecmascript_inhabitant_atom(id: concrete_syntax_token_kind_bound)), + ecmascript_named_edge(name: concrete_syntax_token_field_class, target: ecmascript_inhabitant_atom(id: c)), + ecmascript_named_edge(name: concrete_syntax_token_field_binding, target: ecmascript_inhabitant_atom(id: b)) + ] + } + } +} + +fn ecmascript_positional_token_edge(token: EcmascriptConcreteSyntaxToken) -> Edge { + Edge { label: Positional, target: ecmascript_concrete_token_node(token: token) } +} + +fn ecmascript_positional_edges_from_token_classes() -> List { + fold_list( + xs: ecmascript_mvp1_concrete_tokens(), + empty: Empty, + cons: fn(acc, token) { + list_snoc_item(xs: acc, item: ecmascript_positional_token_edge(token: token)) + } + ) +} + +fn ecmascript_mvp1_serialize_source_children() -> List { + list_append( + left: [ + ecmascript_named_edge(name: ecmascript_mvp1_source_text_field, target: ecmascript_inhabitant_atom(id: ecmascript_mvp1_source_literal)), + ecmascript_named_edge(name: ecmascript_mvp1_source_grammar_field, target: ecmascript_inhabitant_atom(id: ecmascript_production_mvp1_fn_add)) + ], + right: ecmascript_positional_edges_from_token_classes() + ) +} + +fn ecmascript_mvp1_serialize_source_node() -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: ecmascript_mvp1_serialize_source_children() + } +} + +// --- FormalProduction authority (flat rhs) + GrammarExpr operational shim (parse.dag) --- + +fn ecmascript_formal_rhs_from_token_classes() -> List { + fold_list( + xs: ecmascript_mvp1_concrete_tokens(), + empty: Empty, + cons: fn(acc, token) { + list_snoc_item( + xs: acc, + item: grammar_formal_terminal(identity: ecmascript_concrete_token_class(token: token)) + ) + } + ) +} + +// ๐ŸŸก gated โ€” feature:ecmascript-formal-symbol-to-grammar-expr-shim โ€” bind TASKS.md T-7 / CP-1b โ€” +// interim FormalGrammarSymbol โ†’ GrammarExpr projection for operational parse lowering only; +// dissolve-on: std/grammar substrate projects FormalGrammarSymbol to GrammarExpr directly. +fn ecmascript_formal_symbol_to_grammar_expr(sym: FormalGrammarSymbol) -> GrammarExpr { + match sym { + FormalTerminalOccurrence { terminal: terminal } => + Terminal { token_class: terminal.identity } + FormalNonterminalOccurrence { nonterminal: nonterminal } => + Nonterminal { production: nonterminal.identity } + } +} + +// ๐ŸŸก gated โ€” feature:ecmascript-formal-epsilon-grammar-expr-shim โ€” bind TASKS.md T-7 / CP-1b โ€” +// dissolve-on: std/grammar epsilon projection replaces Optional+sentinel terminal shim. +fn ecmascript_formal_epsilon_grammar_expr() -> GrammarExpr { + Optional { + element: Terminal { token_class: ecmascript_formal_epsilon_shim_terminal } + } +} + +// ๐ŸŸก gated โ€” feature:ecmascript-formal-rhs-to-expr-shim-fold โ€” bind TASKS.md T-7 / CP-1b โ€” +// interim fold carrier for FormalProduction.rhs โ†’ GrammarExpr Sequence lowering only; +// dissolve-on: std/grammar substrate fold_non_empty_right (or equivalent) replaces this coproduct. +type EcmascriptFormalRhsToExprState + = EcmascriptFormalRhsToExprUninitialized + | EcmascriptFormalRhsToExprReady { expr: GrammarExpr } + +fn ecmascript_formal_rhs_to_grammar_expr(rhs: List) -> GrammarExpr { + match fold_list( + xs: rhs, + empty: EcmascriptFormalRhsToExprUninitialized, + cons: fn(state, sym) { + let piece = ecmascript_formal_symbol_to_grammar_expr(sym: sym) + match state { + EcmascriptFormalRhsToExprUninitialized => + EcmascriptFormalRhsToExprReady { expr: piece } + EcmascriptFormalRhsToExprReady { expr: acc } => + EcmascriptFormalRhsToExprReady { + expr: Sequence { left: acc, right: piece } + } + } + } + ) { + EcmascriptFormalRhsToExprUninitialized => ecmascript_formal_epsilon_grammar_expr() + EcmascriptFormalRhsToExprReady { expr: result } => result + } +} + +// ๐ŸŸก gated โ€” feature:ecmascript-formal-alt-choice-shim-fold โ€” bind TASKS.md T-7 / CP-1b โ€” +// interim fold carrier for multi-alt FormalProduction lhs โ†’ GrammarExpr Choice lowering only; +// dissolve-on: std/grammar substrate fold_non_empty_right (or equivalent) replaces this coproduct. +type EcmascriptFormalAltChoiceState + = EcmascriptFormalAltChoiceUninitialized + | EcmascriptFormalAltChoiceReady { expr: GrammarExpr } + +fn ecmascript_formal_alternatives_to_choice_expr(alts: List>) -> GrammarExpr { + match fold_list( + xs: alts, + empty: EcmascriptFormalAltChoiceUninitialized, + cons: fn(state, rhs) { + let alt_expr = ecmascript_formal_rhs_to_grammar_expr(rhs: rhs) + match state { + EcmascriptFormalAltChoiceUninitialized => + EcmascriptFormalAltChoiceReady { expr: alt_expr } + EcmascriptFormalAltChoiceReady { expr: acc } => + EcmascriptFormalAltChoiceReady { + expr: Choice { left: acc, right: alt_expr } + } + } + } + ) { + EcmascriptFormalAltChoiceUninitialized => ecmascript_formal_epsilon_grammar_expr() + EcmascriptFormalAltChoiceReady { expr: result } => result + } +} + +fn ecmascript_formal_rhs_alternatives_accum_empty() -> List> { + Empty +} + +fn ecmascript_formal_collect_rhs_alternative( + acc: List>, + prod: FormalProduction +) -> List> { + list_snoc_item(xs: acc, item: prod.rhs) +} + +fn ecmascript_formal_rhs_alternatives_from_productions( + prods: List +) -> List> { + fold_list( + xs: prods, + empty: ecmascript_formal_rhs_alternatives_accum_empty(), + cons: ecmascript_formal_collect_rhs_alternative + ) +} + +fn ecmascript_formal_productions_to_grammar_expr(prods: List) -> GrammarExpr { + ecmascript_formal_alternatives_to_choice_expr( + alts: ecmascript_formal_rhs_alternatives_from_productions(prods: prods) + ) +} + +fn ecmascript_formal_production_alts( + head: FormalProduction, + alts: List +) -> List { + list_append(left: [head], right: alts) +} + +fn ecmascript_formal_productions_to_grammar_production( + head: FormalProduction, + alts: List, + emitted: Symbol +) -> GrammarProduction { + GrammarProduction { + name: head.lhs.identity, + expression: ecmascript_formal_productions_to_grammar_expr( + prods: ecmascript_formal_production_alts(head: head, alts: alts) + ), + emitted: ecmascript_grammar_atom(id: emitted) + } +} + +fn ecmascript_formal_production_mvp1_fn_add() -> FormalProduction { + grammar_formal_production( + lhs: ecmascript_production_mvp1_fn_add, + rhs: ecmascript_formal_rhs_from_token_classes() + ) +} + +fn ecmascript_wave1_formal_productions() -> List { + [ecmascript_formal_production_mvp1_fn_add()] +} + +fn ecmascript_grammar_production_mvp1_fn_add() -> GrammarProduction { + GrammarProduction { + name: ecmascript_production_mvp1_fn_add, + expression: ecmascript_formal_productions_to_grammar_expr( + prods: [ecmascript_formal_production_mvp1_fn_add()] + ), + emitted: ecmascript_mvp1_emitted_add_fn_node() + } +} + +fn ecmascript_mvp1_grammar_relation_row() -> EcmascriptGrammarRelationRow { + EcmascriptGrammarRelationRow { + production: ecmascript_formal_production_mvp1_fn_add(), + emitted: ecmascript_mvp1_emitted_add_fn_node(), + tokens: ecmascript_mvp1_concrete_tokens() + } +} + +fn ecmascript_relation_token_edges(tokens: List) -> List { + fold_list( + xs: tokens, + empty: Empty, + cons: fn(acc, token) { + list_snoc_item(xs: acc, item: ecmascript_positional_token_edge(token: token)) + } + ) +} + +fn ecmascript_grammar_relation_row_node(row: EcmascriptGrammarRelationRow) -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge(name: grammar_relation_field_production, target: formal_production_to_node(production: row.production)), + ecmascript_named_edge(name: grammar_relation_field_emitted, target: row.emitted), + ecmascript_named_edge( + name: grammar_relation_field_tokens, + target: Node { + kind: TypeNode { connective: Conj }, + children: ecmascript_relation_token_edges(tokens: row.tokens) + } + ) + ] + } +} + +fn ecmascript_mvp1_translation_rules_node() -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge( + name: ecmascript_relation_rule_mvp1_fn_add, + target: ecmascript_grammar_relation_row_node(row: ecmascript_mvp1_grammar_relation_row()) + ) + ] + } +} + +fn ecmascript_mvp1_target_model_node() -> Node { + Node { + kind: TypeNode { connective: Conj }, + children: [ + ecmascript_named_edge(name: target_model_edge_selection_policy, target: ecmascript_mvp1_selection_policy_node()), + ecmascript_named_edge(name: target_model_edge_declared_inhabitants, target: ecmascript_declared_inhabitants_root()), + ecmascript_named_edge(name: target_model_edge_translation_rules, target: ecmascript_mvp1_translation_rules_node()), + ecmascript_named_edge(name: target_model_edge_serialize_source, target: ecmascript_mvp1_serialize_source_node()) + ] + } +} + +fn ecmascript_mvp1_binding_spellings() -> Map { + map_insert( + map_insert( + map_insert(empty_map(), ecmascript_binding_fn_add, "add"), + ecmascript_binding_param_x, + "x" + ), + ecmascript_binding_param_y, + "y" + ) +} + +fn ecmascript_mvp1_target_model() -> TargetModel { + TargetModel { + bundle: ecmascript_mvp1_target_model_node(), + lex: ecmascript_wave1_lex(), + binding_spellings: ecmascript_mvp1_binding_spellings(), + authority_source_text: ecmascript_mvp1_source_text + } +} + +fn ecmascript_lex_rule(token_class: Symbol, text: String) -> LexRule { + TokenRule { token_class: token_class, pattern: LiteralPattern { text: text } } +} + +fn ecmascript_ident_lex_pattern() -> LexPattern { + SequencePattern { + left: CharClassPattern { class: IdentStartChar }, + right: RepeatPattern { element: CharClassPattern { class: IdentContinueChar } } + } +} + +fn ecmascript_ident_lex_rule() -> LexRule { + TokenRule { + token_class: ecmascript_token_ident, + pattern: ecmascript_ident_lex_pattern() + } +} + +// ๐ŸŸก predicate dissolution โ€” feature:ecmascript-wave2a-decimal-int-literal โ€” bind TASKS.md T-6/T-7 โ€” +// dissolve-on: std LexCharClass carries NonZeroDigitChar (or full ES2022 NumericLiteral LexPattern). +// ๐ŸŸก gated โ€” feature:ecmascript-wave2a-decimal-int-literal โ€” ASCII 49โ€“57 ladder until +// `NonZeroDigitChar` lands on v4.std.lexing; consumed only by ecmascript_decimal_int_literal_pattern. +fn ecmascript_nonzero_digit_char_pattern() -> LexPattern { + ChoicePattern { + left: CharPattern { char: 49 }, + right: ChoicePattern { + left: CharPattern { char: 50 }, + right: ChoicePattern { + left: CharPattern { char: 51 }, + right: ChoicePattern { + left: CharPattern { char: 52 }, + right: ChoicePattern { + left: CharPattern { char: 53 }, + right: ChoicePattern { + left: CharPattern { char: 54 }, + right: ChoicePattern { + left: CharPattern { char: 55 }, + right: ChoicePattern { + left: CharPattern { char: 56 }, + right: CharPattern { char: 57 } + } + } + } + } + } + } + } + } +} + +// ๐ŸŸก gated โ€” feature:ecmascript-wave2a-decimal-int-literal โ€” decimal subset `0` | [1-9][0-9]* only; +// wave-2a fixture uses 0/1. Does not model 0b/0o/0x bases, NumericLiteralSeparator (`_`), nor +// the `n` BigIntLiteral suffix per ES2022 ยง12.8.3. Dissolves when T-6/T-7 lands the full +// NumericLiteral LexPattern. +fn ecmascript_decimal_int_literal_pattern() -> LexPattern { + ChoicePattern { + left: LiteralPattern { text: "0" }, + right: SequencePattern { + left: ecmascript_nonzero_digit_char_pattern(), + right: RepeatPattern { element: CharClassPattern { class: DigitChar } } + } + } +} + +fn ecmascript_int_literal_lex_rule() -> LexRule { + TokenRule { + token_class: ecmascript_token_int_literal, + pattern: ecmascript_decimal_int_literal_pattern() + } +} + +// ๐ŸŸก gated โ€” feature:T-6-token-layout-trivia-policy โ€” layout/whitespace/insignificant-trivia is +// baked into LiteralPattern.text below (e.g. ") { ", "; }") instead of ES2022 ยง12.2 +// WhiteSpace/LineTerminator/Comment trivia carriers. Dissolves when T-6 supplies +// TokenLayout/TriviaPolicy and token_sequence_to_source interleaves layout +// (https://tc39.es/ecma262/2022/#sec-white-space). +fn ecmascript_wave1_lex_rules() -> LexRuleSet { + LexRuleSet { + rules: [ + ecmascript_lex_rule(token_class: ecmascript_token_rparen_lbrace_inner_open, text: ") {\n "), + ecmascript_lex_rule(token_class: ecmascript_token_rparen_lbrace_open, text: ") { "), + ecmascript_lex_rule(token_class: ecmascript_token_semicolon_rbrace_inner_close, text: ";\n }"), + ecmascript_lex_rule(token_class: ecmascript_token_semicolon_rbrace_close, text: "; }"), + ecmascript_lex_rule(token_class: ecmascript_token_if_open, text: "if ("), + ecmascript_lex_rule(token_class: ecmascript_token_let_assign_semicolon, text: "let "), + ecmascript_lex_rule(token_class: ecmascript_token_return_inner, text: "\n return "), + ecmascript_lex_rule(token_class: ecmascript_token_return_outer, text: "\n return "), + ecmascript_lex_rule(token_class: ecmascript_token_kw_function, text: "function "), + ecmascript_lex_rule(token_class: ecmascript_token_kw_return, text: "return "), + ecmascript_lex_rule(token_class: ecmascript_token_kw_if, text: "if "), + ecmascript_lex_rule(token_class: ecmascript_token_kw_let, text: "let "), + ecmascript_int_literal_lex_rule(), + ecmascript_ident_lex_rule(), + ecmascript_lex_rule(token_class: ecmascript_token_equal, text: " = "), + ecmascript_lex_rule(token_class: ecmascript_token_plus, text: " + "), + ecmascript_lex_rule(token_class: ecmascript_token_greater, text: " > "), + ecmascript_lex_rule(token_class: ecmascript_token_lparen, text: "("), + ecmascript_lex_rule(token_class: ecmascript_token_rparen, text: ")"), + ecmascript_lex_rule(token_class: ecmascript_token_lbrace, text: "{"), + ecmascript_lex_rule(token_class: ecmascript_token_rbrace, text: "}"), + ecmascript_lex_rule(token_class: ecmascript_token_comma, text: ", "), + ecmascript_lex_rule(token_class: ecmascript_token_semicolon, text: ";") + ] + } +} + +fn ecmascript_wave1_lex() -> LexRules { + ModeledLexRules { root: ecmascript_wave1_lex_rules() } +} + +fn ecmascript_grammar_atom(id: Symbol) -> Node { + ecmascript_inhabitant_atom(id: id) +} + +fn ecmascript_wave1_grammar_root() -> GrammarRoot { + GrammarRoot { + start: ecmascript_production_fn_decl, + productions: [ + ecmascript_grammar_production_mvp1_fn_add(), + // FunctionDeclaration (ES2022 ยง15.2): `function` BindingIdentifier `(` FormalParameters `)` Block. + // MVP-1 monomorphizes FormalParameters to a single binding identifier โ€” wider arity is wave-2a + // extension after T-6/T-7 lex/grammar substrate broadens. + ecmascript_formal_productions_to_grammar_production( + head: grammar_formal_production( + lhs: ecmascript_production_fn_decl, + rhs: [ + grammar_formal_terminal(identity: ecmascript_token_kw_function), + grammar_formal_terminal(identity: ecmascript_token_ident), + grammar_formal_terminal(identity: ecmascript_token_lparen), + grammar_formal_terminal(identity: ecmascript_token_ident), + grammar_formal_terminal(identity: ecmascript_token_rparen_lbrace_open), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_block) + ] + ), + alts: Empty, + emitted: ecmascript_surface_fn_item + ), + // Block (ES2022 ยง14.2): `{` StatementList `}` โ€” layout baked into the closing composite token. + // Left-biased Choice: longer/recursive block alt must precede single-stmt alt. + ecmascript_formal_productions_to_grammar_production( + head: grammar_formal_production( + lhs: ecmascript_production_block, + rhs: [ + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_stmt), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_block) + ] + ), + alts: [ + grammar_formal_production( + lhs: ecmascript_production_block, + rhs: [grammar_formal_nonterminal_occurrence(identity: ecmascript_production_stmt)] + ) + ], + emitted: ecmascript_surface_block + ), + ecmascript_formal_productions_to_grammar_production( + head: grammar_formal_production( + lhs: ecmascript_production_stmt, + rhs: [grammar_formal_nonterminal_occurrence(identity: ecmascript_production_assign_stmt)] + ), + alts: [ + grammar_formal_production( + lhs: ecmascript_production_stmt, + rhs: [grammar_formal_nonterminal_occurrence(identity: ecmascript_production_if_stmt)] + ), + grammar_formal_production( + lhs: ecmascript_production_stmt, + rhs: [grammar_formal_nonterminal_occurrence(identity: ecmascript_production_return_stmt)] + ) + ], + emitted: ecmascript_surface_stmt + ), + // LexicalDeclaration (ES2022 ยง14.3.1): `let` BindingIdentifier `=` AssignmentExpression `;`. + // MVP carries plain `Identifier = AssignmentExpression` form; `let` keyword and semicolon + // emission are layout-baked. + ecmascript_formal_productions_to_grammar_production( + head: grammar_formal_production( + lhs: ecmascript_production_assign_stmt, + rhs: [ + grammar_formal_terminal(identity: ecmascript_token_kw_let), + grammar_formal_terminal(identity: ecmascript_token_ident), + grammar_formal_terminal(identity: ecmascript_token_equal), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_additive), + grammar_formal_terminal(identity: ecmascript_token_semicolon) + ] + ), + alts: Empty, + emitted: ecmascript_surface_assign_stmt + ), + // IfStatement (ES2022 ยง14.6) head: `if (` Expression `) {` Statement `}` โ€” single-body MVP. + ecmascript_formal_productions_to_grammar_production( + head: grammar_formal_production( + lhs: ecmascript_production_if_stmt, + rhs: [ + grammar_formal_terminal(identity: ecmascript_token_if_open), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_comparison), + grammar_formal_terminal(identity: ecmascript_token_rparen_lbrace_inner_open), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_return_stmt) + ] + ), + alts: Empty, + emitted: ecmascript_surface_if_stmt + ), + // ReturnStatement (ES2022 ยง14.10): `return` Expression `;` โ€” layout alts cover outer/inner. + ecmascript_formal_productions_to_grammar_production( + head: grammar_formal_production( + lhs: ecmascript_production_return_stmt, + rhs: [ + grammar_formal_terminal(identity: ecmascript_token_return_inner), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_primary), + grammar_formal_terminal(identity: ecmascript_token_semicolon) + ] + ), + alts: [ + grammar_formal_production( + lhs: ecmascript_production_return_stmt, + rhs: [ + grammar_formal_terminal(identity: ecmascript_token_return_outer), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_primary), + grammar_formal_terminal(identity: ecmascript_token_semicolon) + ] + ), + grammar_formal_production( + lhs: ecmascript_production_return_stmt, + rhs: [ + grammar_formal_terminal(identity: ecmascript_token_kw_return), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_primary) + ] + ) + ], + emitted: ecmascript_surface_return_stmt + ), + ecmascript_formal_productions_to_grammar_production( + head: grammar_formal_production( + lhs: ecmascript_production_comparison, + rhs: [ + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_additive), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_comparison_tail) + ] + ), + alts: Empty, + emitted: ecmascript_surface_comparison + ), + // Left-biased Choice: consuming alt before empty tail alt. + ecmascript_formal_productions_to_grammar_production( + head: grammar_formal_production( + lhs: ecmascript_production_comparison_tail, + rhs: [ + grammar_formal_terminal(identity: ecmascript_token_greater), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_additive) + ] + ), + alts: [grammar_formal_production(lhs: ecmascript_production_comparison_tail, rhs: Empty)], + emitted: ecmascript_surface_comparison_tail + ), + ecmascript_formal_productions_to_grammar_production( + head: grammar_formal_production( + lhs: ecmascript_production_additive, + rhs: [ + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_primary), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_additive_tail) + ] + ), + alts: Empty, + emitted: ecmascript_surface_additive + ), + // Left-biased Choice: consuming alt before empty tail alt. + ecmascript_formal_productions_to_grammar_production( + head: grammar_formal_production( + lhs: ecmascript_production_additive_tail, + rhs: [ + grammar_formal_terminal(identity: ecmascript_token_plus), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_primary), + grammar_formal_nonterminal_occurrence(identity: ecmascript_production_additive_tail) + ] + ), + alts: [grammar_formal_production(lhs: ecmascript_production_additive_tail, rhs: Empty)], + emitted: ecmascript_surface_additive_tail + ), + ecmascript_formal_productions_to_grammar_production( + head: grammar_formal_production( + lhs: ecmascript_production_primary, + rhs: [grammar_formal_terminal(identity: ecmascript_token_ident)] + ), + alts: [ + grammar_formal_production( + lhs: ecmascript_production_primary, + rhs: [grammar_formal_terminal(identity: ecmascript_token_int_literal)] + ) + ], + emitted: ecmascript_surface_primary + ) + ], + sync_tokens: grammar_empty_sync_tokens() + } +} + +fn ecmascript_wave1_grammar() -> ParseGrammar { + ModeledGrammar { root: ecmascript_wave1_grammar_root() } +} + +fn ecmascript_wave1_lex_token_symbol(sym: Symbol) -> Bool { + lex_rule_set_token_class_member( + rules: ecmascript_wave1_lex_rules(), + token_class: sym + ) +} + +fn ecmascript_catalog_surface_spelling_eq(sym: Symbol, spelling: Symbol) -> Bool { + sym == spelling +} + +fn ecmascript_catalog_surface_fold_false() -> Bool { + false +} + +fn ecmascript_number_catalog_surface_step( + sym: Symbol, + acc: Bool, + facts: EcmascriptNumberPrimitiveFacts +) -> Bool { + acc || ecmascript_catalog_surface_spelling_eq(sym: sym, spelling: facts.surface_spelling) +} + +fn ecmascript_number_catalog_surface_symbol(sym: Symbol) -> Bool { + fold_list( + xs: ecmascript_number_facts_catalog, + empty: ecmascript_catalog_surface_fold_false(), + cons: fn(acc, facts) { + ecmascript_number_catalog_surface_step(sym: sym, acc: acc, facts: facts) + } + ) +} + +fn ecmascript_bigint_catalog_surface_step( + sym: Symbol, + acc: Bool, + facts: EcmascriptBigIntPrimitiveFacts +) -> Bool { + acc || ecmascript_catalog_surface_spelling_eq(sym: sym, spelling: facts.surface_spelling) +} + +fn ecmascript_bigint_catalog_surface_symbol(sym: Symbol) -> Bool { + fold_list( + xs: ecmascript_bigint_facts_catalog, + empty: ecmascript_catalog_surface_fold_false(), + cons: fn(acc, facts) { + ecmascript_bigint_catalog_surface_step(sym: sym, acc: acc, facts: facts) + } + ) +} + +fn ecmascript_boolean_catalog_surface_step( + sym: Symbol, + acc: Bool, + facts: EcmascriptBooleanPrimitiveFacts +) -> Bool { + acc || ecmascript_catalog_surface_spelling_eq(sym: sym, spelling: facts.surface_spelling) +} + +fn ecmascript_boolean_catalog_surface_symbol(sym: Symbol) -> Bool { + fold_list( + xs: ecmascript_boolean_facts_catalog, + empty: ecmascript_catalog_surface_fold_false(), + cons: fn(acc, facts) { + ecmascript_boolean_catalog_surface_step(sym: sym, acc: acc, facts: facts) + } + ) +} + +fn ecmascript_string_catalog_surface_step( + sym: Symbol, + acc: Bool, + facts: EcmascriptStringPrimitiveFacts +) -> Bool { + acc || ecmascript_catalog_surface_spelling_eq(sym: sym, spelling: facts.surface_spelling) +} + +fn ecmascript_string_catalog_surface_symbol(sym: Symbol) -> Bool { + fold_list( + xs: ecmascript_string_facts_catalog, + empty: ecmascript_catalog_surface_fold_false(), + cons: fn(acc, facts) { + ecmascript_string_catalog_surface_step(sym: sym, acc: acc, facts: facts) + } + ) +} + +fn ecmascript_symbol_catalog_surface_step( + sym: Symbol, + acc: Bool, + facts: EcmascriptSymbolPrimitiveFacts +) -> Bool { + acc || ecmascript_catalog_surface_spelling_eq(sym: sym, spelling: facts.surface_spelling) +} + +fn ecmascript_symbol_catalog_surface_symbol(sym: Symbol) -> Bool { + fold_list( + xs: ecmascript_symbol_facts_catalog, + empty: ecmascript_catalog_surface_fold_false(), + cons: fn(acc, facts) { + ecmascript_symbol_catalog_surface_step(sym: sym, acc: acc, facts: facts) + } + ) +} + +fn ecmascript_singleton_catalog_surface_step( + sym: Symbol, + acc: Bool, + facts: EcmascriptSingletonPrimitiveFacts +) -> Bool { + acc || ecmascript_catalog_surface_spelling_eq(sym: sym, spelling: facts.surface_spelling) +} + +fn ecmascript_singleton_catalog_surface_symbol(sym: Symbol) -> Bool { + fold_list( + xs: ecmascript_singleton_facts_catalog, + empty: ecmascript_catalog_surface_fold_false(), + cons: fn(acc, facts) { + ecmascript_singleton_catalog_surface_step(sym: sym, acc: acc, facts: facts) + } + ) +} + +fn ecmascript_catalog_surface_symbol(sym: Symbol) -> Bool { + ecmascript_number_catalog_surface_symbol(sym: sym) || + ecmascript_bigint_catalog_surface_symbol(sym: sym) || + ecmascript_boolean_catalog_surface_symbol(sym: sym) || + ecmascript_string_catalog_surface_symbol(sym: sym) || + ecmascript_symbol_catalog_surface_symbol(sym: sym) || + ecmascript_singleton_catalog_surface_symbol(sym: sym) +} + +fn ecmascript_language_model_canonical_symbols() -> Set { + Set { + member: fn(sym) { + ecmascript_catalog_surface_symbol(sym: sym) || + ecmascript_wave1_lex_token_symbol(sym: sym) || + grammar_carries_symbol(grammar: ecmascript_wave1_grammar(), sym: sym) || + sym == ecmascript_surface_fn_item || + sym == ecmascript_production_mvp1_fn_add || + sym == ecmascript_mvp1_source_literal + } + } +} + +fn ecmascript_language_model_wave1() -> EcmascriptLanguageModel { + EcmascriptLanguageModel { + lex: ecmascript_wave1_lex(), + grammar: ecmascript_wave1_grammar(), + language_identity: ecmascript_language_model_surface_id, + canonical_symbols: ecmascript_language_model_canonical_symbols(), + core: ecmascript_model_core_wave1() + } +}