-
-
Notifications
You must be signed in to change notification settings - Fork 943
Expand file tree
/
Copy pathgenerate_parser
More file actions
executable file
·95 lines (73 loc) · 2.63 KB
/
generate_parser
File metadata and controls
executable file
·95 lines (73 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
# Run from your JRuby home directory....More smarts needed here.
#
# PATH=$PATH:<path to jay executable> tool/generate_parser
#
# jay is available from https://github.com/jruby/jay
#
# BUILD_DEBUG env set to anything will not remove the parse.y files
# generated so you can look at those files (line: comments in final
# source point back at these files).
###### Change these to tastes ######
JAY=jay
RUBY=${RUBY:=ruby}
PARSER_BASE=RubyParser
YYTABLE_PREFIX=
DEBUG=true
###### Do not change below ######
if [ "$1" != "" ]; then
PARSER_BASE=$1
shift
fi
if [ "$1" != "" ]; then
YYTABLE_PREFIX=$1
fi
if [ "$DEBUG" != "" ]; then
DEBUG_FLAG=-t
# Nonesense...my script-fu is weak
DEBUG_STRIP="xdyhbk"
else
DEBUG_FLAG=
DEBUG_STRIP="^//t"
fi
echo "Generating Parser '$PARSER_BASE' w/ YYTable prefix of '$YYTABLE_PREFIX'"
JAVA_SRC=core/src/main/java
PROJECT_ROOT=../../../../../../..
TOOL_DIR=${PROJECT_ROOT}/tool
PARSER_DIR=$JAVA_SRC/org/jruby/parser
RIPPER_DIR=${PROJECT_ROOT}/$JAVA_SRC/org/jruby/ext/ripper
pushd $PARSER_DIR
if [ "$SKIP_PARSER" == "" ]; then
echo "processing parser"
$RUBY $TOOL_DIR/preprocess_parser.rb < $PARSER_BASE.y > parse.y
# Generate grammar as intermediate file
echo "generating parser using jay"
$JAY $DEBUG_FLAG parse.y < skeleton.parser | grep -v $DEBUG_STRIP > $PARSER_BASE.out
echo "patching parser"
$RUBY $TOOL_DIR/patch_parser.rb $PARSER_BASE.out $YYTABLE_PREFIX $PARSER_BASE.y > $PARSER_BASE.out2
echo "optimizing parser"
$RUBY $TOOL_DIR/optimize_parser.rb $PARSER_BASE.out2 $YYTABLE_PREFIX > $PARSER_BASE.java
rm -f $PARSER_BASE.out $PARSER_BASE.out2
if [ "$BUILD_DEBUG" == "" ]; then
rm -f parse.y
fi
fi
if [ "$SKIP_RIPPER" == "" ]; then
echo "processing ripper"
$RUBY $TOOL_DIR/preprocess_parser.rb ripper < $PARSER_BASE.y > $RIPPER_DIR/ripper_parse.y
cd $RIPPER_DIR
echo "in ripper dir ${PWD}"
echo "applying ripper DSL"
$RUBY ../$TOOL_DIR/preproc_ripper.rb ripper_parse.y > ripper_$PARSER_BASE.out
echo "generating ripper using jay"
$JAY $DEBUG_FLAG ripper_$PARSER_BASE.out < ../../parser/skeleton.parser | grep -v $DEBUG_STR#IP > ripper_$PARSER_BASE.out2
echo "patching ripper"
$RUBY ../$TOOL_DIR/patch_parser.rb ripper_$PARSER_BASE.out2 $YYTABLE_PREFIX ripper_$PARSER_BASE.out > ripper_$PARSER_BASE.out3
echo "optimizing ripper"
$RUBY ../$TOOL_DIR/optimize_parser.rb ripper_$PARSER_BASE.out3 $YYTABLE_PREFIX > RipperParser.java
if [ "$BUILD_DEBUG" == "" ]; then
rm -f ripper_$PARSER_BASE.out ripper_$PARSER_BASE.out2 ripper_$PARSER_BASE.out3
rm -f ripper_parse.y
fi
fi
popd