lua-literal 0.1.0 → 0.2.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 +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +9 -0
- data/README.md +4 -0
- data/lib/lua/literal.rb +1 -0
- data/lib/lua/literal/parser.rb +28 -7
- data/lib/lua/literal/transform.rb +7 -5
- data/lib/lua/literal/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e5df06fe05cd5b78ae6c72d85127073b0b5d15d114ba6075274c4be7dd68a539
|
|
4
|
+
data.tar.gz: 49736a59edd2c6e17d2ffdb19f4c820f9ac285e24c60aab0ec34273c62b239b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e3c317cd3e3a2e5d8dd5d6fd276548ed37fb53f69934e13f06e8773f2f77891045323546fdadca52b29c0f8ea58bdfaabf8d43f1b12c588a3a3dc87d9537ce33
|
|
7
|
+
data.tar.gz: 745b110958417e590c5ff4942654d271d44c11b3b5edcfb38312401504c06a665730d8098ec7999ff4de003d70bf59609b71b797216adb633b7607303538d215
|
data/.rubocop.yml
CHANGED
|
@@ -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
|
data/CHANGELOG.md
ADDED
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.
|
data/lib/lua/literal.rb
CHANGED
data/lib/lua/literal/parser.rb
CHANGED
|
@@ -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('}'))
|
|
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
|
-
|
|
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
|
-
|
|
48
|
-
|
|
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:
|
|
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
|
}
|
data/lib/lua/literal/version.rb
CHANGED
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.
|
|
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-
|
|
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
|