Skip to content

Commit

Permalink
[tools/find] Automation to build the 'find' grammar.
Browse files Browse the repository at this point in the history
Not used yet.

Addresses issue #85.
  • Loading branch information
Andy Chu committed Jun 7, 2019
1 parent 74182c7 commit 16ed985
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 7 additions & 2 deletions build/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,21 @@ minimal() {
asdl/run.sh gen-typed-arith-asdl

# Needed on Travis.
grammar
oil-grammar
find-grammar

pylibc
line-input
}

grammar() {
oil-grammar() {
oil_lang/grammar_gen.py marshal oil_lang/grammar.pgen2 _devbuild/gen
}

find-grammar() {
oil_lang/grammar_gen.py marshal tools/find/find.pgen2 _devbuild/gen
}

# Prerequisites: build/codegen.sh {download,install}-re2c
all() {
minimal
Expand Down
11 changes: 9 additions & 2 deletions oil_lang/grammar_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,21 @@ def main(argv):
grammar_path = argv[0]
out_dir = argv[1]

basename, _ = os.path.splitext(os.path.basename(grammar_path))

# HACK for find:
if basename == 'find':
from tools.find import parse as find_parse
tok_def = find_parse.TokenDef()

with open(grammar_path) as f:
gr = pgen.MakeGrammar(f, tok_def=tok_def)

marshal_path = os.path.join(out_dir, 'grammar.marshal')
marshal_path = os.path.join(out_dir, basename + '.marshal')
with open(marshal_path, 'wb') as out_f:
gr.dump(out_f)

nonterm_path = os.path.join(out_dir, 'grammar_nt.py')
nonterm_path = os.path.join(out_dir, basename + '_nt.py')
with open(nonterm_path, 'w') as out_f:
gr.dump_nonterminals(out_f)

Expand Down
Empty file added tools/find/__init__.py
Empty file.

0 comments on commit 16ed985

Please sign in to comment.