Skip to content

Commit

Permalink
More scanner refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Evans committed Aug 19, 2024
1 parent fa50fb1 commit e6b5880
Showing 1 changed file with 42 additions and 34 deletions.
76 changes: 42 additions & 34 deletions bootstrap/src/hmc/scan.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,15 @@ let in_fstring t =
let malformation ~base ~past description =
Token.Rendition.Malformation.init ~base ~past ~description

let malformation_incl View.{cursor; _} t description =
malformation ~base:t.tok_base ~past:cursor description

let malformation_excl View.{pcursor; _} t description =
malformation ~base:t.tok_base ~past:pcursor description

let malformation_pexcl View.{ppcursor; _} t description =
malformation ~base:t.tok_base ~past:ppcursor description

let malformed malformation =
Token.Rendition.of_mals [malformation]

Expand Down Expand Up @@ -3680,6 +3689,15 @@ module Dfa = struct
let accept_tok tok cursor t =
{t with tok_base=cursor}, Accept tok

let accept_tok_incl tok View.{cursor; _} t =
accept_tok tok cursor t

let accept_tok_excl tok View.{pcursor; _} t =
accept_tok tok pcursor t

let accept_tok_pexcl tok View.{ppcursor; _} t =
accept_tok tok ppcursor t

let source_at cursor t =
Source.Slice.of_cursors ~base:t.tok_base ~past:cursor

Expand Down Expand Up @@ -3834,26 +3852,17 @@ module Dfa = struct
let node0_start =
{
edges0=map_of_cps_alist [
(",", fun (View.{cursor; _} as view) t ->
accept_tok (Tok_comma {source=source_incl view t}) cursor t);
(";", fun (View.{cursor; _} as view) t ->
accept_tok (Tok_semi {source=source_incl view t}) cursor t);
(",", fun view t -> accept_tok_incl (Tok_comma {source=source_incl view t}) view t);
(";", fun view t -> accept_tok_incl (Tok_semi {source=source_incl view t}) view t);
("(", advance State_lparen);
(")", fun (View.{cursor; _} as view) t ->
accept_tok (Tok_rparen {source=source_incl view t}) cursor t);
(")", fun view t -> accept_tok_incl (Tok_rparen {source=source_incl view t}) view t);
("[", advance State_lbrack);
("]", fun (View.{cursor; _} as view) t ->
accept_tok (Tok_rbrack {source=source_incl view t}) cursor t);
("{", fun (View.{cursor; _} as view) t ->
accept_tok (Tok_lcurly {source=source_incl view t}) cursor t);
("}", fun (View.{cursor; _} as view) t ->
accept_tok (Tok_rcurly {source=source_incl view t}) cursor t);
("\\", fun (View.{cursor; _} as view) t ->
accept_tok (Tok_bslash {source=source_incl view t}) cursor t);
("&", fun (View.{cursor; _} as view) t ->
accept_tok (Tok_amp {source=source_incl view t}) cursor t);
("!", fun (View.{cursor; _} as view) t ->
accept_tok (Tok_xmark {source=source_incl view t}) cursor t);
("]", fun view t -> accept_tok_incl (Tok_rbrack {source=source_incl view t}) view t);
("{", fun view t -> accept_tok_incl (Tok_lcurly {source=source_incl view t}) view t);
("}", fun view t -> accept_tok_incl (Tok_rcurly {source=source_incl view t}) view t);
("\\", fun view t -> accept_tok_incl (Tok_bslash {source=source_incl view t}) view t);
("&", fun view t -> accept_tok_incl (Tok_amp {source=source_incl view t}) view t);
("!", fun view t -> accept_tok_incl (Tok_xmark {source=source_incl view t}) view t);
("\n", accept_whitespace_incl);
("~", advance State_tilde);
("?", advance State_qmark);
Expand Down Expand Up @@ -3886,30 +3895,30 @@ module Dfa = struct
advance (State_integer_dec (State.Integer_dec.init ~n:digit)) view t
);
];
default0=(fun (View.{cursor; _} as view) t ->
let mal = malformation ~base:t.tok_base ~past:cursor "Unsupported codepoint" in
accept_tok (Tok_error {source=source_incl view t; error=[mal]}) cursor t
default0=(fun view t ->
let mal = malformation_incl view t "Unsupported codepoint" in
accept_tok_incl (Tok_error {source=source_incl view t; error=[mal]}) view t
);
eoi0=(fun (View.{cursor; _} as view) t ->
eoi0=(fun view t ->
match Level.level t.level, t.line_state with
| 0L, Line_begin -> accept_tok (Tok_line_delim {source=source_incl view t}) cursor t
| 0L, _ -> accept_tok (Tok_end_of_input {source=source_incl view t}) cursor t
| 0L, Line_begin -> accept_tok_incl (Tok_line_delim {source=source_incl view t}) view t
| 0L, _ -> accept_tok_incl (Tok_end_of_input {source=source_incl view t}) view t
| _ -> begin
accept_tok (Tok_dedent {
accept_tok_incl (Tok_dedent {
source=source_incl view t;
dedent=(Constant ())
}) cursor {t with level=Level.pred t.level}
}) view {t with level=Level.pred t.level}
end
);
}

let node0_lparen = {
edges0=map_of_cps_alist [
("|", accept_incl Tok_lcapture);
("|", fun view t -> accept_tok_incl (Tok_lcapture {source=source_incl view t}) view t);
("*", advance (State_paren_comment_body (State.Paren_comment_body.init ~nesting:1L)));
];
default0=accept_excl Tok_lparen;
eoi0=accept_incl Tok_lparen;
default0=(fun view t -> accept_tok_excl (Tok_lparen {source=source_excl view t}) view t);
eoi0=(fun view t -> accept_tok_incl (Tok_lparen {source=source_incl view t}) view t);
}

let node0_lbrack = {
Expand Down Expand Up @@ -4838,11 +4847,10 @@ module Dfa = struct
advance (State_real_dec_dot (State.Real_dec_dot.mals ~mals:[mal])) view t
);
];
default0=(fun view t -> Token.Tok_r64 {source=source_excl view t; r64=(Constant 0.)})
(*XXX
default0=accept_excl (AbstractToken.Tok_r64 (Constant 0.));
*)
eoi0=accept_incl (AbstractToken.Tok_r64 (Constant 0.));
default0=(fun view t ->
accept_tok_excl (Tok_r64 {source=source_excl view t; r64=(Constant 0.)}) view t);
eoi0=(fun view t ->
accept_tok_incl (Tok_r64 {source=source_incl view t; r64=(Constant 0.)}) view t);
}

let node0_0box ~base_cps ~state ~state_base_init =
Expand Down

0 comments on commit e6b5880

Please sign in to comment.