compile_PopRetrieve_EBNF.py 1.67 KB
Newer Older
1 2
#!/usr/bin/python3

3 4
"""compile_PopRetrieve.py - test of Pop and Retrieve operators 
                             
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

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
sys.path.append(os.path.abspath('../../'))
26
from DHParser.DSLsupport import run_compiler, source_changed
27 28

if (not os.path.exists('PopRetrieve_compiler.py') or
Eckhart Arnold's avatar
Eckhart Arnold committed
29
    source_changed('PopRetrieve.ebnf', 'PopRetrieve_compiler.py')):
30
    print("recompiling parser")
31 32 33 34 35
    errors = run_compiler("PopRetrieve.ebnf")
    if errors:
        print(errors)
        sys.exit(1)

36 37 38
from PopRetrieve_compiler import compile_PopRetrieve

result, errors, ast = compile_PopRetrieve("PopRetrieveTest.txt")
39 40 41
if errors:
    print(errors)
    sys.exit(1)
42 43
else:
    print(result)
Eckhart Arnold's avatar
Eckhart Arnold committed
44

45
result, errors, ast = compile_PopRetrieve("PopRetrieveTest2.txt")
Eckhart Arnold's avatar
Eckhart Arnold committed
46 47
if errors:
    print(errors)
48
    sys.exit(1)
49 50 51 52 53 54 55 56 57 58 59 60 61
else:
    print(result)


# errors = run_compiler("PopRetrieveTest.txt", 'PopRetrieve_compiler.py')
# if errors:
#     print(errors)
#     sys.exit(1)
#
# errors = run_compiler("PopRetrieveTest2.txt", 'PopRetrieve_compiler.py')
# if errors:
#     print(errors)
#     sys.exit(1)