ocaml: phase 1 type annotations on let / (e : T) (+4 tests, 473 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
let NAME [PARAMS] : T = expr and (expr : T) parse and skip the type source. Runtime no-op since SX is dynamic. Works in inline let, top-level let, and parenthesised expressions: let x : int = 5 ;; x + 1 -> 6 let f (x : int) : int = x + 1 in f 41 -> 42 (5 : int) -> 5 ((1 + 2) : int) * 3 -> 9
This commit is contained in:
@@ -422,7 +422,21 @@
|
||||
(else
|
||||
(let
|
||||
((e (parse-expr)))
|
||||
(begin (consume! "op" ")") e))))))
|
||||
(begin
|
||||
;; Optional type annotation `(e : T)` — skip
|
||||
;; the type source before `)`.
|
||||
(when (at-op? ":")
|
||||
(begin
|
||||
(advance-tok!)
|
||||
(define skip-pty
|
||||
(fn ()
|
||||
(cond
|
||||
((>= idx tok-len) nil)
|
||||
((= (ocaml-tok-type (peek-tok)) "eof") nil)
|
||||
((at-op? ")") nil)
|
||||
(else (begin (advance-tok!) (skip-pty))))))
|
||||
(skip-pty)))
|
||||
(consume! "op" ")") e))))))
|
||||
((and (= tt "op") (= tv "["))
|
||||
(begin
|
||||
(advance-tok!)
|
||||
@@ -683,6 +697,18 @@
|
||||
(when (not (= p nil))
|
||||
(begin (append! ps p) (collect-params))))))
|
||||
(collect-params)
|
||||
;; Optional type annotation: skip `: TYPE` before `=`.
|
||||
(when (at-op? ":")
|
||||
(begin
|
||||
(advance-tok!)
|
||||
(define skip-tann
|
||||
(fn ()
|
||||
(cond
|
||||
((>= idx tok-len) nil)
|
||||
((= (ocaml-tok-type (peek-tok)) "eof") nil)
|
||||
((at-op? "=") nil)
|
||||
(else (begin (advance-tok!) (skip-tann))))))
|
||||
(skip-tann)))
|
||||
(consume! "op" "=")
|
||||
(let ((rhs (parse-expr)))
|
||||
(append! bindings (list nm ps rhs)))))))
|
||||
@@ -1101,6 +1127,18 @@
|
||||
(collect-params)))
|
||||
(else nil))))
|
||||
(collect-params)
|
||||
;; Optional type annotation: skip `: TYPE` before `=`.
|
||||
(when (at-op? ":")
|
||||
(begin
|
||||
(advance-tok!)
|
||||
(define skip-tann
|
||||
(fn ()
|
||||
(cond
|
||||
((>= idx tok-len) nil)
|
||||
((= (ocaml-tok-type (peek-tok)) "eof") nil)
|
||||
((at-op? "=") nil)
|
||||
(else (begin (advance-tok!) (skip-tann))))))
|
||||
(skip-tann)))
|
||||
(consume! "op" "=")
|
||||
(let ((expr-start (cur-pos)))
|
||||
(begin
|
||||
|
||||
Reference in New Issue
Block a user