compile_MLW-entry.py 1.43 KB
Newer Older
1
2
#!/usr/bin/python3

3
4
"""compile_MLW-entry.py - simple utility script for compiling a sample 
                          MLW entry
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

Author: Eckhart Arnold <arnold@badw.de>

Copyright 2017 Bavarian Academy of Sciences and Humanities

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

    http://www.apache.org/licenses/LICENSE-2.0

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

import os
import sys
Eckhart Arnold's avatar
Eckhart Arnold committed
25
sys.path.append(os.path.abspath('../../../'))
di68kap's avatar
di68kap committed
26
27
import DHParser.toolkit as toolkit
from DHParser.ebnf import grammar_changed
28
from DHParser.dsl import compile_on_disk
29
30

MLW_ebnf = os.path.join('..', 'MLW.ebnf')
31
MLW_compiler = os.path.join('..', 'MLWCompiler.py')
32

di68kap's avatar
di68kap committed
33
# print(grammar_changed(MLW_ebnf, MLW_compiler))
34
35

if (not os.path.exists(MLW_compiler) or
36
    grammar_changed(MLW_compiler, MLW_ebnf)):
37
    print("recompiling parser")
38
    errors = compile_on_disk(MLW_ebnf)
39
    if errors:
di68kap's avatar
di68kap committed
40
        print('\n'.join(errors))
41
42
        sys.exit(1)

Eckhart Arnold's avatar
Eckhart Arnold committed
43
with toolkit.logging():
44
    errors = compile_on_disk("fascitergula.mlw", MLW_compiler, ".sxpr")
45
if errors:
di68kap's avatar
di68kap committed
46
    print('\n'.join(errors))
47
    sys.exit(1)