gob-lang 1.5.10 → 1.6.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
  SHA256:
3
- metadata.gz: 2d46e4b719e0fb9c05ab9354f3c7f5fdf6a24dee9562fac906a0918728fc8ff9
4
- data.tar.gz: ccb5aeb774d0b9c91488bc181772a5e512e6d6c490e3fd9b2947906d0d6a4714
3
+ metadata.gz: 6cbb5cf07751dbe1b068fe63b097d286bbbd7137ac7166f2869493a590ae580f
4
+ data.tar.gz: 939090e983cbceba44de2772db9c1b3ce2096e15e50b31137fa6e171f1bf00ca
5
5
  SHA512:
6
- metadata.gz: c4bfdba6f98edab15dc8a48aa8dcd40803ce5a4861624ba6399f0ae229dbdc4c14d0b6943491a87a3266b51152649c1cc18a3aefe703140dd96c08b92bff9c21
7
- data.tar.gz: 582e696d5a61dcd3743899b8433f92c1fabc3a22d8081d384a98476a169590f2304f30f684013ecc9615ab30f50e479ed0715246636055a2722beecdc403bca7
6
+ metadata.gz: 1922e6c771b8c2089808df5d9319fd8957e8eb35a849400193f63c064cbe17d01007ee03b19960e8cb11eede8b5b4dea2690be2252006521ce7716f4776b200c
7
+ data.tar.gz: 2f48145857a0668f9924015e5c54a83e5d07d699fd68d1e2d578873c7f95dfef870dda78b038fcb5e41fc9dcfaebce3445cf403118dcd198b4c6d05f91465334
@@ -10,15 +10,12 @@ module Gob
10
10
  module Transpilation
11
11
  class Runner
12
12
  module DefinitionNodes
13
- # A bracketed group, nesting recursively. A comma inside a group
14
- # belongs to the type, so it is never an item separator.
15
13
  GROUP = /(?<group>
16
14
  \( (?: [^()\[\]{}] | \g<group> )* \)
17
15
  | \[ (?: [^()\[\]{}] | \g<group> )* \]
18
16
  | \{ (?: [^()\[\]{}] | \g<group> )* \}
19
17
  )/x
20
18
 
21
- # One item of a signature list: anything up to a top-level comma.
22
19
  ITEM = /(?<item> (?: [^,()\[\]{}] | #{GROUP} )+ )/x
23
20
 
24
21
  def parse_signature_comment(text)
@@ -165,9 +162,6 @@ module Gob
165
162
  )
166
163
  end
167
164
 
168
- # A field list is read by taking its head apart and matching the tail,
169
- # so every shape a field can take is one pattern in one case.
170
- #
171
165
  # Title: string, # `json:"title"`
172
166
  # Title string `json:"title"`
173
167
  # ---
@@ -244,16 +238,11 @@ module Gob
244
238
  ]
245
239
  [ EmbeddedField(type), *Fields(rest) ]
246
240
 
247
- # Whatever else shares the body with the fields belongs to another
248
- # rule, so the tail carries on alone.
249
- # ---
250
241
  in [_, *rest]
251
242
  Fields(rest)
252
243
  end
253
244
  end
254
245
 
255
- # Embedded struct fields have no name, only the type.
256
- # ---
257
246
  def EmbeddedFields(nodes)
258
247
  Array(nodes).map { |node| EmbeddedField(node) }
259
248
  end
@@ -264,9 +253,6 @@ module Gob
264
253
  )
265
254
  end
266
255
 
267
- # A label wears its colon and a tag wears its comment hash; the field is
268
- # the one place that knows to take them off.
269
- # ---
270
256
  def Field(label, type, tag: nil)
271
257
  SyntaxTree::Go::Field.new(
272
258
  names: [ Ident(label.delete_suffix(":")) ],
@@ -275,11 +261,6 @@ module Gob
275
261
  )
276
262
  end
277
263
 
