File: generate_parser

package info (click to toggle)
jruby 9.4.8.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 89,244 kB
  • sloc: ruby: 548,574; java: 276,189; yacc: 25,873; ansic: 6,178; xml: 6,111; sh: 1,855; sed: 94; makefile: 78; jsp: 48; tcl: 40; exp: 12
file content (93 lines) | stat: -rwxr-xr-x 2,594 bytes parent folder | download | duplicates (2)
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
#!/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

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

popd