lua-literal 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: 07f66fc9b4403eb46e870cf8c10f2e5276ccc91cfeb1a97c107143942875d34e
4
- data.tar.gz: 5d844615dd7ab5dc9c217a60376875a2311111cc505612de16e2adc77e0dd0dd
3
+ metadata.gz: e5df06fe05cd5b78ae6c72d85127073b0b5d15d114ba6075274c4be7dd68a539
4
+ data.tar.gz: 49736a59edd2c6e17d2ffdb19f4c820f9ac285e24c60aab0ec34273c62b239b0
5
5
  SHA512:
6
- metadata.gz: 023a3ed726e61843bc68a7d21df59cfed1162c9942ba884cc66b2fc9467327294702e09a6725edb3f6ba24f20fa08cf9d0e5c046e3eeaccdb3a642e29e467e7f
7
- data.tar.gz: 597cf6e0a42df7a3ac9695abd8218a73052119988ec624b68667a71cfa130c0e0902d0b57278e1d294779d6011951d3fad08f8337f7e3c960e3926101b1f5e2a
6
+ metadata.gz: e3c317cd3e3a2e5d8dd5d6fd276548ed37fb53f69934e13f06e8773f2f77891045323546fdadca52b29c0f8ea58bdfaabf8d43f1b12c588a3a3dc87d9537ce33
7
+ data.tar.gz: 745b110958417e590c5ff4942654d271d44c11b3b5edcfb38312401504c06a665730d8098ec7999ff4de003d70bf59609b71b797216adb633b7607303538d215
@@ -14,6 +14,9 @@ AllCops:
14
14
  TargetRubyVersion: 2.7
15
15
  UseCache: true
16
16
 
17
+ Layout/EmptyLineAfterGuardClause:
18
+ Enabled: true
19
+
17
20
  Layout/EmptyLineAfterMagicComment:
18
21
  Enabled: true
19
22
 
@@ -95,6 +98,7 @@ Style/MethodCallWithArgsParentheses:
95
98
  Enabled: true
96
99
  IgnoredMethods:
97
100
  # language core
101
+ - raise
98
102
  - require
99
103
  - require_relative
100
104
  # gem/bundler
@@ -0,0 +1,9 @@
1
+ # ChangeLog
2
+
3
+ ## 0.2.0
4
+
5
+ - Support string concatenation
6
+
7
+ ## 0.1.0
8
+
9
+ - Initial release
data/README.md CHANGED
@@ -60,6 +60,10 @@ Lua's tables are converted to Ruby's `Hash`.
60
60
 
61
61
  Short comments are recognized and removed.
62
62
 
63
+ ### String concatenation
64
+
65
+ This is not strictly a literal expression but supported for convenience.
66
+
63
67
  ## Unsupported literals
64
68
 
65
69
  * Hexadecimal numerals.
@@ -8,5 +8,6 @@ require 'lua/literal/transform'
8
8
  module Lua
9
9
  module Literal
10
10
  class Error < StandardError; end
11
+ class ParseError < Error; end
11
12
  end
12
13
  end
@@ -10,12 +10,12 @@ module Lua
10
10
 
11
11
  # table_constructor ::= '{' [fieldlist] '}'
12
12
  rule(:table_constructor) {
13
- (str('{') >> space? >> fieldlist.maybe >> space? >> str('}')).as(:table)
13
+ (str('{') >> space? >> fieldlist.maybe.as(:table) >> space? >> str('}'))
14
14
  }
15
15
 
16
16
  # fieldlist ::= field {fieldsep field} [fieldsep]
17
17
  rule(:fieldlist) {
18
- (field >> space? >> (fieldsep >> space? >> field).repeat).as(:fields) >> space? >> fieldsep.maybe
18
+ field >> space? >> (fieldsep >> space? >> field).repeat >> space? >> fieldsep.maybe
19
19
  }
20
20
 
21
21
  # field ::= '[' exp ']' '=' exp | Name '=' exp | exp
@@ -44,14 +44,19 @@ module Lua
44
44
  space? >>
45
45
  (
46
46
  table_constructor |
47
- literal_nil |
48
- literal_false |
49
- literal_true |
50
- numeral |
51
- literal_string
47
+ string_concatenation |
48
+ scalar
52
49
  ) >> space?
53
50
  }
54
51
 
52
+ rule(:scalar) {
53
+ literal_nil |
54
+ literal_false |
55
+ literal_true |
56
+ numeral |
57
+ literal_string
58
+ }
59
+
55
60
  rule(:literal_nil) {
56
61
  str('nil')
57
62
  }
@@ -157,6 +162,10 @@ module Lua
157
162
  match('[0-9]')
158
163
  }
159
164
 
165
+ rule(:string_concatenation) {
166
+ (scalar.as(:lhs) >> space? >> str('..') >> space? >> scalar.as(:rhs)).as(:string_concatenation)
167
+ }
168
+
160
169
  rule(:name) {
161
170
  (match('[A-Za-z_]') >> match('[A-Za-z_0-9]').repeat).as(:name)
162
171
  }
@@ -177,6 +186,18 @@ module Lua
177
186
  rule(:space?) {
178
187
  (space | comment).repeat
179
188
  }
189
+
190
+ # Parses the given argument as a Lua literal expression
191
+ #
192
+ # See {file:README.md} for supported syntax.
193
+ # @param [String, Parslet::Source] lua_literal Lua literal expression
194
+ # @return [Hash, Array, Parslet::Slice] PORO (Plain old Ruby object) result tree
195
+ # @see {::Parslet::Parser#parse}
196
+ def parse(lua_literal)
197
+ super(lua_literal)
198
+ rescue Parslet::ParseFailed
199
+ raise Lua::Literal::ParseError
200
+ end
180
201
  end
181
202
  end
182
203
  end
@@ -57,6 +57,10 @@ module Lua
57
57
  vs.join
58
58
  }
59
59
 
60
+ rule(string_concatenation: subtree(:v)) {
61
+ [v[:lhs], v[:rhs]].join
62
+ }
63
+
60
64
  rule('nil') {
61
65
  nil
62
66
  }
@@ -69,7 +73,9 @@ module Lua
69
73
  false
70
74
  }
71
75
 
72
- rule(table: {fields: subtree(:fields)}) {
76
+ rule(table: subtree(:fields)) {
77
+ next {} if fields.nil?
78
+
73
79
  pairs = (fields.is_a?(Hash) ? [fields] : fields)
74
80
  indexed, kvs = pairs.partition {|pair| pair.key?(:indexed) }
75
81
  hash = kvs.inject({}) {|acc, pair| acc.merge(pair) }
@@ -77,10 +83,6 @@ module Lua
77
83
  hash
78
84
  }
79
85
 
80
- rule(table: '{}') {
81
- Hash[]
82
- }
83
-
84
86
  rule(key: subtree(:key), value: subtree(:value)) {
85
87
  {key => value}
86
88
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Lua
4
4
  module Literal
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  public_constant :VERSION
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lua-literal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OZAWA Sakuro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-21 00:00:00.000000000 Z
11
+ date: 2020-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -136,6 +136,7 @@ files:
136
136
  - ".rubocop.yml"
137
137
  - ".rubocop_todo.yml"
138
138
  - ".travis.yml"
139
+ - CHANGELOG.md
139
140
  - Gemfile
140
141
  - LICENSE.txt
141
142
  - README.md