starlark_compiler 0.3.0 → 0.4.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: 663c6958d605dfe906b15293619e97fff4040f4fa57568b88c5d76a343a04083
4
- data.tar.gz: c04c32107df5dfd72be317e48f3f6b96683a21c02b648c8e1f8932859c9b8072
3
+ metadata.gz: f9056c314125d14aa7ee9af25d658629397f42ab961917622c6204f196df7fe3
4
+ data.tar.gz: 57bef8b8f602d04a8fdc86437fff2020cd473be044098bb8e6e9822c9045a08b
5
5
  SHA512:
6
- metadata.gz: 7cfa2e574e4a1be840990253089e61680d58232e9370af894e1cbb502ff8ba1aa145961c2161dd157e0c5d49cdf9bbdf1e2618cbb2c4b0ee18ee146a5dc2e59a
7
- data.tar.gz: d12126d5aecf51ff166c650372620b6171791df5704aea2cf7a8e8e5d5cb68730cd2d0a42c892ec7b58a9c82128893fbc0b51f89cebc1e0f3835f92d3bd96d95
6
+ metadata.gz: 85ba7945d934680f16e4d9613fee54f71b763837545914105908c0acb350a6bd7e27e588766adc8563e18cd75c97e894ad03325102c1778a62d0af389d201a3b
7
+ data.tar.gz: bb63ffc5a3882822e71a44b28379de380e7266d49f552c3d88d8fd7389616a910710bf083da9b37c94da2eb679ae9ca562df49fe083d281952a4b6bc2f440b06
@@ -0,0 +1,21 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
8
+
9
+ jobs:
10
+ integration_tests:
11
+ name: Build and Test
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v1
15
+ - uses: actions/setup-ruby@v1
16
+ with:
17
+ ruby-version: "2.x" # Version range or exact version of a Ruby version to use, using semvers version range syntax.
18
+ - name: Install Gems
19
+ run: bundle install
20
+ - name: Build and Test
21
+ run: bundle exec rake
@@ -0,0 +1,23 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "RSpec - active spec file only",
9
+ "type": "Ruby",
10
+ "request": "launch",
11
+ "useBundler": true,
12
+ "pathToBundler": "/Users/yuanfeng/.rvm/gems/ruby-2.6.1/wrappers/bundle",
13
+ "pathToRDebugIDE": "/Users/yuanfeng/.rvm/gems/ruby-2.6.1/gems/ruby-debug-ide-0.7.2",
14
+ "debuggerPort": "1240",
15
+ "program": "/Users/yuanfeng/.rvm/gems/ruby-2.6.1/bin/rspec",
16
+ "args": [
17
+ "-I",
18
+ "${workspaceRoot}",
19
+ "${file}"
20
+ ]
21
+ }
22
+ ]
23
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ 0.4.0
2
+
3
+ * Add variable assignment and reference ability
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- starlark_compiler (0.3.0)
4
+ starlark_compiler (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -20,9 +20,9 @@ Or install it yourself as:
20
20
  $ gem install starlark_compiler
21
21
 
22
22
  ## Usage
23
-
23
+ The following code:
24
24
  ```ruby
25
- starlark_string = StarlarkCompiler::AST.build do
25
+ ast = StarlarkCompiler::AST.build do
26
26
  ast = StarlarkCompiler::AST.new(toplevel: [])
27
27
  ast << function_call(
28
28
  'load',
@@ -39,20 +39,48 @@ starlark_string = StarlarkCompiler::AST.build do
39
39
  'ios_library',
40
40
  name: string('App_Objc'),
41
41
  srcs: function_call('glob', array([string('Sources/**/*.swift')])) +
42
- ['A.swift']
42
+ ['A.swift']
43
43
  )
44
+ ast << variable_assignment('deps', array([':App_Objc'])
45
+ ast << variable_assignment('numbers', array([1,2,3]))
44
46
  ast << function_call(
45
47
  'ios_application',
46
48
  name: string('App'),
47
- deps: array([
48
- string(':App_Objc')
49
- ]),
49
+ deps: variable_reference('deps'),
50
50
  entitlements: array([string(':App.entitlements')])
51
51
  )
52
- StarlarkCompiler::Writer.write(ast: ast, io: +'')
52
+ ast
53
53
  end
54
+ starlark_string = StarlarkCompiler::Writer.write(ast: ast, io: +'')
55
+ ```
56
+ will populate `starlark_string` with:
57
+ ```python
58
+ load(
59
+ "@bazel_build_rules_apple//rules:ios.bzl",
60
+ "ios_application",
61
+ _ios_application = "ios_application",
62
+ )
63
+ load("@bazel_build_rules_apple//rules:ios.bzl", "ios_application")
64
+
65
+ ios_library(
66
+ name = "App_Objc",
67
+ srcs = glob(["Sources/**/*.swift"]) + ["A.swift"],
68
+ )
69
+
70
+ deps = [":App_Objc"]
71
+
72
+ numbers = [
73
+ 1,
74
+ 2,
75
+ 3,
76
+ ]
77
+
78
+ ios_application(
79
+ name = "App",
80
+ deps = deps,
81
+ entitlements = [":App.entitlements"],
82
+ )
54
83
  ```
55
-
56
84
  ## Development
57
85
 
58
86
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -46,6 +46,8 @@ module StarlarkCompiler
46
46
  end
47
47
 
48
48
  class Node
49
+ TYPE = :Expression
50
+
49
51
  %i[- + / * % == < <= >= >].each do |op|
50
52
  define_method(op) { |rhs| BinaryOperator.new(self, rhs, operator: op) }
51
53
  end
@@ -73,7 +75,7 @@ module StarlarkCompiler
73
75
  when Numeric
74
76
  Number.new(obj)
75
77
  else
76
- raise Error, "#{obj.inspect} not convertible to Node"
78
+ raise Error, "Ruby stdlib type #{obj.inspect} not convertible to Node"
77
79
  end
78
80
  end
79
81
  end
@@ -101,6 +103,17 @@ module StarlarkCompiler
101
103
  end
102
104
  end
103
105
 
106
+ class VariableReference < Node
107
+ attr_reader :var
108
+ def initialize(var)
109
+ unless var.is_a?(::String)
110
+ raise "Variable Reference must be a string, not #{var.class}"
111
+ end
112
+
113
+ @var = var
114
+ end
115
+ end
116
+
104
117
  class Array < Node
105
118
  attr_reader :elements
106
119
  def initialize(elements)
@@ -108,6 +121,19 @@ module StarlarkCompiler
108
121
  end
109
122
  end
110
123
 
124
+ class VariableAssignment < Node
125
+ TYPE = :Statement
126
+ attr_reader :name, :var
127
+ def initialize(name, var)
128
+ @name = name
129
+ if node(var).class::TYPE != :Expression
130
+ raise "Unsupported type on rhs for assignment: #{var.class}"
131
+ end
132
+
133
+ @var = node(var)
134
+ end
135
+ end
136
+
111
137
  class FunctionCall < Node
112
138
  attr_reader :name, :args, :kwargs
113
139
  def initialize(name, *args, **kwargs)
@@ -8,6 +8,7 @@ module StarlarkCompiler
8
8
  def initialize(package:, workspace: Dir.pwd)
9
9
  @loads = Hash.new { |h, k| h[k] = Set.new }
10
10
  @targets = {}
11
+ @variable_assignments = {}
11
12
  @package = package
12
13
  @workspace = workspace
13
14
  @path = File.join(@workspace, @package, 'BUILD.bazel')
@@ -26,6 +27,10 @@ module StarlarkCompiler
26
27
  @targets[name] = function_call
27
28
  end
28
29
 
30
+ def add_variable_assignment(name:, var:)
31
+ @variable_assignments[name] = var
32
+ end
33
+
29
34
  def save!
30
35
  File.open(@path, 'w') do |f|
31
36
  Writer.write(ast: to_starlark, io: f)
@@ -36,10 +41,14 @@ module StarlarkCompiler
36
41
  loads = @loads
37
42
  .sort_by { |k, _| k }
38
43
  .map { |f, fn| AST.build { function_call('load', f, *fn.sort) } }
44
+ variable_assignments = @variable_assignments
45
+ .map do |name, var|
46
+ AST.build { variable_assignment(name, var) }
47
+ end
39
48
  targets = @targets
40
49
  .sort_by { |k, _| k }
41
50
  .map { |_f, fn| normalize_function_call_kwargs(fn) }
42
- AST.new(toplevel: loads + targets)
51
+ AST.new(toplevel: loads + variable_assignments + targets)
43
52
  end
44
53
 
45
54
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StarlarkCompiler
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -97,6 +97,15 @@ module StarlarkCompiler
97
97
  io << ')'
98
98
  end
99
99
 
100
+ def write_variable_reference(variable)
101
+ io << variable.var
102
+ end
103
+
104
+ def write_variable_assignment(assignment)
105
+ io << assignment.name << ' = '
106
+ write_node(assignment.var)
107
+ end
108
+
100
109
  def write_array(array)
101
110
  single_line = single_line?(array)
102
111
  io << '['
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: starlark_compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Giddins
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-13 00:00:00.000000000 Z
11
+ date: 2021-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,17 +24,19 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- description:
27
+ description:
28
28
  email:
29
29
  - segiddins@segiddins.me
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".github/workflows/tests.yml"
34
35
  - ".gitignore"
35
36
  - ".rspec"
36
37
  - ".rubocop.yml"
37
- - ".travis.yml"
38
+ - ".vscode/launch.json"
39
+ - CHANGELOG.md
38
40
  - CODE_OF_CONDUCT.md
39
41
  - Gemfile
40
42
  - Gemfile.lock
@@ -55,7 +57,7 @@ licenses:
55
57
  metadata:
56
58
  homepage_uri: https://github.com/segiddins/starlark_compiler
57
59
  source_code_uri: https://github.com/segiddins/starlark_compiler
58
- post_install_message:
60
+ post_install_message:
59
61
  rdoc_options: []
60
62
  require_paths:
61
63
  - lib
@@ -71,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
73
  version: '0'
72
74
  requirements: []
73
75
  rubygems_version: 3.0.1
74
- signing_key:
76
+ signing_key:
75
77
  specification_version: 4
76
78
  summary: A starlark gem
77
79
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.1
7
- before_install: gem install bundler -v 2.0.2