gob-lang 1.5.6 → 1.5.8
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/gob/cli/base.rb +0 -14
- data/lib/gob/transpilation/runner.rb +20 -10
- data/lib/gob/version.rb +1 -1
- data/lib/gob.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4cd6d81f3fb29faa854c61fbdf3c65dc4d831cc19326d8a5f9895ea1f71afe00
|
|
4
|
+
data.tar.gz: 403697e65db0a24072a5ba8af57ce079a4592bd7f00f6c1226101a7f5915264c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b15913d1fcee07cae9741a70b46fb5922e33c77fd5d76565ce65f9d5623ff5a83f7de356e73372725dba3f0f62159d39be616e7694186510519ff799a1fd099d
|
|
7
|
+
data.tar.gz: 4968ae2587e03f2cbcd1e80adb87a2b970197bdab0d346efab3d285779c52ab72cff3e7c436c05744215991536c3e9a8fde0b21b7ddf4a9967abca4c4fd661a2
|
data/lib/gob/cli/base.rb
CHANGED
|
@@ -38,21 +38,7 @@ module Gob
|
|
|
38
38
|
matches
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
def validate_source!(source, path)
|
|
42
|
-
offenses = Gob::Validation::Rules.validate(source, path: path)
|
|
43
|
-
return if offenses.empty?
|
|
44
|
-
|
|
45
|
-
Gob::CLI::Errors.render_offenses(offenses, path: path)
|
|
46
|
-
exit 1
|
|
47
|
-
end
|
|
48
|
-
|
|
49
41
|
def transpile_source(source, path)
|
|
50
|
-
Gob::Reporter.step("fmt #{path}")
|
|
51
|
-
source = Gob::Validation::Rules.autocorrect(source, path: path)
|
|
52
|
-
|
|
53
|
-
Gob::Reporter.step("vet #{path}")
|
|
54
|
-
validate_source!(source, path)
|
|
55
|
-
|
|
56
42
|
Gob::Reporter.step("transpile #{path}")
|
|
57
43
|
go_source = Gob.transpile_to_go(source, path: path, check: false)
|
|
58
44
|
|
|
@@ -10,6 +10,17 @@ 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
|
+
GROUP = /(?<group>
|
|
16
|
+
\( (?: [^()\[\]{}] | \g<group> )* \)
|
|
17
|
+
| \[ (?: [^()\[\]{}] | \g<group> )* \]
|
|
18
|
+
| \{ (?: [^()\[\]{}] | \g<group> )* \}
|
|
19
|
+
)/x
|
|
20
|
+
|
|
21
|
+
# One item of a signature list: anything up to a top-level comma.
|
|
22
|
+
ITEM = /(?<item> (?: [^,()\[\]{}] | #{GROUP} )+ )/x
|
|
23
|
+
|
|
13
24
|
def parse_signature_comment(text)
|
|
14
25
|
body = text.to_s.strip.sub(/\A#\s*/, "")
|
|
15
26
|
parts = body.split(/\s*->\s*/, 2)
|
|
@@ -17,16 +28,15 @@ module Gob
|
|
|
17
28
|
right = parts[1].to_s.strip
|
|
18
29
|
|
|
19
30
|
split_items = ->(v) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
in /\A\
|
|
28
|
-
|
|
29
|
-
v.scan(/func\([^()]*\)(?:\s+[^,]+)?|\[[^\[\]]*\][^,]*|[^,]+/).map(&:strip).reject(&:empty?)
|
|
31
|
+
case v.strip
|
|
32
|
+
in /\A\s*\z/
|
|
33
|
+
[]
|
|
34
|
+
in /\A\((?<inner>.*)\)\z/m
|
|
35
|
+
split_items.call($~[:inner])
|
|
36
|
+
in /\A#{ITEM}\s*,\s*(?<rest>.*)\z/m
|
|
37
|
+
[$~[:item].strip, *split_items.call($~[:rest])]
|
|
38
|
+
in /\A#{ITEM}\z/
|
|
39
|
+
[$~[:item].strip]
|
|
30
40
|
end
|
|
31
41
|
}
|
|
32
42
|
|
data/lib/gob/version.rb
CHANGED
data/lib/gob.rb
CHANGED
|
@@ -29,14 +29,14 @@ module Gob
|
|
|
29
29
|
____
|
|
30
30
|
|
|
31
31
|
# Parse `source` and transpile it into a SyntaxTree::Go tree.
|
|
32
|
-
def self.transpile(source, path: nil, check:
|
|
32
|
+
def self.transpile(source, path: nil, check: false)
|
|
33
33
|
Validation::Rules.check!(source, path: path) if check
|
|
34
34
|
Transpilation::Context.global_for(path) if path
|
|
35
35
|
Transpilation::Runner.new.call(RubyParser.parse(source))
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# Transpile `source` and emit it as Go source text.
|
|
39
|
-
def self.transpile_to_go(source, path: nil, check:
|
|
39
|
+
def self.transpile_to_go(source, path: nil, check: false)
|
|
40
40
|
Go::Printer.print(transpile(source, path: path, check: check))
|
|
41
41
|
end
|
|
42
42
|
end
|