ocaml: phase 1+5.1 type aliases + poly_stack baseline (+3 tests, 469 / 19 baseline)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 39s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 39s
Parser: in parse-decl-type, dispatch on the post-= token:
'|' or Ctor -> sum type
'{' -> record type
otherwise -> type alias (skip to boundary)
AST (:type-alias NAME PARAMS) with body discarded. Runtime no-op since
SX has no nominal types.
poly_stack.ml baseline exercises:
module type ELEMENT = sig type t val show : t -> string end
module IntElem = struct type t = int let show x = ... end
module Make (E : ELEMENT) = struct ... use E.show ... end
module IntStack = Make(IntElem)
Demonstrates the substrate handles signature decls + abstract types +
functor parameter with sig constraint.
This commit is contained in:
@@ -1242,6 +1242,29 @@
|
||||
(field-more)
|
||||
(consume! "op" "}")
|
||||
(list :type-def-record name tparams fields)))))
|
||||
;; Type alias: type t = int / type t = 'a list / etc.
|
||||
;; Detected when next token is NOT `|` and NOT a ctor.
|
||||
((and (not (at-op? "|"))
|
||||
(not (= (ocaml-tok-type (peek-tok)) "ctor")))
|
||||
(begin
|
||||
;; Skip the alias source up to the next boundary.
|
||||
(define skip-alias
|
||||
(fn ()
|
||||
(cond
|
||||
((>= idx tok-len) nil)
|
||||
((= (ocaml-tok-type (peek-tok)) "eof") nil)
|
||||
((at-op? ";;") nil)
|
||||
((at-kw? "let") nil)
|
||||
((at-kw? "type") nil)
|
||||
((at-kw? "and") nil)
|
||||
((at-kw? "module") nil)
|
||||
((at-kw? "exception") nil)
|
||||
((at-kw? "open") nil)
|
||||
((at-kw? "include") nil)
|
||||
((at-kw? "end") nil)
|
||||
(else (begin (advance-tok!) (skip-alias))))))
|
||||
(skip-alias)
|
||||
(list :type-alias name tparams)))
|
||||
(else
|
||||
(begin
|
||||
(when (at-op? "|") (advance-tok!))
|
||||
|
||||
Reference in New Issue
Block a user