Skip to content

Repository files navigation

Yuho

Domain-specific language for encoding statutes as executable bytes.

Release PyPI License: MIT Python 3.10+

Paper  ·  Docs  ·  Status matrix  ·  Encoded library

What is Yuho?

Yuho is a formally verified domain-specific language dedicated to simplifying legalese by providing a programmatic representation of Singapore Law.

Current applications are focused on Singapore Criminal Law but really can be applied to any jurisdiction that relies on statutes.

For Language Nerds

In specific, Yuho mainly comprises a statute DSL compiler that transpiles .yh statute encodings (specified in Yuho's grammer spec) into a typed AST.

This means you can run syntax, semantic and lint checks on .yh code.

Yuho also additionally emits reviewable artefacts in JSON, Plaintext English, $LaTeX$, Mermaid, Alloy, DOCX, Akoma Ntoso, and LegalRuleML.

Current Capabilities

Note

See the feature status matrix for stable, partial, experimental and presently unsupported surfaces.

General

Surface Capability
Grammar Tree-sitter grammar for statute blocks, structs, functions, tests, imports, cross-section predicates, penalty combinators, and exception priority
Analysis yuho check, yuho lint, formatting, AST visualization, source diagnostics
Transpilers JSON, English, LaTeX, Mermaid, Alloy, DOCX, Akoma Ntoso, LegalRuleML
Verification Z3/Alloy backends via yuho verify, plus Lean structural-diff checks
Corpus tools AKN round-trip, runtime test sweep, reference graph via yuho refs
Corpora library/penal_code Singapore canonical corpus, library/bharatiya_nyaya_sanhita BNS 2023 replacement corpus for IPC, library/indian_penal_code raw IPC snapshot, library/malaysia_penal_code and library/pakistan_penal_code IPC-lineage proof-of-concept corpora

Encoded statues

One of my gripes with most Legal DSLs presently available (in the current year 2024) are their lack of examples of the DSL actually in use or application.

With this specific trauma in mind, Yuho provides a thoroughly encoded corpus of all 524 sections of the Singapore Penal Code 1871 are encoded at library/penal_code/.

Installation

PyPI

The easiest way to get started with Yuho is via PyPI installation from the CLI.

$ uv tool install 'yuho[dev]'
$ yuho doctor
$ yuho init yuho-starter

Direct GitHub Repo

Alternatively run the below.

$ git clone https://github.com/gongahkia/yuho && cd yuho
$ ./install.sh --dev

Usage

The below instructions are for locally using and running Yuho.

$ uv venv --python 3.13 .venv
$ source .venv/bin/activate
$ uv pip install -e '.[dev]'
$ yuho doctor
$ yuho --help
$ yuho doctor
$ yuho init yuho-starter
$ yuho check library/penal_code/s415_cheating/statute.yh
$ yuho lint library/penal_code/s415_cheating/statute.yh
$ yuho ast library/penal_code/s415_cheating/statute.yh --stats --depth 3
$ yuho verify --capabilities

Shell Completion

Yuho optionally provides shell completion for most popular shells.

$ yuho completion zsh --install
$ yuho completion bash --install
$ yuho completion fish --install

Documentation

Paper

You can find my paper Yuho: A Domain-Specific Language for Encoding the Singapore Penal Code as Executable Statute published on Zenodo here.

Citation

If you use Yuho or its encoded library in academic work, cite the below.

@software{yuho_2026,
  author  = {Gabriel Ong Zhe Mian},
  title   = {Yuho: A Domain-Specific Language for Encoding the Singapore Penal Code as Executable Statute},
  year    = {2026},
  url     = {https://github.com/gongahkia/yuho},
  version = {5.1.0}
}

Contribute

Yuho is open-source. Contribution guidelines are found at CONTRIBUTING.md.

References

Analogues

Yuho takes much inspiration from the following projects.

  • Natural L4: Language with an English-like syntax that transpiles to multiple targets, focused on codification of Singapore law at large and Contract Law in specific.
  • Catala: Language syntax that explicitly mimicks logical structure of the Law, focused on general Socio-fiscal legislature in most jurisidictions.
  • Blawx: User-friendly web-based tool for Rules as Code, a declarative logic knowledge representation tool for encoding, testing and using rules.
  • Morphir: Technology agnostic toolkit for digitisation of business models and their underlying decision logic, enabling automation in fintech.
  • OpenFisca: Open-source platform for modelling social policies through tax and benefits systems across jurisdictions.
  • Docassemble: Document automation system for generating guided interview documents through a question-and-answer interface.
  • Akoma Ntoso: Standardised XML schema for representing parliamentary, legislative and judiciary documents across jurisdictions.

Research

Yuho stands on the shoulders of past research and academia.

About

DSL for SG Criminal Law

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages