chelsy 0.0.8 → 0.0.9
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/lib/chelsy/ast.rb +36 -25
- data/lib/chelsy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6c2c39422a4c60d65a9808f55dec47e9401d50d
|
4
|
+
data.tar.gz: 1e2159913cb694fdaa99d326b5ea7a466a047d6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dba34f4c4f6abd2d6778bb498375263841b37a803dca37e3305f4acd06e8e53e9d0547379ebf27c0269b7576a06d136731bf063f47797b10ddd9dc084baeb72
|
7
|
+
data.tar.gz: 02c82c641dcbe31e7a754fcd37a50d348016774d3e3946a3b00de84f2a7414616eed037b4eda8d93a1a10adeeea910533b8a020890eee7c77e0f7e0fbe2e0c8c
|
data/lib/chelsy/ast.rb
CHANGED
@@ -3,23 +3,23 @@ require "forwardable"
|
|
3
3
|
|
4
4
|
module Chelsy
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
# Returns an object as an immutable string.
|
7
|
+
#
|
8
|
+
# @param [Object] obj an Object
|
9
|
+
# @return [String] The string representation of `obj`. It's frozen (unmodifiable).
|
10
|
+
def immutable_stringify(obj)
|
11
|
+
str = obj.to_s
|
12
|
+
if str.frozen?
|
13
|
+
str
|
14
|
+
else
|
15
|
+
str.dup.freeze
|
8
16
|
end
|
17
|
+
end
|
9
18
|
|
10
|
-
|
19
|
+
module_function :immutable_stringify
|
11
20
|
|
12
|
-
|
13
|
-
|
14
|
-
# @param [Object] obj an Object
|
15
|
-
# @return [String] The string representation of `obj`. It's frozen (unmodifiable).
|
16
|
-
def immutable_stringify(obj)
|
17
|
-
str = obj.to_s
|
18
|
-
if str.frozen?
|
19
|
-
str
|
20
|
-
else
|
21
|
-
str.dup.freeze
|
22
|
-
end
|
21
|
+
class Node
|
22
|
+
def initialize(**opts)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -97,9 +97,6 @@ module Chelsy
|
|
97
97
|
|
98
98
|
end
|
99
99
|
|
100
|
-
module Syntax
|
101
|
-
end
|
102
|
-
|
103
100
|
class FragmentList < Node
|
104
101
|
include NodeList
|
105
102
|
|
@@ -132,7 +129,7 @@ module Chelsy
|
|
132
129
|
# Initialize instance.
|
133
130
|
# @param [#to_s] code C code snippet
|
134
131
|
def initialize(code, **rest)
|
135
|
-
@code = immutable_stringify(code)
|
132
|
+
@code = Chelsy.immutable_stringify(code)
|
136
133
|
super **rest
|
137
134
|
end
|
138
135
|
|
@@ -523,7 +520,7 @@ module Chelsy
|
|
523
520
|
attr_reader :value
|
524
521
|
|
525
522
|
def initialize(str, wide: false, **rest)
|
526
|
-
@value = immutable_stringify(str)
|
523
|
+
@value = Chelsy.immutable_stringify(str)
|
527
524
|
@wide = !!wide
|
528
525
|
|
529
526
|
super(**rest)
|
@@ -985,9 +982,18 @@ module Chelsy
|
|
985
982
|
class Switch < Stmt
|
986
983
|
attr_reader :expr, :stmt
|
987
984
|
|
988
|
-
def initialize(expr, stmt, **rest)
|
985
|
+
def initialize(expr, stmt=nil, **rest, &block)
|
989
986
|
@expr = Syntax::Expr.ensure(expr)
|
990
|
-
|
987
|
+
|
988
|
+
if stmt
|
989
|
+
@stmt = Syntax::Stmt.ensure(stmt)
|
990
|
+
elsif block
|
991
|
+
@stmt = Block.new
|
992
|
+
block.call(@stmt)
|
993
|
+
else
|
994
|
+
raise ArgumentError, "missing body statement"
|
995
|
+
end
|
996
|
+
|
991
997
|
super **rest
|
992
998
|
end
|
993
999
|
end
|
@@ -1175,7 +1181,7 @@ module Chelsy
|
|
1175
1181
|
attr_reader :location
|
1176
1182
|
|
1177
1183
|
def initialize(location, system: false, **rest)
|
1178
|
-
@location = immutable_stringify(location)
|
1184
|
+
@location = Chelsy.immutable_stringify(location)
|
1179
1185
|
@system = !!system
|
1180
1186
|
|
1181
1187
|
super **rest
|
@@ -1249,7 +1255,7 @@ module Chelsy
|
|
1249
1255
|
|
1250
1256
|
def initialize(lineno, filename=nil, **rest)
|
1251
1257
|
@lineno = Syntax::Coercers::Int.ensure(lineno)
|
1252
|
-
@filename = immutable_stringify(filename) if filename
|
1258
|
+
@filename = Chelsy.immutable_stringify(filename) if filename
|
1253
1259
|
|
1254
1260
|
super **rest
|
1255
1261
|
end
|
@@ -1260,7 +1266,7 @@ module Chelsy
|
|
1260
1266
|
attr_reader :pragma
|
1261
1267
|
|
1262
1268
|
def initialize(pragma, **rest)
|
1263
|
-
@pragma = immutable_stringify(pragma)
|
1269
|
+
@pragma = Chelsy.immutable_stringify(pragma)
|
1264
1270
|
super **rest
|
1265
1271
|
end
|
1266
1272
|
end
|
@@ -1300,6 +1306,10 @@ module Chelsy
|
|
1300
1306
|
Param = Coercer.new(Chelsy::Param) do |value|
|
1301
1307
|
Chelsy::Param.new(*value) if ::Array === value
|
1302
1308
|
end
|
1309
|
+
|
1310
|
+
Block = Coercer.new(Chelsy::Block) do |value|
|
1311
|
+
Chelsy::Block.new(value) if ::Array === value
|
1312
|
+
end
|
1303
1313
|
end
|
1304
1314
|
|
1305
1315
|
TopLevel = Any.new('TopLevel', [Declarative])
|
@@ -1326,7 +1336,8 @@ module Chelsy
|
|
1326
1336
|
Initializer = Any.new('Initializer', [Syntax::Expr, Chelsy::Initializer, Chelsy::InitializerList])
|
1327
1337
|
Stmt = Any.new('Statement', [
|
1328
1338
|
Syntax::Expr, # Treats Expr as Expression Statement
|
1329
|
-
Chelsy::Stmt
|
1339
|
+
Chelsy::Stmt,
|
1340
|
+
Coercers::Block])
|
1330
1341
|
BlockItem = Any.new('BlockItem', [
|
1331
1342
|
Syntax::Stmt,
|
1332
1343
|
Chelsy::Declarative])
|
data/lib/chelsy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chelsy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takanori Ishikawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|