Skip to content

Commit

Permalink
Do not group star splices by default (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossberg authored Jun 28, 2024
2 parents cb6f5c6 + d356782 commit 769ca42
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
9 changes: 5 additions & 4 deletions document/core/valid/matching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ A :ref:`reference type <syntax-reftype>` ${reftype: REF nul1 heaptype_1} matches

* :math:`\NULL_1` is absent or :math:`\NULL_2` is present.

$${rule: Reftype_sub/*}
$${rule: {Reftype_sub/*}}

.. index:: value type, number type, reference type
Expand Down Expand Up @@ -197,7 +197,7 @@ A :ref:`composite type <syntax-comptype>` ${:comptype_1} matches a type ${:compt

* The :ref:`field type <syntax-fieldtype>` :math:`\fieldtype_1` :ref:`matches <match-fieldtype>` :math:`\fieldtype_2`.

$${rule: Comptype_sub/*}
$${rule: {Comptype_sub/*}}

.. index:: field type, storage type, value type, packed type, mutability
Expand All @@ -216,7 +216,8 @@ A :ref:`field type <syntax-fieldtype>` ${fieldtype: (mut1 storagetype_1)} matche

* Or both :math:`\mut_1` and :math:`\mut_2` are :math:`\MVAR` and :math:`\storagetype_2` :ref:`matches <match-storagetype>` :math:`\storagetype_1` as well.

$${rule: Fieldtype_sub/*}
$${rule: {Fieldtype_sub/*}}

A :ref:`storage type <syntax-storagetype>` :math:`\storagetype_1` matches a type :math:`\storagetype_2` if and only if:

Expand Down Expand Up @@ -320,7 +321,7 @@ A :ref:`global type <syntax-globaltype>` ${globaltype: (mut1 valtype_1)} matches

* Or both :math:`\mut_1` and :math:`\mut_2` are |MCONST| and :math:`t_1` :ref:`matches <match-valtype>` :math:`t_2`.

$${rule: Globaltype_sub/*}
$${rule: {Globaltype_sub/*}}

.. index:: external type, function type, table type, memory type, global type
Expand Down
8 changes: 4 additions & 4 deletions document/core/valid/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $${rule: Type_ok}

* Then the type sequence is valid.

$${rule: Types_ok/*}
$${rule: {Types_ok/*}}

.. index:: function, local, function index, local index, type index, function type, value type, local type, expression, import
Expand Down Expand Up @@ -88,7 +88,7 @@ Functions ${:func} are classified by :ref:`defined types <syntax-deftype>` that

* Then the function definition is valid with type :math:`C.\CTYPES[x]`.

$${rule: Func_ok Local_ok}
$${rule: Func_ok}


.. index:: local, local type, value type
Expand All @@ -114,7 +114,7 @@ Locals ${:local} are classified with :ref:`local types <syntax-localtype>`.

* The local is valid with :ref:`local type <syntax-localtype>` :math:`\UNSET~\valtype`.

$${rule: Local_ok/*}
$${rule: {Local_ok/*}}
.. note::
For cases where both rules are applicable, the former yields the more permissable type.
Expand Down Expand Up @@ -209,7 +209,7 @@ $${rule: Global_ok}

* Then the sequence is valid with the sequence of :ref:`global types <syntax-globaltype>` consisting of :math:`\X{gt}_1` prepended to :math:`\X{gt}^\ast`.

$${rule: Globals_ok/*}
$${rule: {Globals_ok/*}}

.. index:: element, table, table index, expression, constant, function index
Expand Down
8 changes: 5 additions & 3 deletions spectec/src/backend-splice/splice.ml
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,21 @@ let find_entry space src id1 id2 entries =
error src ("duplicate " ^ space ^ " identifier `" ^ id1 ^ "/" ^ id2 ^ "`")
*)

let ungroup = List.map (fun x -> [x])

let find_syntax env src id1 id2 =
match Map.find_opt id1 env.syn with
| None -> error src ("unknown syntax identifier `" ^ id1 ^ "`")
| Some syntax ->
let defs = find_entries "syntax" src id1 id2 syntax.sfragments in
if id2 = "" then [defs] else List.map (fun def -> [def]) defs
if id2 = "" then [defs] else ungroup defs

let find_grammar env src id1 id2 =
match Map.find_opt id1 env.gram with
| None -> error src ("unknown grammar identifier `" ^ id1 ^ "`")
| Some grammar ->
let defs = find_entries "grammar" src id1 id2 grammar.gfragments in
if id2 = "" then [defs] else List.map (fun def -> [def]) defs
if id2 = "" then [defs] else ungroup defs

let find_relation env src id1 id2 =
find_nosub "relation" src id1 id2;
Expand All @@ -219,7 +221,7 @@ let find_relation env src id1 id2 =
let find_rule env src id1 id2 =
match Map.find_opt id1 env.rel with
| None -> error src ("unknown relation identifier `" ^ id1 ^ "`")
| Some relation -> [find_entries "rule" src id1 id2 relation.rules]
| Some relation -> ungroup (find_entries "rule" src id1 id2 relation.rules)

let find_def env src id1 id2 =
find_nosub "definition" src id1 id2;
Expand Down
4 changes: 2 additions & 2 deletions spectec/test-splice/TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ $$
}{
C \vdash \epsilon : \epsilon \rightarrow \epsilon
} \, {[\textsc{\scriptsize T{-}instr*{-}empty}]}
\qquad
\\[3ex]\displaystyle
\frac{
C \vdash {{\mathit{instr}}^\ast} : {t_1^\ast}~{\rightarrow}_{({x^\ast})}\,{t_2^\ast}
\qquad
Expand Down Expand Up @@ -297,7 +297,7 @@ $$
$$
\begin{array}{@{}l@{}rcl@{}l@{}}
{[\textsc{\scriptsize E{-}if{-}true}]} \quad & (\mathsf{i{\scriptstyle 32}}{.}\mathsf{const}~c)~(\mathsf{if}~{\mathit{bt}}~{{\mathit{instr}}_1^\ast}~\mathsf{else}~{{\mathit{instr}}_2^\ast}) &\hookrightarrow& (\mathsf{block}~{\mathit{bt}}~{{\mathit{instr}}_1^\ast})
&\qquad \mbox{if}~c \neq 0 \\
&\qquad \mbox{if}~c \neq 0 \\[0.8ex]
{[\textsc{\scriptsize E{-}if{-}false}]} \quad & (\mathsf{i{\scriptstyle 32}}{.}\mathsf{const}~c)~(\mathsf{if}~{\mathit{bt}}~{{\mathit{instr}}_1^\ast}~\mathsf{else}~{{\mathit{instr}}_2^\ast}) &\hookrightarrow& (\mathsf{block}~{\mathit{bt}}~{{\mathit{instr}}_2^\ast})
&\qquad \mbox{if}~c = 0 \\
\end{array}
Expand Down

0 comments on commit 769ca42

Please sign in to comment.