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

4
A parser-combinator-based parsing and compiling infrastructure for domain
5
specific languages (DSL) in Digital Humanities projects.
Eckhart Arnold's avatar
Eckhart Arnold committed
6
7
8
9
10
11
12
13

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


License
-------

14
15
DHParser is open source software under the [MIT License](https://opensource.org/licenses/MIT)

Eckhart Arnold's avatar
Eckhart Arnold committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Copyright 2016-2017  Eckhart Arnold, Bavarian Academy of Sciences and Humanities

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the 
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
 to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


38
**Exception**: The module ``DHParser/typing34.py`` was directly taken from the
Eckhart Arnold's avatar
Eckhart Arnold committed
39
Python 3.5 source code in order for DHParser to be backwards compatible
40
with Python 3.4. The module ``DHParser/typing34.py`` is licensed under the
Eckhart Arnold's avatar
Eckhart Arnold committed
41
42
43
44
45
46
[Python Software Foundation License Version 2](https://docs.python.org/3.5/license.html)


Sources
-------

47
Find the sources on [gitlab.lrz.de/badw-it/DHParser](https://gitlab.lrz.de/badw-it/DHParser) . 
Eckhart Arnold's avatar
Eckhart Arnold committed
48
49
50
Get them with:
    
    git clone https://gitlab.lrz.de/badw-it/DHParser
51

Eckhart Arnold's avatar
Eckhart Arnold committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Please contact me, if you are intested in contributing to the
development or just using DHParser.  


Disclaimer
----------

DHParser is still in an early development stage. While it is definitaly
usable, features may be dropped or added without notice and class or
function names changed in future versions. The API is NOT YET STABLE!

Use it for testing an evaluation, but not in an production environment
or contact me first, if you intend to do so.

66
67
68
69

Purpose
-------

70
71
72
73
74
75
DHParser 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
76
77
78
79
80
81
82
83
84
85
86
[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
87
88
generators out there, e.g. [Añez's grako parser generator][Añez_2017], 
[Eclipse XText][XText_Website]. However, DHParser is
89
90
intended as a tool that is specifically geared towards digital
humanities applications, while most existing parser generators come
91
92
93
94
95
96
97
98
99
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
100
101
influences some of its design decisions such as, for example, clearly
separating the parsing, syntax-tree-transformation and compilation
102
stages. Finally, DHParser is intended as a tool to experiment with.  One
103
104
105
106
107
108
109
110
111
112
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/)"!
113
114
115

Further (intended) use cases are:

116
117
118
119
120
121
122
* 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.)
123
124
125
* EBNF itself. DHParser is already self-hosting ;-)
* Digital and cross-media editions 
* Digital dictionaries
Eckhart Arnold's avatar
Eckhart Arnold committed
126

127
128
129
130
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
131
132
133
134
135
136
parsing process will be stored in a sub-directory named "LOG".


Introduction
------------

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

di68kap's avatar
di68kap committed
139

140
141
142
References
----------

143
144
Juancarlo Añez: grako, a PEG parser generator in Python, 2017. URL:
[bitbucket.org/apalala/grako][Añez_2017]
145

di68kap's avatar
di68kap committed
146
[Añez_2017]: https://bitbucket.org/apalala/grako
147
148


149
150
151
152
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
153
München 2016. Short-URL: [tiny.badw.de/2JVT][Arnold_2016]
154

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


158
159
160
Brian Ford: Parsing Expression Grammars: A Recognition-Based Syntactic
Foundation, Cambridge
Massachusetts, 2004. Short-URL:[http://t1p.de/jihs][Ford_2004]
161
162
163
164
165
166
167
168
169
170
171
172
173
174

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


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.


Dominikus Herzberg: Objekt-orientierte Parser-Kombinatoren in Python,
Blog-Post, September, 18th 2008 on denkspuren. gedanken, ideen,
175
176
anregungen und links rund um informatik-themen, short-URL:
[http://t1p.de/bm3k][Herzberg_2008a]
177
178
179
180
181
182

[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
183
184
links rund um informatik-themen, short-URL:
[http://t1p.de/7jzh][Herzberg_2008b]
185
186
187
188
189
190

[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
di68kap's avatar
di68kap committed
191
informatik-themen, short-URL: [http://t1p.de/s0zk][Herzberg_2007]
192
193
194
195
196
197
198

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


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


199
200
201
202
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]
203
204
205
206

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


207
208
209
210
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]
211
212
213

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

214
215
216
217
218
219
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.
[http://dslbook.org/][Voelter_2013]  

[voelter_2013]: http://dslbook.org/
220
221
222

[tex_stackexchange_no_bnf]: http://tex.stackexchange.com/questions/4201/is-there-a-bnf-grammar-of-the-tex-language
 
di68kap's avatar
di68kap committed
223
[tex_stackexchange_latex_parsers]: http://tex.stackexchange.com/questions/4223/what-parsers-for-latex-mathematics-exist-outside-of-the-tex-engines 
224
225

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