Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
badw-it
DHParser
Commits
dd505977
Commit
dd505977
authored
Jun 09, 2017
by
di68kap
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- examples/Tutorial: Lyrik.ebnf tested and fixed
parent
c1b3846f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
23 deletions
+20
-23
DHParser/dsl.py
DHParser/dsl.py
+3
-2
DHParser/parsers.py
DHParser/parsers.py
+2
-1
examples/Tutorial/Lyrik.ebnf
examples/Tutorial/Lyrik.ebnf
+2
-2
examples/Tutorial/LyrikCompiler.py
examples/Tutorial/LyrikCompiler.py
+13
-18
No files found.
DHParser/dsl.py
View file @
dd505977
...
...
@@ -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
()
...
...
DHParser/parsers.py
View file @
dd505977
...
...
@@ -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
)
...
...
examples/Tutorial/Lyrik.ebnf
View file @
dd505977
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 }+
...
...
examples/Tutorial/LyrikCompiler.py
View file @
dd505977
...
...
@@ -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
,
One
OrMore
(
LEERZEILE
)))
text
=
OneOrMore
(
Sequence
(
strophe
,
Zero
OrMore
(
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
#
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment