Commit dd505977 authored by di68kap's avatar di68kap
Browse files

- examples/Tutorial: Lyrik.ebnf tested and fixed

parent c1b3846f
......@@ -397,8 +397,9 @@ def compile_on_disk(source_file, compiler_suite="", extension=".xml"):
except (PermissionError, FileNotFoundError, IOError) as error:
intro, imports, scanner, parser, ast, compiler, outro = '', '', '', '', '', '', ''
except ValueError as error:
raise ValueError('File "' + rootname + 'Compiler.py" seems to be corrupted. '
'Please delete or repair file manually!')
name = '"' + rootname + 'Compiler.py"'
raise ValueError('Could not identify all required sections in ' + name +
'. Please delete or repair ' + name + ' manually!')
finally:
if f:
f.close()
......
......@@ -164,7 +164,8 @@ def add_parser_guard(parser_func):
node, rest = parser_func(parser, text)
if grammar.history_tracking:
if grammar.moving_forward or (node and node._errors): # and result[0] == None
# don't track returning parsers except in case an error has occurred
if grammar.moving_forward or (node and node._errors):
grammar.moving_forward = False
record = HistoryRecord(grammar.call_stack.copy(), node, len(rest))
grammar.history.append(record)
......
gedicht = bibliographisches { LEERZEILE }+ [serie] §titel §text §ENDE
gedicht = bibliographisches { LEERZEILE }+ [serie] §titel §text /\s*/ §ENDE
bibliographisches = autor §"," [NZ] werk §"," [NZ] ort §"," [NZ] jahr §"."
autor = namenfolge [verknüpfung]
......@@ -11,7 +11,7 @@ serie = !(titel vers NZ vers) { NZ zeile }+ { LEERZEILE }+
titel = NZ zeile { LEERZEILE }+
zeile = { ZEICHENFOLGE }+
text = { strophe {LEERZEILE}+ }+
text = { strophe {LEERZEILE} }+
strophe = { NZ vers }+
vers = { ZEICHENFOLGE }+
......
......@@ -17,7 +17,8 @@ except ImportError:
import re
from DHParser.toolkit import logging, is_filename
from DHParser.parsers import Grammar, CompilerBase, Required, Token, \
Optional, OneOrMore, Sequence, RE, NegativeLookahead, mixin_comment, compile_source
Optional, OneOrMore, ZeroOrMore, Sequence, RE, NegativeLookahead, \
mixin_comment, compile_source
from DHParser.syntaxtree import traverse, no_operation
......@@ -44,7 +45,7 @@ def get_scanner():
class LyrikGrammar(Grammar):
r"""Parser for a Lyrik source file, with this grammar:
gedicht = bibliographisches { LEERZEILE }+ [serie] §titel §text
gedicht = bibliographisches { LEERZEILE }+ [serie] §titel §text /\s*/ §ENDE
bibliographisches = autor §"," [NZ] werk §"," [NZ] ort §"," [NZ] jahr §"."
autor = namenfolge [verknüpfung]
......@@ -54,10 +55,10 @@ class LyrikGrammar(Grammar):
jahr = JAHRESZAHL
serie = !(titel vers NZ vers) { NZ zeile }+ { LEERZEILE }+
titel = NZ zeile
titel = NZ zeile { LEERZEILE }+
zeile = { ZEICHENFOLGE }+
text = { strophe {LEERZEILE}+ }+
text = { strophe {LEERZEILE} }+
strophe = { NZ vers }+
vers = { ZEICHENFOLGE }+
......@@ -75,7 +76,7 @@ class LyrikGrammar(Grammar):
JAHRESZAHL = /\d\d\d\d/~
ENDE = !/./
"""
source_hash__ = "6718329094e23c5285d3bed5b2861c10"
source_hash__ = "28d8514ebe2ab4ebc985f22b7fa968d4"
parser_initialization__ = "upon instatiation"
COMMENT__ = r''
WSP__ = mixin_comment(whitespace=r'[\t ]*', comment=r'')
......@@ -95,22 +96,19 @@ class LyrikGrammar(Grammar):
wortfolge = OneOrMore(WORT)
vers = OneOrMore(ZEICHENFOLGE)
strophe = OneOrMore(Sequence(NZ, vers))
text = OneOrMore(Sequence(strophe, OneOrMore(LEERZEILE)))
text = OneOrMore(Sequence(strophe, ZeroOrMore(LEERZEILE)))
zeile = OneOrMore(ZEICHENFOLGE)
titel = Sequence(NZ, zeile)
serie = Sequence(NegativeLookahead(Sequence(titel, vers, NZ, vers)), OneOrMore(Sequence(NZ, zeile)),
OneOrMore(LEERZEILE))
titel = Sequence(NZ, zeile, OneOrMore(LEERZEILE))
serie = Sequence(NegativeLookahead(Sequence(titel, vers, NZ, vers)), OneOrMore(Sequence(NZ, zeile)), OneOrMore(LEERZEILE))
jahr = JAHRESZAHL
ort = Sequence(wortfolge, Optional(verknüpfung))
untertitel = Sequence(wortfolge, Optional(verknüpfung))
werk = Sequence(wortfolge, Optional(Sequence(Token("."), Required(untertitel))), Optional(verknüpfung))
autor = Sequence(namenfolge, Optional(verknüpfung))
bibliographisches = Sequence(autor, Required(Token(",")), Optional(NZ), werk, Required(Token(",")), Optional(NZ),
ort, Required(Token(",")), Optional(NZ), jahr, Required(Token(".")))
gedicht = Sequence(bibliographisches, OneOrMore(LEERZEILE), Optional(serie), Required(titel), Required(text))
bibliographisches = Sequence(autor, Required(Token(",")), Optional(NZ), werk, Required(Token(",")), Optional(NZ), ort, Required(Token(",")), Optional(NZ), jahr, Required(Token(".")))
gedicht = Sequence(bibliographisches, OneOrMore(LEERZEILE), Optional(serie), Required(titel), Required(text), RE('\\s*', wR=''), Required(ENDE))
root__ = gedicht
def get_grammar():
global thread_local_Lyrik_grammar_singleton
try:
......@@ -265,10 +263,7 @@ def get_compiler(grammar_name="Lyrik", grammar_source=""):
LyrikCompiler(grammar_name, grammar_source)
return thread_local_Lyrik_compiler_singleton
#######################################################################
#######################################################################
#
# END OF DHPARSER-SECTIONS
#
......
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