README.md 10.6 KB
Newer Older
1 2
DHParser
========
Eckhart Arnold's avatar
Eckhart Arnold committed
3

eckhart's avatar
eckhart committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
DHParser - The domian specific language (DSL) construction kit for the Digit Humanities


Features
--------

* 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!  
Eckhart Arnold's avatar
Eckhart Arnold committed
23 24 25 26 27


License
-------

28
DHParser is open source software under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
29

30
Copyright 2016-2018  Eckhart Arnold, Bavarian Academy of Sciences and Humanities
Eckhart Arnold's avatar
Eckhart Arnold committed
31

32 33 34
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
Eckhart Arnold's avatar
Eckhart Arnold committed
35

36
    https://www.apache.org/licenses/LICENSE-2.0e
Eckhart Arnold's avatar
Eckhart Arnold committed
37

38 39 40 41 42
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Eckhart Arnold's avatar
Eckhart Arnold committed
43

eckhart's avatar
eckhart committed
44 45 46 47 48 49 50

Author
------

Author: Eckhart Arnold, Bavarian Academy of Sciences
Email:  arnold@badw.de

51

52 53 54 55 56 57 58 59 60 61
Installation
------------

You can install DHParser from the Python package index (https://pypi.org)*:

    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).

eckhart's avatar
eckhart committed
62

63 64 65 66 67 68 69 70 71 72 73
Post-Installaton
----------------

It is recommended that you install the `regex`-module
(https://bitbucket.org/mrabarnett/mrab-regex). 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 `buildpackages.sh`-script (or `buildpackages.bat` on
Windows-systems) after installation. This script compiles the
di68kap's avatar
di68kap committed
74
`stringview.py`-module to C-Code with the cython Python to C compiler
75 76 77 78
(https://cython.org). This requires that you have cython and a
C-compiler installed on your system.


79 80 81
Sources
-------

82
Find the sources on [gitlab.lrz.de/badw-it/DHParser](https://gitlab.lrz.de/badw-it/DHParser) .
83
Get them with:
84

85
    git clone https://gitlab.lrz.de/badw-it/DHParser
86

87 88 89 90
There exists a mirror of this repository on github:
https://github.com/jecki/DHParser Be aware, though, that the github-mirror
may occasionally lag behind a few commits.

Eckhart Arnold's avatar
Eckhart Arnold committed
91
Please contact me, if you are intested in contributing to the
92
development or just using DHParser.
Eckhart Arnold's avatar
Eckhart Arnold committed
93

eckhart's avatar
eckhart committed
94

Eckhart Arnold's avatar
Eckhart Arnold committed
95 96 97
Disclaimer
----------

eckhart's avatar
eckhart committed
98 99 100
DHParser is still in development stage. While it is already quite mature, 
there may still be changes to the API.

Eckhart Arnold's avatar
Eckhart Arnold committed
101

102 103 104
Purpose
-------

eckhart's avatar
eckhart committed
105 106 107 108
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.
109

110
Domain specific languages are widespread in
111 112
computer sciences, but seem to be underused in the Digital Humanities.
While DSLs are sometimes introduced to Digital-Humanities-projects as
113 114 115 116 117 118 119 120 121 122 123
[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
124
generators out there, e.g. [Añez's grako parser generator][Añez_2017],
125
[Eclipse XText][XText_Website]. However, DHParser is
126 127
intended as a tool that is specifically geared towards digital
humanities applications, while most existing parser generators come
128 129
from compiler construction toolkits for programming languages.
While I expect DSLs in computer science and DSLs in the Digital
130
Humanities to be quite similar as far as the technological realization
131 132 133 134
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
135 136
DSL-construction toolkits in a different direction. Also,
DHParser shall (in the future) serve as a teaching tool, which
137 138
influences some of its design decisions such as, for example, clearly
separating the parsing, syntax-tree-transformation and compilation
139
stages. Finally, DHParser is intended as a tool to experiment with.  One
140 141 142 143 144 145 146 147 148 149
possible research area is, how non
[context-free grammars](https://en.wikipedia.org/wiki/Context-free_grammar)
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](http://www.mlw.badw.de/)"!
150 151 152

Further (intended) use cases are:

153 154 155 156 157 158 159
* 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-based-parsers.)
160
* EBNF itself. DHParser is already self-hosting ;-)
161
* XML-parser, just for the fun of it ;-)
162
* Digital and cross-media editions
163
* Digital dictionaries
Eckhart Arnold's avatar
Eckhart Arnold committed
164

165 166 167 168
For a simple self-test run `dhparser.py` 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
169 170
parsing process will be stored in a sub-directory named "LOG".

eckhart's avatar
eckhart committed
171

172 173 174
Introduction
------------

Eckhart Arnold's avatar
Eckhart Arnold committed
175
see [Introduction.md](https://gitlab.lrz.de/badw-it/DHParser/blob/master/Introduction.md)
Eckhart Arnold's avatar
Eckhart Arnold committed
176

eckhart's avatar
eckhart committed
177

178
References and Acknowledment
179 180
----------

181 182
Juancarlo Añez: grako, a PEG parser generator in Python, 2017. URL:
[bitbucket.org/apalala/grako][Añez_2017]
183

di68kap's avatar
di68kap committed
184
[Añez_2017]: https://bitbucket.org/apalala/grako
185 186


187 188 189 190
Eckhart Arnold: Domänenspezifische Notationen. Eine (noch)
unterschätzte Technologie in den Digitalen Geisteswissenschaften,
Präsentation auf dem
[dhmuc-Workshop: Digitale Editionen und Auszeichnungssprachen](https://dhmuc.hypotheses.org/workshop-digitale-editionen-und-auszeichnungssprachen),
di68kap's avatar
di68kap committed
191
München 2016. Short-URL: [tiny.badw.de/2JVT][Arnold_2016]
192

di68kap's avatar
di68kap committed
193
[Arnold_2016]: https://f.hypotheses.org/wp-content/blogs.dir/1856/files/2016/12/EA_Pr%C3%A4sentation_Auszeichnungssprachen.pdf
194

195 196
Brian Ford: Parsing Expression Grammars: A Recognition-Based Syntactic
Foundation, Cambridge
197
Massachusetts, 2004. Short-URL:[t1p.de/jihs][Ford_2004]
198 199 200

[Ford_2004]: https://pdos.csail.mit.edu/~baford/packrat/popl04/peg-popl04.pdf

201
[Ford_20XX]: http://bford.info/packrat/
202 203 204 205 206 207

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.

208 209 210 211 212 213
Elizabeth Scott and Adrian Johnstone, GLL Parsing,
in: Electronic Notes in Theoretical Computer Science 253 (2010) 177–189,
[dotat.at/tmp/gll.pdf][scott_johnstone_2010]

[scott_johnstone_2010]: http://dotat.at/tmp/gll.pdf

214 215
Dominikus Herzberg: Objekt-orientierte Parser-Kombinatoren in Python,
Blog-Post, September, 18th 2008 on denkspuren. gedanken, ideen,
216
anregungen und links rund um informatik-themen, short-URL:
217
[t1p.de/bm3k][Herzberg_2008a]
218 219 220 221 222

[Herzberg_2008a]: http://denkspuren.blogspot.de/2008/09/objekt-orientierte-parser-kombinatoren.html

Dominikus Herzberg: Eine einfache Grammatik für LaTeX, Blog-Post,
September, 18th 2008 on denkspuren. gedanken, ideen, anregungen und
223
links rund um informatik-themen, short-URL:
224
[t1p.de/7jzh][Herzberg_2008b]
225 226 227 228 229

[Herzberg_2008b]: http://denkspuren.blogspot.de/2008/09/eine-einfache-grammatik-fr-latex.html

Dominikus Herzberg: Uniform Syntax, Blog-Post, February, 27th 2007 on
denkspuren. gedanken, ideen, anregungen und links rund um
230
informatik-themen, short-URL: [t1p.de/s0zk][Herzberg_2007]
231 232 233 234 235

[Herzberg_2007]: http://denkspuren.blogspot.de/2007/02/uniform-syntax.html

[ISO_IEC_14977]: http://www.cl.cam.ac.uk/~mgk25/iso-14977.pdf

236 237 238 239
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. [commonmark.org][MacFarlane_et_al_2017]
240 241 242

[MacFarlane_et_al_2017]: http://commonmark.org/

243 244 245 246
Stefan Müller: DSLs in den digitalen Geisteswissenschaften,
Präsentation auf dem
[dhmuc-Workshop: Digitale Editionen und Auszeichnungssprachen](https://dhmuc.hypotheses.org/workshop-digitale-editionen-und-auszeichnungssprachen),
München 2016. Short-URL: [tiny.badw.de/2JVy][Müller_2016]
247 248 249

[Müller_2016]: https://f.hypotheses.org/wp-content/blogs.dir/1856/files/2016/12/Mueller_Anzeichnung_10_Vortrag_M%C3%BCnchen.pdf

250 251
Markus Voelter, Sbastian Benz, Christian Dietrich, Birgit Engelmann,
Mats Helander, Lennart Kats, Eelco Visser, Guido Wachsmuth:
252
DSL Engineering. Designing, Implementing and Using Domain-Specific Languages, 2013.
253 254 255 256 257 258 259 260 261 262 263 264
[dslbook.org/][Voelter_2013]

Christopher Seaton: A Programming Language Where the Syntax and Semantics
are Mutuable at Runtime, University of Bristol 2007,
[chrisseaton.com/katahdin/katahdin.pdf][seaton_2007]

Vegard Øye: General Parser Combinators in Racket, 2012,
[epsil.github.io/gll/][vegard_2012]

[vegard_2012]: https://epsil.github.io/gll/ 

[seaton_2007]: http://chrisseaton.com/katahdin/katahdin.pdf
265 266

[voelter_2013]: http://dslbook.org/
267 268

[tex_stackexchange_no_bnf]: http://tex.stackexchange.com/questions/4201/is-there-a-bnf-grammar-of-the-tex-language
269 270

[tex_stackexchange_latex_parsers]: http://tex.stackexchange.com/questions/4223/what-parsers-for-latex-mathematics-exist-outside-of-the-tex-engines
271 272

[XText_website]: https://www.eclipse.org/Xtext/