~tim-ats-d/Postem-markup

b7fc43d309cea746272221f2d1ca1445bc4aa891 — Tim-ats-d 2 years ago 74a4f8d
Fix checking of unformat expression.
3 files changed, 16 insertions(+), 15 deletions(-)

M src/ast/eval.ml
M src/ast/types.ml
M src/checker/checker.ml
M src/ast/eval.ml => src/ast/eval.ml +1 -1
@@ 20,7 20,7 @@ module MakeWithExpsn (Expsn : Expansion.S) : S with type t := string = struct
  and eval_expr ctx expr =
    let open Types in
    match expr with
    | Text s | White s -> s
    | Text s | White s | Unformat s -> s
    | Group grp -> eval_group ctx grp
    | UnaryOp { op; group } -> eval_uop ctx op group


M src/ast/types.ml => src/ast/types.ml +1 -0
@@ 3,5 3,6 @@deriving show]
and expr =
  | Text of string
  | White of string
  | Unformat of string
  | Group of expr list
  | UnaryOp of { op : string; group : expr }

M src/checker/checker.ml => src/checker/checker.ml +14 -14
@@ 4,23 4,23 @@ module type S = sig
  val check : Syntax.Parsed_ast.t -> (Ast.Types.doc, Err.checker_err) result
end

type state =
  | Expr of Ast.Types.expr
  | Expand of Ast.Types.expr * Ast.Types.expr

module Make (Expsn : Ast.Expansion.S) : S = struct
  open Result

  type state =
    | Expr of Ast.Types.expr
    | Expand of Ast.Types.expr * Ast.Types.expr

  let rec check parsed_ast =
    List.rev parsed_ast
    |> List.fold_left
         (fun acc expr ->
           let+ grp = acc in
           let+ expr' = pexpr expr in
           match expr' with
           | Expr e -> Ok (e :: grp)
           | Expand (e, e') -> Ok (e :: e' :: grp))
         (Ok [])
    List.fold_left
      (fun acc expr ->
        let+ grp = acc in
        let+ expr' = pexpr expr in
        match expr' with
        | Expr e -> Ok (e :: grp)
        | Expand (e, e') -> Ok (e :: e' :: grp))
      (Ok [])
    @@ List.rev parsed_ast

  and pexpr =
    let open Ast.Types in


@@ 33,7 33,7 @@ module Make (Expsn : Ast.Expansion.S) : S = struct
        in
        ok @@ Expr (Text text)
    | LWhite w -> ok @@ Expr (White w)
    | LUnformat u -> ok @@ Expr (Text u)
    | LUnformat u -> ok @@ Expr (Unformat u)
    | LGroup g ->
        let+ grp =
          List.fold_left