parser 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 126ed67c12d5d057262636b6c422560a131e5163
4
- data.tar.gz: b1e624ccb5d937b3655ac97cd281a75dd3d94bc1
3
+ metadata.gz: f90753aea951ab24c817278f94b4e1844151e496
4
+ data.tar.gz: 49a0cd6eb5dbf0fec9900f1d927ac20bdd8b90fd
5
5
  SHA512:
6
- metadata.gz: c2b4262dbce1ca86cbce53800a164ec23c71c976191421978500c6b58151e026716b7975916ac1b7b5fac5b72061f7ea3872e02cc4ed3adc39cd91f2df769e64
7
- data.tar.gz: 730b931cdb766441f165778ce4bf2def697298ebdda55e7d3d1d96c5f26d0a703f6345c4ee26cdaf22acd1bf41d2b059162fb91dd350714693866d724e9524b9
6
+ metadata.gz: 01192b4d7d2b63f8348b2af97b567796f5aedfbb6562843dfce4590f1b15479997693e2b3d688ad3969d542ead2e4ab69389e6b5060da9f0b332ac165ee73c40
7
+ data.tar.gz: fdcbb3072c1c66d2d1ab3f54eb05f595eeab30860f9b59b5d1e472dc3ae681fdf3cb9376b2fd0945ef97cbabfb10a4f1959b4231ba9e0b8c9ee426625b5a14b5
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ tmp
19
19
  lib/parser/lexer.rb
20
20
  lib/parser/ruby18.rb
21
21
  lib/parser/ruby19.rb
22
+ lib/parser/ruby20.rb
data/Rakefile CHANGED
@@ -13,7 +13,8 @@ task :build => :generate_release
13
13
 
14
14
  GENERATED_FILES = %w(lib/parser/lexer.rb
15
15
  lib/parser/ruby18.rb
16
- lib/parser/ruby19.rb)
16
+ lib/parser/ruby19.rb
17
+ lib/parser/ruby20.rb)
17
18
 
18
19
  CLEAN.include(GENERATED_FILES)
19
20
 
data/TODO.md ADDED
@@ -0,0 +1,20 @@
1
+ # 2.0
2
+
3
+ 1. test for "** interpreted as argument prefix" diagnostic
4
+ 6. https://github.com/ruby/ruby/commit/c46bda
5
+ 7. https://github.com/ruby/ruby/commit/1ab3974b0efea5155da005ec08a1feee90023d98
6
+ 9. https://github.com/ruby/ruby/commit/d6a977f667f9d824cfe95976f3afc31e55580edb
7
+ 10. https://github.com/ruby/ruby/commit/8fe3fb4c0f69535b302e124f3afc58dce4be5dbb
8
+ 11. https://github.com/ruby/ruby/commit/3380974143d3fdf1721d9e28d6b2d42036f03bd2
9
+
10
+ # 2.1
11
+
12
+ 1. https://github.com/ruby/ruby/commit/7ea675732ac1dac72f07756498706678d8725719
13
+ 2. https://github.com/ruby/ruby/commit/38da1a5398f146a36910fde34b72dc9b3aa7918f
14
+ 3. https://github.com/ruby/ruby/commit/e489dc1ff42ad3027319d7d01f4885164fdb410a
15
+ 4. https://github.com/ruby/ruby/commit/c07d78eb0e8e9d3a8f9e8c860b362964157ff43a
16
+ 5. https://github.com/ruby/ruby/commit/34a95669dad8843e3e9a4af683682ab2f50856dd
17
+
18
+ # All versions
19
+
20
+ 1. https://github.com/ruby/ruby/commit/9150340b9bcbe305c2647a8d6f6f8e754769f3e7
data/bin/explain-parse CHANGED
@@ -11,4 +11,4 @@ class Parser::Base
11
11
  end
12
12
  end
13
13
 
14
- Parser::Ruby18.parse(ARGF.read)
14
+ p Parser::Ruby20.parse(ARGF.read)
data/lib/parser/all.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'parser/ruby18'
2
2
  require 'parser/ruby19'
3
+ require 'parser/ruby20'
@@ -91,10 +91,34 @@ module Parser
91
91
  end
92
92
  end
93
93
 
94
+ def word(parts)
95
+ if parts.one?
96
+ parts.first
97
+ else
98
+ s(:dstr, *parts)
99
+ end
100
+ end
101
+
94
102
  def words_compose(begin_t, parts, end_t)
95
103
  s(:array, *parts)
96
104
  end
97
105
 
106
+ def symbols_compose(begin_t, parts, end_t)
107
+ parts = parts.map do |part|
108
+ case part.type
109
+ when :str
110
+ value, = *part
111
+ part.updated(:sym, [ value.to_sym ])
112
+ when :dstr
113
+ part.updated(:dsym)
114
+ else
115
+ part
116
+ end
117
+ end
118
+
119
+ s(:array, *parts)
120
+ end
121
+
98
122
  # Hashes
99
123
 
100
124
  def pair(key, assoc_t, value)
@@ -133,7 +157,11 @@ module Parser
133
157
  #
134
158
 
135
159
  def parenthesize(begin_t, expr, end_t)
