salt 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58f8fcc6218bf972ee729572931f84d819e54214
4
+ data.tar.gz: 8fbc92ec6384e78234ef79a4f9731d3474cb436a
5
+ SHA512:
6
+ metadata.gz: e2641e9c27e20e4dd0999df7b95222e594235766d75e6f44ab17d6f8a992cb6214e507e80896694ea44cb81ca0b3c96e14606a602284fbd24e0f42d5cfa76174
7
+ data.tar.gz: bac7d1f1d90c12c68234e1acbcb16a33faee963a74ea70922dbb8779c8ebe579112e9df63ca7a78b28546880bc1aefb92ca5857c4ce9620c04aa8c976b3f2f05
@@ -0,0 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ lib/salt/parser.err
37
+ lib/salt/parser.inf
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,11 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - 'lib/salt/parser.rb'
6
+
7
+ Style/AlignParameters:
8
+ EnforcedStyle: with_fixed_indentation
9
+
10
+ Style/SignalException:
11
+ EnforcedStyle: only_raise
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 2.1.0
5
+ - 2.0.0
6
+ - 1.9.3
7
+ - jruby-19mode
8
+ script: bundle exec rspec -f d spec
9
+ sudo: false
10
+ cache: bundler
@@ -0,0 +1,6 @@
1
+ --protected
2
+ --private
3
+ -m markdown
4
+ -
5
+ LICENSE.txt
6
+ README.md
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ salt (0.0.1)
5
+ command-runner (~> 0.9)
6
+ commander
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.0.0)
12
+ astrolabe (1.3.0)
13
+ parser (>= 2.2.0.pre.3, < 3.0)
14
+ command-runner (0.9.3)
15
+ hashie (~> 3.3)
16
+ promise
17
+ commander (4.3.0)
18
+ highline (~> 1.6.11)
19
+ diff-lcs (1.2.5)
20
+ hashie (3.4.0)
21
+ highline (1.6.21)
22
+ parser (2.2.0.3)
23
+ ast (>= 1.1, < 3.0)
24
+ powerpack (0.1.0)
25
+ promise (0.3.1)
26
+ rainbow (2.0.0)
27
+ rake (10.4.2)
28
+ rspec (3.2.0)
29
+ rspec-core (~> 3.2.0)
30
+ rspec-expectations (~> 3.2.0)
31
+ rspec-mocks (~> 3.2.0)
32
+ rspec-core (3.2.2)
33
+ rspec-support (~> 3.2.0)
34
+ rspec-expectations (3.2.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.2.0)
37
+ rspec-mocks (3.2.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.2.0)
40
+ rspec-support (3.2.2)
41
+ rubocop (0.29.1)
42
+ astrolabe (~> 1.3)
43
+ parser (>= 2.2.0.1, < 3.0)
44
+ powerpack (~> 0.1)
45
+ rainbow (>= 1.99.1, < 3.0)
46
+ ruby-progressbar (~> 1.4)
47
+ rubocop-rspec (1.2.2)
48
+ ruby-progressbar (1.7.1)
49
+
50
+ PLATFORMS
51
+ x64-mingw32
52
+
53
+ DEPENDENCIES
54
+ bundler (~> 1.6)
55
+ rake (~> 10.0)
56
+ rspec (~> 3.1)
57
+ rubocop
58
+ rubocop-rspec
59
+ salt!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jeremy Rodi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,2 @@
1
+ # salt
2
+ Sane Alternative Language To C
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'salt'
6
+
7
+ Salt::CLI.new.run
@@ -0,0 +1,19 @@
1
+ require 'salt/version'
2
+ require 'salt/scanner'
3
+ require 'salt/parser'
4
+ require 'salt/compiler'
5
+ require 'salt/walker'
6
+ require 'salt/cli'
7
+
8
+ module Salt
9
+ def parse(path)
10
+ parse_string(File.read(path))
11
+ end
12
+
13
+ def parse_string(string, source = '(eval)')
14
+ tokens = Scanner.scan(string, source)
15
+ ast = Parser.parse(tokens)
16
+ end
17
+
18
+ module_function :parse, :parse_string
19
+ end
@@ -0,0 +1,40 @@
1
+ require 'commander'
2
+
3
+ module Salt
4
+ class CLI
5
+ include Commander::Methods
6
+
7
+ def run
8
+ program :name, 'Salt'
9
+ program :version, Salt::VERSION
10
+ program :description, 'Compiles and/or runs salt programs.'
11
+
12
+ compile_command
13
+ lint_command
14
+ run_command
15
+
16
+ run!
17
+ end
18
+
19
+ private
20
+
21
+ def compile_command
22
+ command :compile do |command|
23
+ command.syntax = 'salt compile'
24
+ command.description = 'Compiles the given file.'
25
+ command.option '-f STRING', '--file STRING', String,
26
+ 'The file to compile.'
27
+
28
+ command.action do |_, options|
29
+ p options
30
+ end
31
+ end
32
+ end
33
+
34
+ def lint_command
35
+ end
36
+
37
+ def run_command
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ module Salt
4
+ class Compiler
5
+ class Type
6
+ attr_reader :type
7
+
8
+ def initialize(type, clname, value)
9
+ @type = type
10
+ @clname = clname
11
+ @value = value
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Salt
2
+ class Generator
3
+ def initialize(settings)
4
+ @settings = settings
5
+ end
6
+
7
+ def generate(ast)
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Salt
2
+ module Generator
3
+ module Main
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,353 @@
1
+ %require "~> 0.1"
2
+ %generator "ruby"
3
+
4
+ %ruby.error-class SyntaxError
5
+ %panic-mode true
6
+
7
+ %terminal IDENTIFIER
8
+ %terminal NUMBER
9
+ %terminal UNUMBER
10
+ %terminal FLOAT
11
+ %terminal DOUBLE
12
+ %terminal SNUMBER
13
+ %terminal USNUMBER
14
+ %terminal LNUMBER
15
+ %terminal ULNUMBER
16
+ %terminal LLNUMBER
17
+ %terminal ULLNUMBER
18
+ %terminal CHARACTER
19
+ %terminal STRING
20
+ %terminal FUNCTION "function"
21
+ %terminal FUNC "func"
22
+ %terminal CLASS "class"
23
+ %terminal STRUCT "struct"
24
+ %terminal UNION "union"
25
+ %terminal CONTINUE "continue"
26
+ %terminal BREAK "break"
27
+ %terminal IF "if"
28
+ %terminal ELSE "else"
29
+ %terminal FOR "for"
30
+ %terminal WHILE "while"
31
+ %terminal DO "do"
32
+ %terminal GOTO "goto"
33
+ %terminal RETURN "return"
34
+ %terminal TYPEDEF "typedef"
35
+ %terminal LABEL "label"
36
+ %terminal LBRACE "{"
37
+ %terminal RBRACE "}"
38
+ %terminal LPAREN "("
39
+ %terminal RPAREN ")"
40
+ %terminal LBRACK "["
41
+ %terminal RBRACK "]"
42
+ %terminal EQUALS "="
43
+ %terminal PLUS "+"
44
+ %terminal DPLUS "++"
45
+ %terminal MINUS "-"
46
+ %terminal DMINUS "--"
47
+ %terminal DIVIDE "/"
48
+ %terminal MOD "%"
49
+ %terminal LSHIFT "<<"
50
+ %terminal RSHIFT ">>"
51
+ %terminal AMBER "&"
52
+ %terminal CARET "^"
53
+ %terminal STAR "*"
54
+ %terminal COLON ":"
55
+ %terminal DCOLON "::"
56
+ %terminal SEMICOLON ";"
57
+ %terminal HASH "#"
58
+ %terminal COMMA ","
59
+ %terminal LBRK "<"
60
+ %terminal RBRK ">"
61
+ %terminal COMP "=="
62
+ %terminal NCMP "!="
63
+ %terminal LNOT "!"
64
+ %terminal BNOT "~"
65
+ %terminal LAND "&&"
66
+ %terminal LOR "||"
67
+ %terminal BOR "|"
68
+
69
+ %nonassoc STRING
70
+ %left SDEC SINC CALL ACCESS
71
+ %right PDEC PINC UPLUS UMINUS CAST LNOT BNOT DREF REF
72
+ %left MULTIPLY DIVIDE MOD
73
+ %left PLUS MINUS
74
+ %left LSHIFT RSHIFT
75
+ %left LBRK RBRK
76
+ %left COMP NCMP
77
+ %left BAND
78
+ %left BXOR
79
+ %left BOR
80
+ %left LAND
81
+ %left LOR
82
+ %right EQUALS OEQ
83
+ %left COMMA
84
+ %nonassoc _
85
+ %nonassoc RETURN
86
+
87
+ %%
88
+
89
+ body: parts.maybe
90
+ { |a| [:root, a] }
91
+
92
+ preprocessor: HASH IDENTIFIER function.body SEMICOLON
93
+ { |_, a, b, _| [:pre, a, b] }
94
+
95
+ parts.maybe: parts | nothing
96
+ parts: parts part
97
+ { |a, b| a << b }
98
+ | part
99
+ { |a| [a] }
100
+ | type
101
+ { |a| [a] }
102
+ part: function | class | struct | union | typedef | preprocessor
103
+
104
+ function: FUNCTION IDENTIFIER LPAREN function.arguments.maybe RPAREN
105
+ COLON type LBRACE function.body RBRACE
106
+ { |_, a, _, b, _, _, c, _, d, _| [:func, a, b, c, d] }
107
+ function.arguments.maybe: function.arguments | nothing
108
+ function.arguments: function.arguments COMMA function.argument
109
+ { |a, _, b| a << b }
110
+ | function.argument
111
+ function.argument: IDENTIFIER COLON type { |a, _, b| [:fnarg, a, b] }
112
+
113
+ class: CLASS class.name LBRACE class.body RBRACE
114
+ { |_, a, _, b, _| [:class, a, b] }
115
+ class.name: class.name DCOLON IDENTIFIER
116
+ { |a, _, b| a << b }
117
+ | IDENTIFIER
118
+ { |a| [:clname, a] }
119
+
120
+ class.body: class.parts.maybe
121
+ class.parts.maybe: class.parts | nothing
122
+ class.parts: class.parts class.part
123
+ { |a, b| a << b }
124
+ | class.part
125
+ { |a| [a] }
126
+ class.part: class.attribute | class.function | preprocessor
127
+ class.attribute: IDENTIFIER COLON type SEMICOLON
128
+ { |a, _, b| [:clattr, a, b] }
129
+ class.function: FUNC IDENTIFIER LPAREN function.arguments.maybe RPAREN
130
+ COLON type LBRACE function.body RBRACE
131
+ { |_, a, _, b, _, _, c, _, d, _| [:clfunc, a, b, c, d] }
132
+
133
+ struct: STRUCT class.name LBRACE struct.body RBRACE
134
+ { |_, a, _, b, _| [:struct, a, b] }
135
+ struct.anon: STRUCT LBRACE struct.body RBRACE
136
+ { |_, _, b, _| [:struct, nil, b] }
137
+ struct.body: struct.parts.maybe
138
+ struct.parts.maybe: struct.parts | nothing
139
+ struct.parts: struct.parts struct.part
140
+ { |a, b| a << b }
141
+ | struct.part
142
+ { |a| [a] }
143
+ struct.part: class.attribute | preprocessor
144
+
145
+ union: UNION class.name LBRACE union.body RBRACE
146
+ { |_, a, _, b, _| [:union, a, b] }
147
+ union.anon: UNION LBRACE union.body RBRACE
148
+ { |_, _, b, _| [:union, nil, b] }
149
+ union.body: union.parts.maybe
150
+ union.parts.maybe: union.parts | nothing
151
+ union.parts: union.parts union.part
152
+ { |a, b| a << b }
153
+ | union.part
154
+ { |a| [a] }
155
+ union.part: class.attribute | preprocessor
156
+
157
+ type: type CARET
158
+ { |a| [:pointer, a] }
159
+ | class.name
160
+ | struct.anon
161
+ | union.anon
162
+
163
+ function.body: function.body.parts.maybe
164
+ function.body.parts.maybe: function.body.parts | nothing
165
+ function.body.parts: function.body.parts function.body.part
166
+ { |a, b| a << b }
167
+ | function.body.part
168
+ { |a| [a] }
169
+ function.body.part: function.body.declare SEMICOLON
170
+ | function.body.expression SEMICOLON
171
+ | function.body.control SEMICOLON
172
+ | preprocessor
173
+ function.body.expression: function.body.assignment
174
+ | function.body.reference
175
+ | function.body.call
176
+ | function.body.math
177
+ | function.body.literal
178
+ | function.body.logic
179
+ | LPAREN function.body.expression RPAREN
180
+ { |_, a, _| a }
181
+
182
+ function.body.declare: IDENTIFIER COLON type
183
+ { |a, _, b| [:variable, a, b] }
184
+ | IDENTIFIER COLON type EQUALS
185
+ function.body.expression
186
+ { |a, _, b, _, c| [:variable, a, b, c] }
187
+
188
+ function.body.assignment: function.body.reference EQUALS
189
+ function.body.expression %prec EQUALS
190
+ { |a, _, b| [:assign, a, b] }
191
+ function.body.reference: CARET function.body.expression %prec DEREF
192
+ { |_, a| [:deref, a] }
193
+ | AMBER function.body.expression %prec REF
194
+ { |_, a| [:ref, a] }
195
+ | function.body.expression LBRACK
196
+ function.body.expression RBRACK %prec ACCESS
197
+ { |a, _, b, _| [:brack, a, b] }
198
+ | IDENTIFIER
199
+ function.body.call: function.body.expression
200
+ LPAREN function.body.call.arguments.maybe
201
+ RPAREN %prec CALL
202
+ { |a, _, b, _| [:call, a, b] }
203
+ function.body.math: function.body.expression PLUS
204
+ function.body.expression
205
+ { |a, _, b| [:add, a, b] }
206
+ | function.body.expression MINUS
207
+ function.body.expression
208
+ { |a, _, b| [:sub, a, b] }
209
+ | function.body.expression STAR
210
+ function.body.expression %prec MULTIPLY
211
+ { |a, _, b| [:mult, a, b] }
212
+ | function.body.expression DIVIDE
213
+ function.body.expression
214
+ { |a, _, b| [:div, a, b] }
215
+ | function.body.expression MOD
216
+ function.body.expression
217
+ { |a, _, b| [:mod, a, b] }
218
+ | function.body.expression LSHIFT
219
+ function.body.expression
220
+ { |a, _, b| [:lshift, a, b] }
221
+ | function.body.expression RSHIFT
222
+ function.body.expression
223
+ { |a, _, b| [:rshift, a, b] }
224
+ | function.body.expression DPLUS %prec SINC
225
+ { |a, _| [:sinc, a] }
226
+ | function.body.expression DMINUS %prec SDEC
227
+ { |a, _| [:sdec, a] }
228
+ | DMINUS function.body.expression %prec PINC
229
+ { |_, a| [:pinc, a] }
230
+ | DPLUS function.body.expression %prec PDEC
231
+ { |_, a| [:pdec, a] }
232
+ | PLUS function.body.expression %prec UPLUS
233
+ { |_, a| [:uplus, a] }
234
+ | MINUS function.body.expression %prec UMINUS
235
+ { |_, a| [:uminus, a] }
236
+ function.body.literal: NUMBER | FLOAT | DOUBLE | UNUMBER
237
+ | SNUMBER | USNUMBER | LNUMBER | ULNUMBER
238
+ | LLNUMBER | ULLNUMBER | CHARACTER
239
+ | function.body.string
240
+ function.body.string: function.body.string STRING
241
+ { |a, b| a << b }
242
+ | STRING
243
+ { |a| [:strlist, a] }
244
+ function.body.logic: LNOT function.body.expression
245
+ { |_, a| [:lnot, a] }
246
+ | BNOT function.body.expression
247
+ { |_, a| [:bnot, a] }
248
+ | function.body.expression LBRK
249
+ function.body.expression
250
+ { |a, _, b| [:lt, a, b] }
251
+ | function.body.expression RBRK
252
+ function.body.expression
253
+ { |a, _, b| [:gt, a, b] }
254
+ | function.body.expression LBRK
255
+ EQUALS function.body.expression
256
+ { |a, _, b| [:lte, a, b] }
257
+ | function.body.expression RBRK
258
+ EQUALS function.body.expression
259
+ { |a, _, b| [:gte, a, b] }
260
+ | function.body.expression COMP
261
+ function.body.expression
262
+ { |a, _, b| [:comp, a, b] }
263
+ | function.body.expression NCMP
264
+ function.body.expression
265
+ { |a, _, b| [:ncmp, a, b] }
266
+ | function.body.expression LAND
267
+ function.body.expression
268
+ { |a, _, b| [:land, a, b] }
269
+ | function.body.expression AMBER
270
+ function.body.expression %prec BAND
271
+ { |a, _, b| [:band, a, b] }
272
+ | function.body.expression LOR
273
+ function.body.expression
274
+ { |a, _, b| [:lor, a, b] }
275
+ | function.body.expression BOR
276
+ function.body.expression
277
+ { |a, _, b| [:bor, a, b] }
278
+ function.body.call.arguments.maybe: function.body.call.arguments
279
+ | nothing
280
+ function.body.call.arguments: function.body.call.arguments COMMA
281
+ function.body.call.argument
282
+ { |a, _, b| a << b }
283
+ | function.body.call.argument
284
+ { |a| [a] }
285
+ function.body.call.argument: function.body.expression
286
+
287
+ function.body.control: control.if
288
+ | control.while
289
+ | control.for
290
+ | control.goto
291
+ | control.label
292
+ | control.return
293
+ | CONTINUE
294
+ { [:continue] }
295
+ | BREAK
296
+ { [:break] }
297
+
298
+ control.if: IF LPAREN function.body.expression RPAREN control.block
299
+ control.if.cont
300
+ { |_, _, a, _, b, c| [:if, a, b, c] }
301
+ control.if.cont: ELSE IF LPAREN function.body.expression RPAREN
302
+ control.block control.if.cont
303
+ { |_, _, _, a, _, b, c| [:elif, a, b, c] }
304
+ | ELSE control.block
305
+ { |_, a| [:else, a] }
306
+ control.while: WHILE LPAREN function.body.expression RPAREN
307
+ control.block
308
+ { |_, _, a, _, b| [:while, a, b] }
309
+ | DO control.block WHILE LPAREN function.body.expression
310
+ { |_, b, _, _, a| [:rwhile, a, b] }
311
+ control.for: FOR LPAREN control.for.compound SEMICOLON
312
+ function.body.expression SEMICOLON control.for.compound
313
+ RPAREN control.block
314
+ { |_, _, a, _, b, _, c, _, d| [:for, a, b, c, d] }
315
+ # for now, ignore a comma-seperated list
316
+ control.for.compound: function.body.expression
317
+ control.goto: GOTO IDENTIFIER
318
+ { |_, a| [:goto, a] }
319
+ control.label: LABEL IDENTIFIER COLON function.body.expression
320
+ { |_, a, _, b| [:label, a, b] }
321
+ control.return: RETURN function.body.expression
322
+ { |_, a| [:return, a] }
323
+ | RETURN SEMICOLON
324
+ { [:return] }
325
+ control.block: function.body.expression
326
+ | LBRACE function.body RBRACE
327
+
328
+ typedef: typedef.type | typedef.func
329
+
330
+ # newtype: oldtype
331
+ typedef.type: TYPEDEF class.name COLON type SEMICOLON
332
+ { |_, a, _, b, _| [:type, a, b] }
333
+ typedef.func: TYPEDEF class.name LPAREN
334
+ function.arguments.maybe RPAREN COLON type SEMICOLON
335
+ { |*a| [:typefn, a[1], a[3], a[6]] }
336
+ | TYPEDEF class.name CARET LPAREN
337
+ function.arguments.maybe RPAREN COLON type SEMICOLON
338
+ { |*a| [:typefnp, a[1], a[4], a[7]] }
339
+ %%
340
+
341
+ module Salt
342
+ class Parser
343
+ %{write}
344
+
345
+ def self.parse(tokens)
346
+ new.parse(tokens)
347
+ end
348
+
349
+ def type(token)
350
+ token.type
351
+ end
352
+ end
353
+ end