1UNAME_S := $(shell uname -s) 2ifeq ($(UNAME_S),Linux) 3 PYTHON ?= ../../python 4endif 5ifeq ($(UNAME_S),Darwin) 6 PYTHON ?= ../../python.exe 7endif 8VENVDIR ?= ./venv 9VENVPYTHON ?= $(VENVDIR)/bin/python 10CPYTHON ?= ../../Lib 11MYPY ?= mypy 12 13GRAMMAR = ../../Grammar/python.gram 14TOKENS = ../../Grammar/Tokens 15TESTFILE = data/cprog.py 16TIMEFILE = data/xxl.py 17TESTDIR = . 18TESTFLAGS = --short 19 20data/xxl.py: 21 $(PYTHON) -m zipfile -e data/xxl.zip data 22 23build: peg_extension/parse.c 24 25peg_extension/parse.c: $(GRAMMAR) $(TOKENS) pegen/*.py peg_extension/peg_extension.c ../../Parser/pegen/pegen.c ../../Parser/pegen/parse_string.c ../../Parser/pegen/*.h pegen/grammar_parser.py 26 $(PYTHON) -m pegen -q c $(GRAMMAR) $(TOKENS) -o peg_extension/parse.c --compile-extension 27 28clean: 29 -rm -f peg_extension/*.o peg_extension/*.so peg_extension/parse.c 30 -rm -f data/xxl.py 31 -rm -rf $(VENVDIR) 32 33dump: peg_extension/parse.c 34 cat -n $(TESTFILE) 35 $(PYTHON) -c "from peg_extension import parse; import ast; t = parse.parse_file('$(TESTFILE)', mode=1); print(ast.dump(t))" 36 37regen-metaparser: pegen/metagrammar.gram pegen/*.py 38 $(PYTHON) -m pegen -q python pegen/metagrammar.gram -o pegen/grammar_parser.py 39 40# Note: These targets really depend on the generated shared object in peg_extension/parse.*.so but 41# this has different names in different systems so we are abusing the implicit dependency on 42# parse.c by the use of --compile-extension. 43 44.PHONY: test 45 46venv: 47 $(PYTHON) -m venv $(VENVDIR) 48 $(VENVPYTHON) -m pip install -U pip setuptools 49 $(VENVPYTHON) -m pip install -r requirements.pip 50 @echo "The venv has been created in the $(VENVDIR) directory" 51 52test: run 53 54run: peg_extension/parse.c 55 $(PYTHON) -c "from peg_extension import parse; t = parse.parse_file('$(TESTFILE)'); exec(t)" 56 57compile: peg_extension/parse.c 58 $(PYTHON) -c "from peg_extension import parse; t = parse.parse_file('$(TESTFILE)', mode=2)" 59 60parse: peg_extension/parse.c 61 $(PYTHON) -c "from peg_extension import parse; t = parse.parse_file('$(TESTFILE)', mode=1)" 62 63check: peg_extension/parse.c 64 $(PYTHON) -c "from peg_extension import parse; t = parse.parse_file('$(TESTFILE)', mode=0)" 65 66stats: peg_extension/parse.c data/xxl.py 67 $(PYTHON) -c "from peg_extension import parse; t = parse.parse_file('$(TIMEFILE)', mode=0); parse.dump_memo_stats()" >@data 68 $(PYTHON) scripts/joinstats.py @data 69 70time: time_compile 71 72time_compile: venv data/xxl.py 73 $(VENVPYTHON) scripts/benchmark.py --parser=new --target=xxl compile 74 75time_parse: venv data/xxl.py 76 $(VENVPYTHON) scripts/benchmark.py --parser=new --target=xxl parse 77 78time_old: time_old_compile 79 80time_old_compile: venv data/xxl.py 81 $(VENVPYTHON) scripts/benchmark.py --parser=old --target=xxl compile 82 83time_old_parse: venv data/xxl.py 84 $(VENVPYTHON) scripts/benchmark.py --parser=old --target=xxl parse 85 86time_peg_dir: venv 87 $(VENVPYTHON) scripts/test_parse_directory.py \ 88 -d $(TESTDIR) \ 89 $(TESTFLAGS) \ 90 --exclude "*/failset/*" \ 91 --exclude "*/failset/**" \ 92 --exclude "*/failset/**/*" 93 94time_stdlib: $(CPYTHON) venv 95 $(VENVPYTHON) scripts/test_parse_directory.py \ 96 -d $(CPYTHON) \ 97 $(TESTFLAGS) \ 98 --exclude "*/bad*" \ 99 --exclude "*/lib2to3/tests/data/*" 100 101mypy: regen-metaparser 102 $(MYPY) # For list of files, see mypy.ini 103 104format-python: 105 black pegen scripts 106 107format: format-python 108 109find_max_nesting: 110 $(PYTHON) scripts/find_max_nesting.py 111 112tags: TAGS 113 114TAGS: pegen/*.py test/test_pegen.py 115 etags pegen/*.py test/test_pegen.py 116