278
- # A method takes a pointer receiver, because a method that cannot modify
279
- # its receiver is the exception rather than the rule. `protected` is that
280
- # exception: it hands the method a copy, so the instance is protected
281
- # from modification.
282
- #
283
264
  # def Mutate(value) # (int)
284
265
  # func (self *colour) Mutate(value int)
285
266
  # ---
@@ -304,8 +285,6 @@ module Gob
304
285
  end
305
286
  end
306
287
 
307
- # self is the name Gob gives every receiver.
308
- # ---
309
288
  def Receiver(name, pointer:)
310
289
  type = Ident(name)
311
290
 
@@ -319,8 +298,6 @@ module Gob
319
298
  )
320
299
  end
321
300
 
322
- # Reads one definition, whatever shape its signature takes.
323
- # ---
324
301
  def Method(definition, receiver:)
325
302
  definition => SyntaxTree::DefNode[
326
303
  name: { value: method },
@@ -333,9 +310,6 @@ module Gob
333
310
  end
334
311
  end
335
312
 
336
- # The names a signature brings into scope: the parameters it binds and
337
- # the results it names.
338
- # ---
339
313
  def Scope(params)
340
314
  case params
341
315
  in { contents: SyntaxTree::Params[requireds: args], comments: [SyntaxTree::Comment[value: types], *] }
@@ -667,8 +641,6 @@ module Gob
667
641
  # when (msg = ch.<<)
668
642
  # case msg := <-ch:
669
643
  # ---
670
- # A comm clause may be parenthesised, as an if condition may be. The
671
- # parentheses are Gob syntax and must not reach the Go output.
672
644
  in SyntaxTree::Paren[ contents: contents ]
673
645
  Comm(
674
646
  case contents
@@ -740,10 +712,6 @@ module Gob
740
712
  # when msg, ok = ch.<<
741
713
  # case msg, ok := <-ch:
742
714
  # ---
743
- # Ruby reads the comma as a when-value separator, so an unparenthesised
744
- # comma-ok receive arrives as several arguments: every target but the
745
- # last, then the assignment that carries the last target and the
746
- # receive. They are one comm clause and are put back together here.
747
715
  in SyntaxTree::When[
748
716
  arguments: SyntaxTree::Args[ parts: [
749
717
  *targets,
@@ -1268,9 +1236,6 @@ module Gob
1268
1236
  # !ok
1269
1237
  # !ok
1270
1238
  # ---
1271
- # A unary expression is not a variable, so it has to be transpiled as
1272
- # the expression it is. Without this an "if !ok" predicate reaches
1273
- # Variable and comes back nil, emitting "if nil".
1274
1239
  in SyntaxTree::Unary
1275
1240
  Statements(node)
1276
1241
 
@@ -2125,10 +2090,45 @@ module Gob
2125
2090
  # ---
2126
2091
  in SyntaxTree::ClassDeclaration[
2127
2092
  constant: SyntaxTree::ConstRef[ constant: SyntaxTree::Const[value: name] ],
2093
+ superclass: nil,
2128
2094
  bodystmt: SyntaxTree::BodyStmt[ statements: SyntaxTree::Statements[ body: body ] ]
2129
2095
  ]
2130
2096
  [ TypeDecl(name, Fields(body)), *Methods(name, body) ]
2131
2097
 
2098
+ # class FilesTable < Table
2099
+ # type FilesTable struct { Table }
2100
+ # ---
2101
+ in SyntaxTree::ClassDeclaration[
2102
+ constant: SyntaxTree::ConstRef[ constant: SyntaxTree::Const[value: name] ],
2103
+ superclass: SyntaxTree::VarRef[value: SyntaxTree::Const] => superclass,
2104
+ bodystmt: SyntaxTree::BodyStmt[ statements: SyntaxTree::Statements[ body: body ] ]
2105
+ ]
2106
+ [ TypeDecl(name, [EmbeddedField(superclass), *Fields(body)]), *Methods(name, body) ]
2107
+
2108
+ # class Node < fs.Inode
2109
+ # type Node struct { fs.Inode }
2110
+ # ---
2111
+ in SyntaxTree::ClassDeclaration[
2112
+ constant: SyntaxTree::ConstRef[ constant: SyntaxTree::Const[value: name] ],
2113
+ superclass: SyntaxTree::CallNode[
2114
+ operator: SyntaxTree::Period[value: "."],
2115
+ message: SyntaxTree::Const,
2116
+ arguments: nil
2117
+ ] => superclass,
2118
+ bodystmt: SyntaxTree::BodyStmt[ statements: SyntaxTree::Statements[ body: body ] ]
2119
+ ]
2120
+ [ TypeDecl(name, [EmbeddedField(superclass), *Fields(body)]), *Methods(name, body) ]
2121
+
2122
+ # class Path < string
2123
+ # type Path string
2124
+ # ---
2125
+ in SyntaxTree::ClassDeclaration[
2126
+ constant: SyntaxTree::ConstRef[ constant: SyntaxTree::Const[value: name] ],
2127
+ superclass: superclass,
2128
+ bodystmt: SyntaxTree::BodyStmt[ statements: SyntaxTree::Statements[ body: body ] ]
2129
+ ]
2130
+ [ TypeDefinition(name, superclass), *Methods(name, body) ]
2131
+
2132
2132
  in SyntaxTree::DefNode[
2133
2133
  name: { value: name },
2134
2134
  params: { contents: SyntaxTree::Params[requireds: args], comments: [SyntaxTree::Comment[value: types], *] } => params,
@@ -2308,20 +2308,14 @@ module Gob
2308
2308
 
2309
2309
  after do |ctx|
2310
2310
  if ctx.equal?(root_context)
2311
- # a declaration may arrive with its methods alongside it
2312
2311
  ctx.tree.replace(ctx.tree.flatten)
2313
2312
 
2314
-
2315
2313
  ctx.tree.unshift(SyntaxTree::Go::GenDecl.new(
2316
2314
  tok: :import,
2317
2315
  specs: ctx.tree.select { |node| node.is_a?(SyntaxTree::Go::ImportSpec) }
2318
2316
  ))
2319
2317
  ctx.tree.reject! { |node| node.is_a?(SyntaxTree::Go::ImportSpec) }
2320
2318
 
2321
- # Adjacent declarations of the same kind become one parenthesised
2322
- # block. Only adjacent ones: a type or a func written between two
2323
- # `const` declarations keeps its place, and the constants on
2324
- # either side of it stay in separate blocks.
2325
2319
  [:const, :var].each do |tok|
2326
2320
  runs = ctx.tree.each_with_object([]) do |node, acc|
2327
2321
  joinable = (node in SyntaxTree::Go::GenDecl[tok: ^tok]) || (node in SyntaxTree::Go::Comment)
@@ -2338,8 +2332,6 @@ module Gob
2338
2332
  ctx.tree.replace(runs.flat_map { |run|
2339
2333
  next [run] unless run.is_a?(Array)
2340
2334
 
2341
- # comments the run trails off in were written against
2342
- # whatever follows the run, so they stay outside the block
2343
2335
  trailing = []
2344
2336
  trailing.unshift(run.pop) while run.last in SyntaxTree::Go::Comment
2345
2337
 
@@ -2347,8 +2339,6 @@ module Gob
2347
2339
 
2348
2340
  grouped = SyntaxTree::Go::GenDecl.new(tok: tok, specs: run.flat_map { |node|
2349
2341
  case node
2350
- # consecutive `#` lines are one block comment, so they wait
2351
- # in state until the spec they were written against arrives
2352
2342
  in SyntaxTree::Go::Comment
2353
2343
  ctx.state.fetch(:comments) << node
2354
2344
  []
data/lib/gob/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gob
4
- VERSION = "1.5.10"
4
+ VERSION = "1.6.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gob-lang
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.10
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Kidd