opal-racc 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +1 -0
- data/lib/opal/racc/parser.rb +159 -0
- metadata +47 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.DS_Store
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Racc runtime for Opal
|
@@ -0,0 +1,159 @@
|
|
1
|
+
# Opal port of racc/parser.rb.
|
2
|
+
#
|
3
|
+
# Original license:
|
4
|
+
#
|
5
|
+
# $originalId: parser.rb,v 1.8 2006/07/06 11:42:07 aamine Exp $
|
6
|
+
#
|
7
|
+
# Copyright (c) 1999-2006 Minero Aoki
|
8
|
+
#
|
9
|
+
# This program is free software.
|
10
|
+
# You can distribute/modify this program under the same terms of ruby.
|
11
|
+
#
|
12
|
+
# As a special exception, when this code is copied by Racc
|
13
|
+
# into a Racc output file, you may use that output file
|
14
|
+
# without restriction.
|
15
|
+
module Racc
|
16
|
+
|
17
|
+
class Parser
|
18
|
+
|
19
|
+
def _racc_setup
|
20
|
+
Racc_arg
|
21
|
+
end
|
22
|
+
|
23
|
+
def do_parse
|
24
|
+
_racc_do_parse_rb _racc_setup, false
|
25
|
+
end
|
26
|
+
|
27
|
+
def _racc_do_parse_rb(arg, in_debug)
|
28
|
+
action_table = arg[0]
|
29
|
+
action_check = arg[1]
|
30
|
+
action_default = arg[2]
|
31
|
+
action_pointer = arg[3]
|
32
|
+
|
33
|
+
goto_table = arg[4]
|
34
|
+
goto_check = arg[5]
|
35
|
+
goto_default = arg[6]
|
36
|
+
goto_pointer = arg[7]
|
37
|
+
|
38
|
+
nt_base = arg[8]
|
39
|
+
reduce_table = arg[9]
|
40
|
+
token_table = arg[10]
|
41
|
+
shift_n = arg[11]
|
42
|
+
reduce_n = arg[12]
|
43
|
+
|
44
|
+
use_result = arg[13]
|
45
|
+
|
46
|
+
# racc sys vars
|
47
|
+
racc_state = [0]
|
48
|
+
racc_tstack = []
|
49
|
+
racc_vstack = []
|
50
|
+
|
51
|
+
racc_t = nil
|
52
|
+
racc_tok = nil
|
53
|
+
racc_val = nil
|
54
|
+
racc_read_next = true
|
55
|
+
|
56
|
+
racc_user_yyerror = false
|
57
|
+
racc_error_status = 0
|
58
|
+
|
59
|
+
token = nil; act = nil; i = nil; nerr = nil; custate = nil
|
60
|
+
|
61
|
+
while true
|
62
|
+
i = action_pointer[racc_state[-1]]
|
63
|
+
|
64
|
+
if i
|
65
|
+
if racc_read_next
|
66
|
+
if racc_t != 0 # not EOF
|
67
|
+
token = next_token
|
68
|
+
|
69
|
+
racc_tok = token[0]
|
70
|
+
racc_val = token[1]
|
71
|
+
|
72
|
+
if racc_tok == false # EOF
|
73
|
+
racc_t = 0
|
74
|
+
else
|
75
|
+
racc_t = token_table[racc_tok]
|
76
|
+
racc_t = 1 unless racc_t
|
77
|
+
# racc_t ||= 1
|
78
|
+
end
|
79
|
+
|
80
|
+
racc_read_next = false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
i += racc_t
|
85
|
+
|
86
|
+
if (i < 0) || (act = action_table[i]).nil? || (action_check[i] != racc_state[-1])
|
87
|
+
act = action_default[racc_state[-1]]
|
88
|
+
end
|
89
|
+
|
90
|
+
else
|
91
|
+
act = action_default[racc_state[-1]]
|
92
|
+
end
|
93
|
+
|
94
|
+
if act > 0 && act < shift_n
|
95
|
+
if racc_error_status > 0
|
96
|
+
if racc_t != 1
|
97
|
+
racc_error_status -= 1
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
racc_vstack.push racc_val
|
102
|
+
curstate = act
|
103
|
+
racc_state << act
|
104
|
+
racc_read_next = true
|
105
|
+
|
106
|
+
elsif act < 0 && act > -reduce_n
|
107
|
+
reduce_i = act * -3
|
108
|
+
reduce_len = reduce_table[reduce_i]
|
109
|
+
reduce_to = reduce_table[reduce_i + 1]
|
110
|
+
method_id = reduce_table[reduce_i + 2]
|
111
|
+
|
112
|
+
tmp_v = racc_vstack.last reduce_len
|
113
|
+
|
114
|
+
racc_state.pop reduce_len
|
115
|
+
racc_vstack.pop reduce_len
|
116
|
+
racc_tstack.pop reduce_len
|
117
|
+
|
118
|
+
if use_result
|
119
|
+
reduce_call_result = self.__send__ method_id, tmp_v, nil, tmp_v[0]
|
120
|
+
racc_vstack.push reduce_call_result
|
121
|
+
else
|
122
|
+
raise "not using result??"
|
123
|
+
end
|
124
|
+
|
125
|
+
racc_tstack.push reduce_to
|
126
|
+
|
127
|
+
k1 = reduce_to - nt_base
|
128
|
+
|
129
|
+
if (reduce_i = goto_pointer[k1]) != nil
|
130
|
+
reduce_i += racc_state[-1]
|
131
|
+
|
132
|
+
if (reduce_i >= 0) && ((curstate = goto_table[reduce_i]) != nil) && (goto_check[reduce_i] == k1)
|
133
|
+
racc_state.push curstate
|
134
|
+
else
|
135
|
+
racc_state.push goto_default[k1]
|
136
|
+
end
|
137
|
+
|
138
|
+
else
|
139
|
+
racc_state.push goto_default[k1]
|
140
|
+
end
|
141
|
+
|
142
|
+
elsif act == shift_n
|
143
|
+
# action
|
144
|
+
return racc_vstack[0]
|
145
|
+
|
146
|
+
elsif act == -reduce_n
|
147
|
+
# reduce
|
148
|
+
raise "Opal Syntax Error: unexpected '#{racc_tok.inspect}'"
|
149
|
+
|
150
|
+
else
|
151
|
+
raise "Rac: unknown action: #{act}"
|
152
|
+
end
|
153
|
+
|
154
|
+
# raise "and finished loop"
|
155
|
+
end
|
156
|
+
end # _racc_do_parse_rb
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opal-racc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adam Beynon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-22 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Opal compatible racc runtime
|
15
|
+
email: adam@adambeynon.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- README.md
|
22
|
+
- lib/opal/racc/parser.rb
|
23
|
+
homepage: http://opalrb.org
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.11
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: Opal compatible racc runtime
|
47
|
+
test_files: []
|