Skip to content

Commit f4d24bc

Browse files
committed
[spectec] Support subscripting prec/succ
1 parent fdb3bd0 commit f4d24bc

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

spectec/doc/Language.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ atomop ::=
163163
"`~" | "`/\" | "`\/" | "`==>" | "`<=>"
164164
"`<-"
165165
"(/\)" | "(\/)" | "(!)" | "(?)" | "(+)" | "(*)" | "(++)"
166-
":_" | "=_" | "==_" | "~~_" | "->_" | "=>_" | "~>_" | "~>*_" | "|-_" | "-|_"
166+
":_" | "=_" | "==_" | "~~_" | "->_" | "=>_" | "~>_" | "~>*_" | "<<_" | ">>_" | "|-_" | "-|_"
167167
```
168168

169169
##### Type Aliases
@@ -1385,7 +1385,7 @@ atomop ::=
13851385
"`~" | "`/\" | "`\/" | "`==>" | "`<=>"
13861386
"`<-"
13871387
"(/\)" | "(\/)" | "(!)" | "(?)" | "(+)" | "(*)" | "(++)"
1388-
":_" | "=_" | "==_" | "~~_" | "->_" | "=>_" | "~>_" | "~>*_" | "|-_" | "-|_"
1388+
":_" | "=_" | "==_" | "~~_" | "->_" | "=>_" | "~>_" | "~>*_" | "<<_" | ">>_" | "|-_" | "-|_"
13891389
```
13901390

13911391

0 Bytes
Binary file not shown.

spectec/src/frontend/lexer.mll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ and token = parse
209209
| "~>*_" { SQARROWSTARSUB }
210210
| "<<" { PREC }
211211
| ">>" { SUCC }
212+
| "<<_" { PRECSUB }
213+
| ">>_" { SUCCSUB }
212214
| "|-" { TURNSTILE }
213215
| "-|" { TILESTURN }
214216
| "|-_" { TURNSTILESUB }

spectec/src/frontend/parser.mly

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ and short_alt_prod' = function
180180
%token NOT AND OR IMPL DIMPL
181181
%token QUEST PLUS MINUS STAR SLASH BACKSLASH UP CAT PLUSMINUS MINUSPLUS
182182
%token ARROW ARROW2 ARROWSUB ARROW2SUB SQARROW SQARROWSUB SQARROWSTAR SQARROWSTARSUB
183-
%token MEM NOTMEM PREC SUCC TURNSTILE TILESTURN TURNSTILESUB TILESTURNSUB
183+
%token MEM NOTMEM PREC SUCC PRECSUB SUCCSUB TURNSTILE TILESTURN TURNSTILESUB TILESTURNSUB
184184
%token DOLLAR TICK
185185
%token BOT TOP
186186
%token HOLE MULTIHOLE NOTHING FUSE FUSEFUSE LATEX
@@ -200,7 +200,7 @@ and short_alt_prod' = function
200200
%left AND
201201
%nonassoc TURNSTILE TURNSTILESUB
202202
%nonassoc TILESTURN TILESTURNSUB
203-
%right SQARROW SQARROWSUB SQARROWSTAR SQARROWSTARSUB PREC SUCC BIGAND BIGOR BIGFORALL BIGEXISTS BIGADD BIGMUL BIGCAT
203+
%right SQARROW SQARROWSUB SQARROWSTAR SQARROWSTARSUB PREC SUCC PRECSUB SUCCSUB BIGAND BIGOR BIGFORALL BIGEXISTS BIGADD BIGMUL BIGCAT
204204
%left COLON SUB SUP ASSIGN EQUIV APPROX COLONSUB EQUIVSUB APPROXSUB
205205
%left COMMA COMMA_NL
206206
%right EQ NE LT GT LE GE MEM NOTMEM EQSUB
@@ -467,6 +467,8 @@ check_atom :
467467
| APPROXSUB { Atom.ApproxSub }
468468
| SQARROWSUB { Atom.SqArrowSub }
469469
| SQARROWSTARSUB { Atom.SqArrowStarSub }
470+
| PRECSUB { Atom.PrecSub }
471+
| SUCCSUB { Atom.SuccSub }
470472
| TILESTURNSUB { Atom.TilesturnSub }
471473
| TURNSTILESUB { Atom.TurnstileSub }
472474

spectec/src/xl/atom.ml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ and atom' =
4747
| SqArrowStarSub (* `~>*_` *)
4848
| Prec (* `<<` *)
4949
| Succ (* `>>` *)
50+
| PrecSub (* `<<_` *)
51+
| SuccSub (* `>>_` *)
5052
| Turnstile (* `|-` *)
5153
| TurnstileSub (* `|-_` *)
5254
| Tilesturn (* `-|` *)
@@ -84,7 +86,8 @@ let is_sub atom =
8486
match atom.it with
8587
| Atom id -> id <> "" && id.[String.length id - 1] = '_'
8688
| ArrowSub | Arrow2Sub | ColonSub | EqualSub | EquivSub | ApproxSub
87-
| SqArrowSub | SqArrowStarSub | TurnstileSub | TilesturnSub -> true
89+
| SqArrowSub | SqArrowStarSub | PrecSub | SuccSub
90+
| TurnstileSub | TilesturnSub -> true
8891
| _ -> false
8992

9093
let sub atom1 atom2 =
@@ -98,6 +101,8 @@ let sub atom1 atom2 =
98101
| ApproxSub, Approx
99102
| SqArrowSub, SqArrow
100103
| SqArrowStarSub, SqArrowStar
104+
| PrecSub, Prec
105+
| SuccSub, Succ
101106
| TurnstileSub, Turnstile
102107
| TilesturnSub, Tilesturn -> true
103108
| _, _ -> false
@@ -144,9 +149,11 @@ let to_string atom =
144149
| SqArrowStarSub -> "~>*_"
145150
| Prec -> "<<"
146151
| Succ -> ">>"
152+
| PrecSub -> "<<_"
153+
| SuccSub -> ">>_"
147154
| Tilesturn -> "-|"
148-
| TilesturnSub -> "-|_"
149155
| Turnstile -> "|-"
156+
| TilesturnSub -> "-|_"
150157
| TurnstileSub -> "|-_"
151158
| Quest -> "^?"
152159
| Star -> "^*"
@@ -220,9 +227,11 @@ let name atom =
220227
| SqArrowStarSub -> "sqarrowstar_" (* Latex: \hookrightarrow^\ast with subscript *)
221228
| Prec -> "prec"
222229
| Succ -> "succ"
230+
| PrecSub -> "prec_"
231+
| SuccSub -> "succ_"
223232
| Tilesturn -> "dashv"
224-
| TilesturnSub -> "dashv_" (* Latex: \dashv with subscript *)
225233
| Turnstile -> "vdash"
234+
| TilesturnSub -> "dashv_" (* Latex: \dashv with subscript *)
226235
| TurnstileSub -> "vdash_" (* Latex: \vdash with subscript *)
227236
| Quest -> "quest" (* Latex: ^? *)
228237
| Star -> "ast" (* Latex: ^\ast *)

0 commit comments

Comments
 (0)