package sqlgg

  1. Overview
  2. Docs
SQL Guided (code) Generator

Install

dune-project
 Dependency

Authors

Maintainers

Sources

sqlgg-20260721.tbz
sha256=40d7699187951dd2f17d885c4f4f04124930bf7dc1119d4cca322c5f0cb42d8e
sha512=e7c90683cddcff3ca0ba9de9e40c2c4c69923ea62e2647f1a70083e42ed00b7cab53f8a14d1a965ee4465966bc02fa75fa7cb42e485beae1a9c26bdc252c3665

doc/src/sqlgg.lib/parser_state.ml.html

Source file parser_state.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

type mode = Normal | Ignore | Ident
let mode = ref Normal
let mode_normal () = mode := Normal
let mode_ignore () = mode := Ignore
let mode_ident () = mode := Ident
module Stmt_metadata = struct
  let stmt_metadata: (int, (string * string) list) Hashtbl.t = Hashtbl.create 16

  let add k v = Hashtbl.add stmt_metadata k v
  let find_all k = Hashtbl.find_all stmt_metadata k
  let reset () = Hashtbl.reset stmt_metadata
end

let current_lexbuf : Lexing.lexbuf option ref = ref None

let with_lexbuf lexbuf f =
  let saved = !current_lexbuf in
  current_lexbuf := Some lexbuf;
  Fun.protect f ~finally:(fun () -> current_lexbuf := saved)

let extract_source (start_, end_) =
  Stdlib.Option.bind !current_lexbuf (fun lexbuf ->
    let len = end_ - start_ in
    if len > 0 && start_ >= 0 && end_ <= lexbuf.Lexing.lex_buffer_len then
      Some (Bytes.sub_string lexbuf.lex_buffer start_ len)
    else
      None)