A key-value store in Rust
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add script to generate noblit.h from docs

I have the declaraions in the docs anyway. Rather than trying to
generate docs from source, we can extract the "source" from the docs.
We can also compile that file with GCC as a basic sanity check. This
transitively ensures that the docs make sense.

+75 -10
+7
.gitignore
··· 14 14 15 15 # Built documentation. 16 16 /site 17 + 18 + # Generated C header and precompiled C header. 19 + noblit.h 20 + noblit.h.gch 21 + 22 + # Prove state (so it can run failed tests first). 23 + .prove
+5
.travis.yml
··· 62 62 - mypy --strict golden 63 63 - mypy --strict libnoblit 64 64 65 + # Generate the C header, then compile it to a precompiled header with GCC. 66 + # This acts as a basic sanity check on the documentation. 67 + - libnoblit/gen_header.py > noblit.h 68 + - gcc noblit.h 69 + 65 70 # Check the goldens. 66 71 - prove --exec golden/run.py golden 67 72
+1
default.nix
··· 4 4 pkgs.buildEnv { 5 5 name = "noblit-devenv"; 6 6 paths = [ 7 + pkgs.gcc # For checking the generated C header. 7 8 pkgs.mkdocs # For building documentation. 8 9 pkgs.mypy # For typechecking the Python code. 9 10 pkgs.perl # The "prove" test harness is part of Perl.
+62
libnoblit/gen_header.py
··· 1 + #!/usr/bin/env python3 2 + 3 + # Noblit -- An immutable append-only database 4 + # Copyright 2020 Ruud van Asseldonk 5 + 6 + # Licensed under the Apache License, Version 2.0 (the "License"); 7 + # you may not use this file except in compliance with the License. 8 + # A copy of the License has been included in the root of the repository. 9 + 10 + """ 11 + Extract the noblit.h C header from the API reference. 12 + """ 13 + 14 + from typing import Iterable, List 15 + 16 + 17 + def extract_decls(lines: Iterable[str]) -> Iterable[str]: 18 + """ 19 + Extract C declarations from code blocks in a markdown file. 20 + """ 21 + declaration: List[str] = [] 22 + 23 + for line in lines: 24 + # Four-space indented code blocks must be preceded by a blank line. 25 + if line.strip() == '': 26 + declaration = [] 27 + 28 + # Include content from code blocks, and join multiple lines, until the 29 + # semicolon terminator. 30 + if line.startswith(' '): 31 + declaration.append(line.strip()) 32 + 33 + if ';' in line: 34 + yield ' '.join(declaration) 35 + 36 + 37 + def get_decls_from_docs() -> List[str]: 38 + """ 39 + Extract declarations from the C API reference. 40 + """ 41 + with open('docs/reference/c.md', 'r', encoding='utf-8') as f: 42 + return list(extract_decls(f)) 43 + 44 + 45 + def main() -> None: 46 + print('#ifndef _NOBLIT_H_') 47 + print('#define _NOBLIT_H_') 48 + print( 49 + '\n/* This file was generated from docs/reference/c.md ' 50 + 'by libnoblit/gen_header.py. */\n' 51 + ) 52 + print('#include <stddef.h>') 53 + print('#include <stdint.h>\n') 54 + 55 + for decl in get_decls_from_docs(): 56 + print(decl) 57 + 58 + print('\n#endif') 59 + 60 + 61 + if __name__ == '__main__': 62 + main()
-10
libnoblit/noblit.h
··· 1 - #ifndef _NOBLIT_H_ 2 - #define _NOBLIT_H_ 3 - 4 - /* This file was generated from docs/reference/c.md by libnoblit/gen_header.py. */ 5 - 6 - typedef struct Noblit noblit_t; 7 - noblit_t* noblit_db_read_packed(uint8_t const* fname, size_t fname_len); 8 - void noblit_db_free(noblit_t* db); 9 - 10 - #endif