Files
pgn_to_tex/lib/internal/parsing.ml
T
owenrees 548f98f303 feat: add public Pgn_to_tex entry point
Move parsing and rendering internals into the private
pgn_to_tex_internal library and rename pgn2tex to converter. Expose only
Pgn_to_tex with default to_tex arguments, abstract diagram_data,
empty_diagrams, and parse_diagrams_json. Update tests, JS bridge, and
README to the new names.
2026-10-23 16:38:24 +02:00

31 lines
739 B
OCaml

open Ast
let in_header = ref false
let next_token buf =
if !in_header then
let tok = Lexer.tokenize_header buf in
match tok with
| Parser.TAG_CLOSE ->
in_header := false;
Parser.TAG_CLOSE
| _ -> tok
else
let tok = Lexer.tokenize_game buf in
match tok with
| Parser.TAG_OPEN ->
in_header := true;
Parser.TAG_OPEN
| _ -> tok
let parse_pgn s =
let buf = Sedlexing.Utf8.from_string s in
in_header := false;
let provider () =
let tok = next_token buf in
let start_pos, end_pos = Sedlexing.lexing_positions buf in
(tok, start_pos, end_pos)
in
try MenhirLib.Convert.Simplified.traditional2revised Parser.main provider
with _ -> failwith "Parse error"