Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

DHParser - Domain specific languages for the Digital Humanities

Project description


DHParser - The domian specific language (DSL) construction kit for the Digit Humanities


* Very beginner-friendly *Python-based* DSL construction kit. Setup, program and
test your own DSL with the widely used Python language.

* Specific focus on *XML-workflows* as these are the most common in the Digital
Humanities. Other output formats are of course also possible. (For example,
DHParser is self-hosting and uses Python-Code as output format.)

* Supports *unit-testing of grammars* and piecewise step-by-step development
as well as debugging of grammars.

* *Customizable parsing errors and error recovery* to make it easy to locate
parsing errors at the right spot and deliver them with a meaningful error
message for users that do not habitually deal with formal notations!


DHParser is open source software under the [Apache 2.0 License](

Copyright 2016-2019 Eckhart Arnold, Bavarian Academy of Sciences and Humanities

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.


Author: Eckhart Arnold, Bavarian Academy of Sciences


You can install DHParser from the Python package index (*:

python -m pip install --user --upgrade DHParser

However, as the software is still in an early beta stage, it is
recommended that you pull it directly from gitlab (see below).


It is recommended that you install the `regex`-module
( If present, DHParser
will use `regex` instead of the built-in `re`-module for regular
expressions. `regex` is faster and more powerful than `re`.

In order to speed up DHParser even more, it is recommended that you
run the ``-script (or `buildpackages.bat` on
Windows-systems) after installation. This script compiles the
``-module to C-Code with the cython Python to C compiler
( This requires that you have cython and a
C-compiler installed on your system.


Find the sources on []( .
Get them with:

git clone

There exists a mirror of this repository on github: Be aware, though, that the github-mirror
may occasionally lag behind a few commits.

Please contact me, if you are intested in contributing to the
development or just using DHParser.


DHParser is still in development stage. While it is already quite mature,
there may still be changes to the API.


DHParser is a parser-combinator-based parsing and compiling
infrastructure for domain specific languages (DSL) in Digital
Humanities projects. It leverages the power of Domain specific
languages for the Digital Humanities.

Domain specific languages are widespread in
computer sciences, but seem to be underused in the Digital Humanities.
While DSLs are sometimes introduced to Digital-Humanities-projects as
[practical adhoc-solution][Müller_2016], these solutions are often
somewhat "quick and dirty". In other words they are more of a hack
than a technology. The purpose of DHParser is to introduce
[DSLs as a technology][Arnold_2016] to the Digital Humanities. It is
based on the well known technology of [EBNF][ISO_IEC_14977]-based
parser generators, but employs the more modern form called
"[parsing expression grammar][Ford_2004]" and
[parser combinators][Ford_20XX] as a variant of the classical
recursive descent parser.

Why another parser generator? There are plenty of good parser
generators out there, e.g. [Añez's grako parser generator][Añez_2017],
[Eclipse XText][XText_Website]. However, DHParser is
intended as a tool that is specifically geared towards digital
humanities applications, while most existing parser generators come
from compiler construction toolkits for programming languages.
While I expect DSLs in computer science and DSLs in the Digital
Humanities to be quite similar as far as the technological realization
is concerned, the use cases, requirements and challenges are somewhat
different. For example, in the humanities annotating text is a central
use case, which is mostly absent in computer science treatments.
These differences might sooner or later require to develop the
DSL-construction toolkits in a different direction. Also,
DHParser shall (in the future) serve as a teaching tool, which
influences some of its design decisions such as, for example, clearly
separating the parsing, syntax-tree-transformation and compilation
stages. Finally, DHParser is intended as a tool to experiment with. One
possible research area is, how non
[context-free grammars](
such as the grammars of [TeX][tex_stackexchange_no_bnf] or
[CommonMark][MacFarlane_et_al_2017] can be described with declarative
langauges in the spirit of but beyond EBNF, and what extensions of the
parsing technology are necessary to capture such languages.

Primary use case at the Bavarian Academy of Sciences and Humanities
(for the time being): A DSL for the
"[Mittellateinische Wörterbuch]("!

Further (intended) use cases are:

* LaTeX -> XML/HTML conversion. See this
[discussion on why an EBNF-parser for the complete TeX/LaTeX-grammar][tex_stackexchange_no_bnf]
is not possible.
* [CommonMark][MacFarlane_et_al_2017] and other DSLs for cross media
publishing of scientific literature, e.g. journal articles. (Common
Mark and Markdown also go beyond what is feasible with pure
* EBNF itself. DHParser is already self-hosting ;-)
* XML-parser, just for the fun of it ;-)
* Digital and cross-media editions
* Digital dictionaries

For a simple self-test run `` from the command line. This
compiles the EBNF-Grammer in `examples/EBNF/EBNF.ebnf` and outputs the
Python-based parser class representing that grammar. The concrete and
abstract syntax tree as well as a full and abbreviated log of the
parsing process will be stored in a sub-directory named "LOG".


See []( for the
motivation and an overview how DHParser works or jump right into the
[Step by Step Guide]( to
learn how to setup and use DHParser.

References and Acknowledment

Juancarlo Añez: grako, a PEG parser generator in Python, 2017. URL:


Eckhart Arnold: Domänenspezifische Notationen. Eine (noch)
unterschätzte Technologie in den Digitalen Geisteswissenschaften,
Präsentation auf dem
[dhmuc-Workshop: Digitale Editionen und Auszeichnungssprachen](,
München 2016. Short-URL: [][Arnold_2016]


Brian Ford: Parsing Expression Grammars: A Recognition-Based Syntactic
Foundation, Cambridge
Massachusetts, 2004. Short-URL:[][Ford_2004]



Richard A. Frost, Rahmatullah Hafiz and Paul Callaghan: Parser
Combinators for Ambiguous Left-Recursive Grammars, in: P. Hudak and
D.S. Warren (Eds.): PADL 2008, LNCS 4902, pp. 167–181, Springer-Verlag
Berlin Heidelberg 2008.

Elizabeth Scott and Adrian Johnstone, GLL Parsing,
in: Electronic Notes in Theoretical Computer Science 253 (2010) 177–189,


Dominikus Herzberg: Objekt-orientierte Parser-Kombinatoren in Python,
Blog-Post, September, 18th 2008 on denkspuren. gedanken, ideen,
anregungen und links rund um informatik-themen, short-URL:


Dominikus Herzberg: Eine einfache Grammatik für LaTeX, Blog-Post,
September, 18th 2008 on denkspuren. gedanken, ideen, anregungen und
links rund um informatik-themen, short-URL:


Dominikus Herzberg: Uniform Syntax, Blog-Post, February, 27th 2007 on
denkspuren. gedanken, ideen, anregungen und links rund um
informatik-themen, short-URL: [][Herzberg_2007]



John MacFarlane, David Greenspan, Vicent Marti, Neil Williams,
Benjamin Dumke-von der Ehe, Jeff Atwood: CommonMark. A strongly
defined, highly compatible specification of
Markdown, 2017. [][MacFarlane_et_al_2017]


Stefan Müller: DSLs in den digitalen Geisteswissenschaften,
Präsentation auf dem
[dhmuc-Workshop: Digitale Editionen und Auszeichnungssprachen](,
München 2016. Short-URL: [][Müller_2016]


Markus Voelter, Sbastian Benz, Christian Dietrich, Birgit Engelmann,
Mats Helander, Lennart Kats, Eelco Visser, Guido Wachsmuth:
DSL Engineering. Designing, Implementing and Using Domain-Specific Languages, 2013.

Christopher Seaton: A Programming Language Where the Syntax and Semantics
are Mutuable at Runtime, University of Bristol 2007,

Vegard Øye: General Parser Combinators in Racket, 2012,







Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
DHParser-0.8.9.tar.gz (587.2 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page