-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
[@@@ocaml.text "/*"] | ||
|
||
(** Copyright 2024, Andrei, PavlushaSource *) | ||
|
||
(** SPDX-License-Identifier: MIT *) | ||
|
||
[@@@ocaml.text "/*"] | ||
|
||
(* https://ocaml.org/manual/5.2/modules.html#s:module-expr *) | ||
|
||
open! Base | ||
open Angstrom | ||
open LAst | ||
|
||
open Common | ||
|
||
let plet = | ||
let* rec_flag, bindings = plet Expr.pexpr Pat.ppat in | ||
opt @@ spaced (string "in") | ||
>>= function | ||
| None -> | ||
return (StrLet (rec_flag, bindings)) | ||
| Some _ -> | ||
Expr.pexpr >>| fun expr -> StrEval (ExpLet (rec_flag, bindings, expr)) | ||
|
||
let pty_params_ = | ||
let pmultiple = parens @@ sep_by1 (ws *> char ',') (ws *> pty_var_id) in | ||
let psingle = pty_var_id >>| List.return in | ||
psingle <|> pmultiple <|> return [] | ||
|
||
let pconstruct_decl_ = | ||
let* id = pconstruct_id in | ||
let* arg = | ||
opt @@ spaced (string "of") | ||
>>= function None -> return None | Some _ -> Ty.pty >>| Option.some | ||
in | ||
return {id; arg} | ||
|
||
let pty_decl = | ||
let* params = string "type" *> ws1 *> pty_params_ in | ||
let* id = ws *> pty_con_id in | ||
let* variants = | ||
ws *> string "=" *> ws | ||
*> opt (string "|") | ||
*> sep_by1 (ws *> char '|') (ws *> pconstruct_decl_) | ||
in | ||
return (StrType {id; params; variants}) | ||
|
||
let peval = Expr.pexpr >>| fun expr -> StrEval expr | ||
|
||
let pstr_item = ws *> choice [plet; pty_decl; peval] | ||
|
||
let pstr = | ||
let sep = ws *> opt (string ";;") in | ||
sep_by sep pstr_item <* sep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[@@@ocaml.text "/*"] | ||
|
||
(** Copyright 2024, Andrei, PavlushaSource *) | ||
|
||
(** SPDX-License-Identifier: MIT *) | ||
|
||
[@@@ocaml.text "/*"] | ||
|
||
open! Base | ||
open Angstrom | ||
open LAst | ||
|
||
val pstr : structure t |