136
- expr
160
+ if expr.nil?
161
+ s(:nil)
162
+ else
163
+ expr
164
+ end
137
165
  end
138
166
 
139
167
  #
@@ -511,7 +539,7 @@ module Parser
511
539
  # Logical operations: and, or
512
540
 
513
541
  def logical_op(type, lhs, token, rhs)
514
- s(type, lhs, rhs)
542
+ s(type, check_condition(lhs), check_condition(rhs))
515
543
  end
516
544
 
517
545
  # Conditionals
@@ -5,25 +5,28 @@ module Parser
5
5
  MONOLITHIC = { :tSTRING_BEG => :tSTRING, :tSYMBEG => :tSYMBOL }
6
6
 
7
7
  TYPES = {
8
- # type start token interpolate?
9
- "'" => [ :tSTRING_BEG, false ],
10
- '%q' => [ :tSTRING_BEG, false ],
11
- '"' => [ :tSTRING_BEG, true ],
12
- '%' => [ :tSTRING_BEG, true ],
13
- '%Q' => [ :tSTRING_BEG, true ],
8
+ # type start token interpolate?
9
+ "'" => [ :tSTRING_BEG, false ],
10
+ '%q' => [ :tSTRING_BEG, false ],
11
+ '"' => [ :tSTRING_BEG, true ],
12
+ '%' => [ :tSTRING_BEG, true ],
13
+ '%Q' => [ :tSTRING_BEG, true ],
14
14
 
15
- '%w' => [ :tQWORDS_BEG, false ],
16
- '%W' => [ :tWORDS_BEG, true ],
15
+ '%w' => [ :tQWORDS_BEG, false ],
16
+ '%W' => [ :tWORDS_BEG, true ],
17
17
 
18
- ":'" => [ :tSYMBEG, false ],
19
- '%s' => [ :tSYMBEG, false ],
20
- ':"' => [ :tSYMBEG, true ],
18
+ '%i' => [ :tQSYMBOLS_BEG, false ],
19
+ '%I' => [ :tSYMBOLS_BEG, true ],
21
20
 
22
- '/' => [ :tREGEXP_BEG, true ],
23
- '%r' => [ :tREGEXP_BEG, true ],
21
+ ":'" => [ :tSYMBEG, false ],
22
+ '%s' => [ :tSYMBEG, false ],
23
+ ':"' => [ :tSYMBEG, true ],
24
24
 
25
- '%x' => [ :tXSTRING_BEG, true ],
26
- '`' => [ :tXSTRING_BEG, true ],
25
+ '/' => [ :tREGEXP_BEG, true ],
26
+ '%r' => [ :tREGEXP_BEG, true ],
27
+
28
+ '%x' => [ :tXSTRING_BEG, true ],
29
+ '`' => [ :tXSTRING_BEG, true ],
27
30
  }
28
31
 
29
32
  attr_reader :heredoc_e, :str_s
@@ -57,6 +60,8 @@ module Parser
57
60
 
58
61
  @interp_braces = 0
59
62
 
63
+ @space_emitted = true
64
+
60
65
  # Monolithic strings are glued into a single token, e.g.
61
66
  # tSTRING_BEG tSTRING_CONTENT tSTRING_END -> tSTRING.
62
67
  @monolithic = (
@@ -77,7 +82,8 @@ module Parser
77
82
  end
78
83
 
79
84
  def words?
80
- type == :tWORDS_BEG || type == :tQWORDS_BEG
85
+ type == :tWORDS_BEG || type == :tQWORDS_BEG ||
86
+ type == :tSYMBOLS_BEG || type == :tQSYMBOLS_BEG
81
87
  end
82
88
 
83
89
  def regexp?
@@ -117,6 +123,10 @@ module Parser
117
123
 
118
124
  # Finalize if last matching delimiter is closed.
119
125
  if @nesting == 0
126
+ if words?
127
+ extend_space(ts, ts)
128
+ end
129
+
120
130
  # Emit the string as a single token if it's applicable.
121
131
  if @monolithic
122
132
  emit(MONOLITHIC[@start_tok], @buffer, @str_s, te)
@@ -160,13 +170,24 @@ module Parser
160
170
  unless @buffer.empty?
161
171
  emit(:tSTRING_CONTENT, @buffer, @buffer_s, @buffer_e)
162
172
 
163
- if words?
164
- emit(:tSPACE, nil, @buffer_e, @buffer_e + 1)
165
- end
166
-
167
173
  @buffer = ''
168
174
  @buffer_s = nil
169
175
  @buffer_e = nil
176
+ extend_content
177
+ end
178
+ end
179
+
180
+ def extend_content
181
+ @space_emitted = false
182
+ end
183
+
184
+ def extend_space(ts, te)
185
+ flush_string
186
+
187
+ unless @space_emitted
188
+ emit(:tSPACE, nil, ts, te)
189
+
190
+ @space_emitted = true
170
191
  end
171
192
  end
172
193
 
@@ -3,6 +3,10 @@ module Parser
3
3
  class Lexer::StackState
4
4
  def initialize(name)
5
5
  @name = name.freeze
6
+ clear
7
+ end
8
+
9
+ def clear
6
10
  @stack = 0
7
11
  end
8
12