Skip to content

Commit

Permalink
Bootstrap the hocc parser
Browse files Browse the repository at this point in the history
Replace the hand-written recursive-descent hocc parser with a hocc-generated
parser. The parsers have equivalent behavior with the inconsequential exception
of how leading/trailing comments are associated with reduction callback code and
the postlude.
  • Loading branch information
Jason Evans committed Aug 18, 2024
1 parent 68f651c commit e877ac0
Show file tree
Hide file tree
Showing 23 changed files with 16,628 additions and 1,912 deletions.
1,992 changes: 1,992 additions & 0 deletions bootstrap/bin/hocc/Parse.hmh

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions bootstrap/bin/hocc/code.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ let expand_hm_callbacks hocc_block symbols callbacks ~indentation formatter =
let underline = Codepoint.of_char '_' in
let overline = Codepoint.kv 0x203eL (*'‾'*) in
let code = Option.value_hlt code in
let source = Parse.source_of_code hocc_block code in
let source = Parse.source_of_code code in
formatter
|> Fmt.fmt "function\n"
|> (fun formatter ->
Expand Down Expand Up @@ -3531,7 +3531,7 @@ let expand_ml_nonterms symbols ~indentation formatter =
|> Fmt.fmt "\n"
|> expand_ml_nonterm_index symbols ~indentation

let expand_ml_callbacks hocc_block symbols callbacks ~indentation formatter =
let expand_ml_callbacks symbols callbacks ~indentation formatter =
let fmt_callbacks ~indentation formatter = begin
let indent = mk_indent indentation in
let formatter, _first = Callbacks.fold ~init:(formatter, true)
Expand All @@ -3552,7 +3552,7 @@ let expand_ml_callbacks hocc_block symbols callbacks ~indentation formatter =
let underline = Codepoint.of_char '_' in
let overline = Codepoint.kv 0x203eL (*'‾'*) in
let code = Option.value_hlt code in
let source = Parse.source_of_code hocc_block code in
let source = Parse.source_of_code code in
formatter
|> Fmt.fmt "(function\n"
|> (fun formatter ->
Expand Down Expand Up @@ -3682,7 +3682,7 @@ let expand_ml_starts symbols states ~indentation formatter =
in
formatter

let expand_ml_template template_indentation template hocc_block
let expand_ml_template template_indentation template
Spec.{algorithm; precs; symbols; prods; callbacks; states} formatter =
let expanders = Map.of_alist (module String) [
("«algorithm»", expand_ml_algorithm algorithm);
Expand All @@ -3692,7 +3692,7 @@ let expand_ml_template template_indentation template hocc_block
("«states»", expand_ml_states states);
("«tokens»", expand_ml_tokens symbols);
("«nonterms»", expand_ml_nonterms symbols);
("«callbacks»", expand_ml_callbacks hocc_block symbols callbacks);
("«callbacks»", expand_ml_callbacks symbols callbacks);
("«starts»", expand_ml_starts symbols states)
] in
formatter |> expand ~template_indentation template expanders
Expand Down Expand Up @@ -3725,7 +3725,7 @@ let generate_ml conf
end
| MatterEpsilon -> formatter
)
|> expand_ml_template indentation ml_template hocc_block spec
|> expand_ml_template indentation ml_template spec
|> (fun formatter ->
match postlude with
| Parse.Matter _ -> begin
Expand Down
Loading

0 comments on commit e877ac0

Please sign in to comment.