Commit e0512e77 authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

- code reorganization, bug fixes, further tests

parent 0cf9ea37
......@@ -21,7 +21,6 @@ Module ``DSLsupport`` contains various functions to support the
compilation of domain specific languages based on an EBNF-grammar.
"""
from functools import partial
import collections
import os
try:
......
......@@ -240,6 +240,7 @@ class EBNFCompiler(CompilerBase):
if 'right' in self.directives['literalws'] else "''"))
definitions.append(('wspL__', WHITESPACE_KEYWORD
if 'left' in self.directives['literalws'] else "''"))
print(self.directives) ####
definitions.append((WHITESPACE_KEYWORD,
("mixin_comment(whitespace="
"r'{whitespace}', comment=r'{comment}')").
......
......@@ -368,17 +368,6 @@ def error_messages(text, errors):
for err in sorted(list(errors)))
def compact_sexpr(s):
"""Returns S-expression ``s`` as a one liner without unnecessary
whitespace.
Example:
>>> compact_sexpr("(a\n (b\n c\n )\n)\n")
(a (b c))
"""
return re.sub('\s(?=\))', '', re.sub('\s+', ' ', s)).strip()
########################################################################
#
# syntax tree transformation functions
......
......@@ -118,6 +118,17 @@ def line_col(text, pos):
return line, column
def compact_sexpr(s):
"""Returns S-expression ``s`` as a one liner without unnecessary
whitespace.
Example:
>>> compact_sexpr("(a\n (b\n c\n )\n)\n")
(a (b c))
"""
return re.sub('\s(?=\))', '', re.sub('\s+', ' ', s)).strip()
def escape_re(s):
"""Returns `s` with all regular expression special characters escaped.
"""
......
DHParser
========
A parser combinator based parsing and compiling infrastructure for domain
A parser-combinator-based parsing and compiling infrastructure for domain
specific languages (DSL) in Digital Humanities projects.
Author: Eckhart Arnold, Bavarian Academy of Sciences
......@@ -32,8 +32,8 @@ parser generators, but employs the more modern form called
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]. However, DHParser is
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. Also,
......@@ -157,3 +157,5 @@ München 2016. Short-URL: [tiny.badw.de/2JVy][Müller_2016]
[tex_stackexchange_no_bnf]: http://tex.stackexchange.com/questions/4201/is-there-a-bnf-grammar-of-the-tex-language
[tex_stackexchange_latex_parsers]: http://tex.stackexchange.com/questions/4223/what-parsers-for-latex-mathematics-exist-outside-of-the-tex-engines
[XText_website]: https://www.eclipse.org/Xtext/
EBNF
====
This directory contains one or more variants of grammars for the Extended
Backus-Naur-Form (EBNF). The file named 'EBNF.ebnf' should always be the grammar
for the stock EBNF-compiler of `ParserCombinators`.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment