Skip to content

Commit

Permalink
Implement Mlc.Scan as wrapper around Hmc.Scan
Browse files Browse the repository at this point in the history
This implemention is ostensibly complete, with the exception of missing
OCaml-specific functionality in `Hmc.Scan`.
  • Loading branch information
Jason Evans committed Sep 16, 2024
1 parent 9bb1152 commit d74db39
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 6,736 deletions.
17 changes: 9 additions & 8 deletions bootstrap/src/hmc/scan.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
* source file). The trace output is detailed enough to diagnose nearly any scanner flaw, as well as
* to aid understanding of how a particular token is scanned.
*
* Most language syntax changes require modifying the DFA, but keywords and special operators can be
* added/removed with low effort.
*
* - Keywords are mapped to tokens in `Dfa.Ident.keyword_map`.
* - Special operators are mapped to tokens in `Dfa.Operator.operator_map`.
* Most language syntax changes require modifying the DFA, but keywords and single-codepoint
* operators can be added/removed with low effort.
*
* Adding/removing a DFA state may require changes in several places:
*
Expand Down Expand Up @@ -124,8 +121,12 @@ module Token = struct
let cmp t0 t1 =
Source.Slice.cmp t0.source t1.source

let init ~base ~past ~description =
{source=Source.Slice.of_cursors ~base ~past; description}
let of_source ~source ~description =
{source; description}

let of_cursors ~base ~past ~description =
let source = Source.Slice.of_cursors ~base ~past in
of_source ~source ~description

let source t =
t.source
Expand Down Expand Up @@ -1499,7 +1500,7 @@ let in_fstring t =
* Convenience routines for reporting malformations. *)

let malformation ~base ~past description =
Token.Rendition.Malformation.init ~base ~past ~description
Token.Rendition.Malformation.of_cursors ~base ~past ~description

let malformation_incl View.{cursor; _} t description =
malformation ~base:t.tok_base ~past:cursor description
Expand Down
3 changes: 2 additions & 1 deletion bootstrap/src/hmc/scan.mli
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ module Token : sig

include FormattableIntf.SMono with type t := t

val init: base:Source.Cursor.t -> past:Source.Cursor.t -> description:string -> t
val of_source: source:Source.Slice.t -> description:string -> t
val of_cursors: base:Source.Cursor.t -> past:Source.Cursor.t -> description:string -> t
val source: t -> Source.Slice.t
val description: t -> string
end
Expand Down
Loading

0 comments on commit d74db39

Please sign in to comment.