haml_parser 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2018bdc583b86d3e184e4f98d1ac356d41641ef7
4
- data.tar.gz: ce85adf4d59e27557bfa16670094a771be76d6bd
3
+ metadata.gz: 57fa4126042491041d5f4331f41515d43c83a589
4
+ data.tar.gz: 56cbec56b038d88ea9f624fb8f77e8d802adb0cc
5
5
  SHA512:
6
- metadata.gz: adf34f95177de3d6cedc65536405fe387b5b9ff10ffd9b7a3fc21344731d692253468629ddc87aa2b2d536163462e71e3323f529710f402fd05375e9cef98b28
7
- data.tar.gz: 5cee1370ebfa90524568fec5948549b7cbd890872eb6a538ba7c5825e5d12450859ff5b3547da54d94fb31e7d3cad29570fefbc7b9fa192269135c49a89db75a
6
+ metadata.gz: a959f007b23c072abf2521e3ad6a7ea6684b5dec4cd975cea09030fa43dcbded2505827c2c82f9fbe808e3dea0ae1c6a8d03388c126fdaaaf9357e730a670112
7
+ data.tar.gz: 72ec32afa7ee002abde26b19538ae2429d04afe55fe4d60b9bcf04155e8ff8486c545ad9d5a5375f657100d6597eb775f590d0baabe935dbb940abbe287a9e3e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.3.0 (2015-11-16)
2
+ - Add support for object reference syntax
3
+ - Fix attribute parser for empty braces or parens
4
+
1
5
  # 0.2.0 (2015-11-15)
2
6
  - Remove `Ast::SilentScript#mid_block_keyword` attribute
3
7
  - Add `Ast::Script#keyword` and `Ast::SilentScript#keyword` attribute
@@ -39,6 +39,7 @@ module HamlParser
39
39
  :self_closing,
40
40
  :nuke_inner_whitespace,
41
41
  :nuke_outer_whitespace,
42
+ :object_ref,
42
43
  :filename,
43
44
  :lineno,
44
45
  ) do
@@ -26,7 +26,7 @@ module HamlParser
26
26
  element.static_class, element.static_id = parse_class_and_id(m[2])
27
27
  rest = m[3] || ''
28
28
 
29
- element.attributes, rest = parse_attributes(rest)
29
+ element.attributes, element.object_ref, rest = parse_attributes(rest)
30
30
  element.nuke_inner_whitespace, element.nuke_outer_whitespace, rest = parse_nuke_whitespace(rest)
31
31
  element.self_closing, rest = parse_self_closing(rest)
32
32
  element.oneline_child = ScriptParser.new(@line_parser).parse(rest)
@@ -57,37 +57,44 @@ module HamlParser
57
57
 
58
58
  OLD_ATTRIBUTE_BEGIN = '{'
59
59
  NEW_ATTRIBUTE_BEGIN = '('
60
+ OBJECT_REF_BEGIN = '['
60
61
 
61
62
  def parse_attributes(rest)
62
- old_attributes = ''
63
- new_attributes = ''
63
+ old_attributes = nil
64
+ new_attributes = nil
65
+ object_ref = nil
64
66
 
65
67
  loop do
66
68
  case rest[0]
67
69
  when OLD_ATTRIBUTE_BEGIN
68
- unless old_attributes.empty?
70
+ if old_attributes
69
71
  break
70
72
  end
71
73
  old_attributes, rest = parse_old_attributes(rest)
72
74
  when NEW_ATTRIBUTE_BEGIN
73
- unless new_attributes.empty?
75
+ if new_attributes
74
76
  break
75
77
  end
76
78
  new_attributes, rest = parse_new_attributes(rest)
79
+ when OBJECT_REF_BEGIN
80
+ if object_ref
81
+ break
82
+ end
83
+ object_ref, rest = parse_object_ref(rest)
77
84
  else
78
85
  break
79
86
  end
80
87
  end
81
88
 
82
- attributes = old_attributes
83
- unless new_attributes.empty?
89
+ attributes = old_attributes || ''
90
+ if new_attributes
84
91
  if attributes.empty?
85
92
  attributes = new_attributes
86
93
  else
87
94
  attributes << ', ' << new_attributes
88
95
  end
89
96
  end
90
- [attributes, rest]
97
+ [attributes, object_ref, rest]
91
98
  end
92
99
 
93
100
  def parse_old_attributes(text)
@@ -204,6 +211,17 @@ module HamlParser
204
211
  end
205
212
  end
206
213
 
214
+ def parse_object_ref(text)
215
+ s = StringScanner.new(text)
216
+ s.pos = 1
217
+ depth = Utils.balance(s, '[', ']')
218
+ if depth == 0
219
+ [s.pre_match[1, s.pre_match.size - 1], s.rest]
220
+ else
221
+ syntax_error!('Unmatched brackets for object reference')
222
+ end
223
+ end
224
+
207
225
  def parse_nuke_whitespace(rest)
208
226
  m = rest.match(/\A(><|<>|[><])(.*)\z/)
209
227
  if m
@@ -1,3 +1,3 @@
1
1
  module HamlParser
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-15 00:00:00.000000000 Z
11
+ date: 2015-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips