code-ruby 2.0.2 → 3.0.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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/VERSION +1 -1
  4. data/lib/code/format.rb +4 -2
  5. data/lib/code/parser.rb +1113 -6
  6. data/lib/code-ruby.rb +0 -1
  7. data/spec/code/node/call_spec.rb +1 -1
  8. data/spec/code/parser/boolean_spec.rb +1 -1
  9. data/spec/code/parser/chained_call_spec.rb +1 -1
  10. data/spec/code/parser/dictionary_spec.rb +1 -1
  11. data/spec/code/parser/function_spec.rb +1 -1
  12. data/spec/code/parser/group_spec.rb +1 -1
  13. data/spec/code/parser/if_modifier_spec.rb +1 -1
  14. data/spec/code/parser/list_spec.rb +1 -1
  15. data/spec/code/parser/number_spec.rb +1 -1
  16. data/spec/code/parser/string_spec.rb +1 -1
  17. data/spec/code_spec.rb +1 -1
  18. metadata +1 -42
  19. data/lib/code/parser/addition.rb +0 -23
  20. data/lib/code/parser/and_operator.rb +0 -19
  21. data/lib/code/parser/bitwise_and.rb +0 -23
  22. data/lib/code/parser/bitwise_or.rb +0 -23
  23. data/lib/code/parser/boolean.rb +0 -23
  24. data/lib/code/parser/call.rb +0 -165
  25. data/lib/code/parser/chained_call.rb +0 -31
  26. data/lib/code/parser/class.rb +0 -15
  27. data/lib/code/parser/code.rb +0 -27
  28. data/lib/code/parser/dictionary.rb +0 -76
  29. data/lib/code/parser/equal.rb +0 -67
  30. data/lib/code/parser/equality.rb +0 -42
  31. data/lib/code/parser/function.rb +0 -135
  32. data/lib/code/parser/greater.rb +0 -32
  33. data/lib/code/parser/group.rb +0 -58
  34. data/lib/code/parser/if.rb +0 -101
  35. data/lib/code/parser/if_modifier.rb +0 -39
  36. data/lib/code/parser/label_name.rb +0 -14
  37. data/lib/code/parser/left_operation.rb +0 -44
  38. data/lib/code/parser/list.rb +0 -47
  39. data/lib/code/parser/multiplication.rb +0 -39
  40. data/lib/code/parser/name.rb +0 -188
  41. data/lib/code/parser/negation.rb +0 -32
  42. data/lib/code/parser/not_keyword.rb +0 -29
  43. data/lib/code/parser/nothing.rb +0 -19
  44. data/lib/code/parser/number.rb +0 -156
  45. data/lib/code/parser/or_keyword.rb +0 -27
  46. data/lib/code/parser/or_operator.rb +0 -19
  47. data/lib/code/parser/power.rb +0 -19
  48. data/lib/code/parser/range.rb +0 -19
  49. data/lib/code/parser/rescue.rb +0 -19
  50. data/lib/code/parser/right_operation.rb +0 -44
  51. data/lib/code/parser/shift.rb +0 -23
  52. data/lib/code/parser/splat.rb +0 -33
  53. data/lib/code/parser/square_bracket.rb +0 -44
  54. data/lib/code/parser/statement.rb +0 -11
  55. data/lib/code/parser/string.rb +0 -85
  56. data/lib/code/parser/ternary.rb +0 -45
  57. data/lib/code/parser/unary_minus.rb +0 -33
  58. data/lib/code/parser/while.rb +0 -81
  59. data/lib/code/parser/whitespace.rb +0 -51
data/lib/code-ruby.rb CHANGED
@@ -8,7 +8,6 @@ require "date"
8
8
  require "did_you_mean"
9
9
  require "digest"
10
10
  require "json"
11
- require "language-ruby"
12
11
  require "mail"
13
12
  require "net/http"
14
13
  require "nokogiri"
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- RSpec.describe Code::Parser::Call do
5
+ RSpec.describe "parser call" do
6
6
  [
7
7
  "f(end: 2)"
8
8
  ].each do |input|
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- RSpec.describe Code::Parser::Boolean do
5
+ RSpec.describe "parser boolean" do
6
6
  [%w[true !false], %w[false !true]].each do |input, expected|
7
7
  it "#{input} == #{expected}" do
8
8
  expect(Code.evaluate(input)).to eq(Code.evaluate(expected))
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- RSpec.describe Code::Parser::ChainedCall do
5
+ RSpec.describe "parser chained call" do
6
6
  [
7
7
  "a.b",
8
8
  "user.first_name",
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- RSpec.describe Code::Parser::Dictionary do
5
+ RSpec.describe "parser dictionary" do
6
6
  [
7
7
  "{}",
8
8
  "{ }",
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- RSpec.describe Code::Parser::Function do
5
+ RSpec.describe "parser function" do
6
6
  [
7
7
  "() => {}",
8
8
  "(a, b) => { add(a, b) }",
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- RSpec.describe Code::Parser::Group do
5
+ RSpec.describe "parser group" do
6
6
  ["(true (nothing))"].each do |input|
7
7
  it "parses #{input}" do
8
8
  Code::Parser.parse(input)
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- RSpec.describe Code::Parser::IfModifier do
5
+ RSpec.describe "parser if modifier" do
6
6
  [
7
7
  ["1 if true", "1"],
8
8
  ["1 if false", "nothing"],
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- RSpec.describe Code::Parser::List do
5
+ RSpec.describe "parser list" do
6
6
  [
7
7
  "[]",
8
8
  "[ ]",
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- RSpec.describe Code::Parser::Number do
5
+ RSpec.describe "parser number" do
6
6
  %w[0 1 1.1 123.123 1_000.12_244 0xf0 0o70 0b10].each do |input|
7
7
  it "parses #{input}" do
8
8
  Code::Parser.parse(input)
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- RSpec.describe Code::Parser::String do
5
+ RSpec.describe "parser string" do
6
6
  [
7
7
  "''",
8
8
  '""',
data/spec/code_spec.rb CHANGED
@@ -344,6 +344,7 @@ RSpec.describe Code do
344
344
  ["a = 1 a += 1 a", "2"],
345
345
  ["a = 1 a -= 1 a", "0"],
346
346
  ["a = 3 a -= 1 if false a", "3"],
347
+ ["a = 1 a = - 1 if false a", "1"],
347
348
  ["a = 3\n(a -= 1) if false\na", "3"],
348
349
  ["a = 1 a /= 2 a", "0.5"],
349
350
  ["a = 1 a <<= 1 a", "2"],
@@ -485,7 +486,6 @@ RSpec.describe Code do
485
486
  ["", ""]
486
487
  ].each do |input, expected|
487
488
  it "#{input} == #{expected}" do
488
- puts input
489
489
  formatted = format_input(input)
490
490
 
491
491
  output = StringIO.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
@@ -289,47 +289,6 @@ files:
289
289
  - lib/code/object/time.rb
290
290
  - lib/code/object/url.rb
291
291
  - lib/code/parser.rb
292
- - lib/code/parser/addition.rb
293
- - lib/code/parser/and_operator.rb
294
- - lib/code/parser/bitwise_and.rb
295
- - lib/code/parser/bitwise_or.rb
296
- - lib/code/parser/boolean.rb
297
- - lib/code/parser/call.rb
298
- - lib/code/parser/chained_call.rb
299
- - lib/code/parser/class.rb
300
- - lib/code/parser/code.rb
301
- - lib/code/parser/dictionary.rb
302
- - lib/code/parser/equal.rb
303
- - lib/code/parser/equality.rb
304
- - lib/code/parser/function.rb
305
- - lib/code/parser/greater.rb
306
- - lib/code/parser/group.rb
307
- - lib/code/parser/if.rb
308
- - lib/code/parser/if_modifier.rb
309
- - lib/code/parser/label_name.rb
310
- - lib/code/parser/left_operation.rb
311
- - lib/code/parser/list.rb
312
- - lib/code/parser/multiplication.rb
313
- - lib/code/parser/name.rb
314
- - lib/code/parser/negation.rb
315
- - lib/code/parser/not_keyword.rb
316
- - lib/code/parser/nothing.rb
317
- - lib/code/parser/number.rb
318
- - lib/code/parser/or_keyword.rb
319
- - lib/code/parser/or_operator.rb
320
- - lib/code/parser/power.rb
321
- - lib/code/parser/range.rb
322
- - lib/code/parser/rescue.rb
323
- - lib/code/parser/right_operation.rb
324
- - lib/code/parser/shift.rb
325
- - lib/code/parser/splat.rb
326
- - lib/code/parser/square_bracket.rb
327
- - lib/code/parser/statement.rb
328
- - lib/code/parser/string.rb
329
- - lib/code/parser/ternary.rb
330
- - lib/code/parser/unary_minus.rb
331
- - lib/code/parser/while.rb
332
- - lib/code/parser/whitespace.rb
333
292
  - lib/code/type.rb
334
293
  - lib/code/type/hash.rb
335
294
  - lib/code/type/maybe.rb
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class Addition < LeftOperation
6
- def statement
7
- Multiplication
8
- end
9
-
10
- def plus
11
- str("+")
12
- end
13
-
14
- def minus
15
- str("-")
16
- end
17
-
18
- def operator
19
- plus | minus
20
- end
21
- end
22
- end
23
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class AndOperator < LeftOperation
6
- def statement
7
- Equality
8
- end
9
-
10
- def ampersand
11
- str("&")
12
- end
13
-
14
- def operator
15
- ampersand << ampersand
16
- end
17
- end
18
- end
19
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class BitwiseAnd < LeftOperation
6
- def statement
7
- Shift
8
- end
9
-
10
- def whitespace?
11
- whitespace
12
- end
13
-
14
- def ampersand
15
- str("&")
16
- end
17
-
18
- def operator
19
- ampersand
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class BitwiseOr < LeftOperation
6
- def statement
7
- BitwiseAnd
8
- end
9
-
10
- def pipe
11
- str("|")
12
- end
13
-
14
- def caret
15
- str("^")
16
- end
17
-
18
- def operator
19
- pipe | caret
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class Boolean < Language
6
- def separator
7
- Name.new.separator
8
- end
9
-
10
- def true_keyword
11
- str("true") << separator.present
12
- end
13
-
14
- def false_keyword
15
- str("false") << separator.present
16
- end
17
-
18
- def root
19
- (true_keyword | false_keyword).aka(:boolean) | Nothing
20
- end
21
- end
22
- end
23
- end
@@ -1,165 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class Call < Language
6
- def name
7
- Name
8
- end
9
-
10
- def label_name
11
- LabelName
12
- end
13
-
14
- def whitespace
15
- Whitespace
16
- end
17
-
18
- def whiltespace_without_newline?
19
- Whitespace.new.without_newline.maybe
20
- end
21
-
22
- def whitespace?
23
- whitespace.maybe
24
- end
25
-
26
- def code
27
- Code
28
- end
29
-
30
- def code_present
31
- Code.new.present
32
- end
33
-
34
- def colon
35
- str(":")
36
- end
37
-
38
- def comma
39
- str(",")
40
- end
41
-
42
- def pipe
43
- str("|")
44
- end
45
-
46
- def equal
47
- str("=")
48
- end
49
-
50
- def opening_curly_bracket
51
- str("{")
52
- end
53
-
54
- def closing_curly_bracket
55
- str("}")
56
- end
57
-
58
- def opening_parenthesis
59
- str("(")
60
- end
61
-
62
- def closing_parenthesis
63
- str(")")
64
- end
65
-
66
- def separator
67
- Name.new.separator
68
- end
69
-
70
- def do_keyword
71
- str("do") << separator.present
72
- end
73
-
74
- def begin_keyword
75
- str("do") << separator.present
76
- end
77
-
78
- def end_keyword
79
- str("end") << separator.present
80
- end
81
-
82
- def asterisk
83
- str("*")
84
- end
85
-
86
- def ampersand
87
- str("&")
88
- end
89
-
90
- def spread_operator
91
- str("...") | str("..") | str(".")
92
- end
93
-
94
- def keyword_argument
95
- label_name.aka(:name) << whitespace? << colon << code.aka(:value)
96
- end
97
-
98
- def regular_argument
99
- code_present.aka(:value)
100
- end
101
-
102
- def argument
103
- keyword_argument | regular_argument
104
- end
105
-
106
- def arguments
107
- opening_parenthesis.ignore << whitespace? <<
108
- (
109
- whitespace? << argument <<
110
- (whitespace? << comma << whitespace?).maybe
111
- ).repeat << whitespace? << closing_parenthesis.ignore.maybe
112
- end
113
-
114
- def prefix
115
- (asterisk << asterisk).aka(:keyword_splat) |
116
- asterisk.aka(:regular_splat) | ampersand.aka(:block) |
117
- spread_operator.aka(:spread)
118
- end
119
-
120
- def keyword_parameter
121
- label_name.aka(:name) << whitespace? << colon.aka(:keyword) <<
122
- code_present.aka(:default).maybe
123
- end
124
-
125
- def regular_parameter
126
- ((prefix.maybe << name.aka(:name)) | prefix) << whitespace? <<
127
- (equal << whitespace? << code_present.aka(:default)).maybe
128
- end
129
-
130
- def parameter
131
- keyword_parameter | regular_parameter
132
- end
133
-
134
- def parameters
135
- pipe.ignore << whitespace? <<
136
- (
137
- whitespace? << parameter <<
138
- (whitespace? << comma << whitespace?).maybe
139
- ).repeat << (whitespace? << pipe.ignore).maybe
140
- end
141
-
142
- def block
143
- (
144
- (do_keyword | begin_keyword).ignore << whitespace <<
145
- parameters.aka(:parameters).maybe << whitespace? <<
146
- code.aka(:body) << (whitespace? << end_keyword).maybe.ignore
147
- ) |
148
- (
149
- opening_curly_bracket.ignore << whitespace? <<
150
- parameters.aka(:parameters).maybe << whitespace? <<
151
- code.aka(:body) <<
152
- (whitespace? << closing_curly_bracket).maybe.ignore
153
- )
154
- end
155
-
156
- def root
157
- (
158
- name.aka(:name) <<
159
- (whiltespace_without_newline? << arguments.aka(:arguments)).maybe <<
160
- (whiltespace_without_newline? << block.aka(:block)).maybe
161
- ).aka(:call)
162
- end
163
- end
164
- end
165
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class ChainedCall < LeftOperation
6
- def statement
7
- SquareBracket
8
- end
9
-
10
- def dot
11
- str(".")
12
- end
13
-
14
- def ampersand
15
- str("&")
16
- end
17
-
18
- def colon
19
- str(":")
20
- end
21
-
22
- def right_statement
23
- ChainedCall
24
- end
25
-
26
- def operator
27
- dot | (colon << colon) | (ampersand << dot)
28
- end
29
- end
30
- end
31
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class Class < Language
6
- def statement
7
- While
8
- end
9
-
10
- def root
11
- statement
12
- end
13
- end
14
- end
15
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class Code < Language
6
- def whitespace
7
- Whitespace
8
- end
9
-
10
- def whitespace?
11
- whitespace.maybe
12
- end
13
-
14
- def statement
15
- Statement
16
- end
17
-
18
- def present
19
- (whitespace? << statement << whitespace?).repeat(1)
20
- end
21
-
22
- def root
23
- present | whitespace?
24
- end
25
- end
26
- end
27
- end
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class Dictionary < Language
6
- def code_present
7
- Code.new.present
8
- end
9
-
10
- def statement
11
- Statement
12
- end
13
-
14
- def name
15
- Name
16
- end
17
-
18
- def label_name
19
- LabelName
20
- end
21
-
22
- def whitespace
23
- Whitespace
24
- end
25
-
26
- def whitespace?
27
- whitespace.maybe
28
- end
29
-
30
- def opening_curly_bracket
31
- str("{")
32
- end
33
-
34
- def closing_curly_bracket
35
- str("}")
36
- end
37
-
38
- def comma
39
- str(",")
40
- end
41
-
42
- def colon
43
- str(":")
44
- end
45
-
46
- def equal
47
- str("=")
48
- end
49
-
50
- def greater
51
- str(">")
52
- end
53
-
54
- def key_value
55
- (label_name.aka(:name) << colon << code_present.aka(:code).maybe).aka(
56
- :name_code
57
- ) |
58
- (
59
- statement.aka(:statement) << colon << code_present.aka(:code).maybe
60
- ).aka(:statement_code) |
61
- (
62
- statement.aka(:statement) << whitespace? << equal << greater <<
63
- code_present.aka(:code).maybe
64
- ).aka(:statement_code) | code_present.aka(:code)
65
- end
66
-
67
- def root
68
- (
69
- opening_curly_bracket.ignore << whitespace? <<
70
- (whitespace? << key_value << (whitespace? << comma).maybe).repeat <<
71
- (whitespace? << closing_curly_bracket.ignore).maybe
72
- ).aka(:dictionnary) | List
73
- end
74
- end
75
- end
76
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class Equal < RightOperation
6
- def statement
7
- Rescue
8
- end
9
-
10
- def equal
11
- str("=")
12
- end
13
-
14
- def plus
15
- str("+")
16
- end
17
-
18
- def minus
19
- str("-")
20
- end
21
-
22
- def asterisk
23
- str("*")
24
- end
25
-
26
- def slash
27
- str("/")
28
- end
29
-
30
- def percent
31
- str("%")
32
- end
33
-
34
- def greater
35
- str(">")
36
- end
37
-
38
- def lesser
39
- str("<")
40
- end
41
-
42
- def ampersand
43
- str("&")
44
- end
45
-
46
- def pipe
47
- str("|")
48
- end
49
-
50
- def caret
51
- str("^")
52
- end
53
-
54
- def right_statement
55
- Statement
56
- end
57
-
58
- def operator
59
- equal | (plus << equal) | (minus << equal) | (asterisk << equal) |
60
- (slash << equal) | (percent << equal) |
61
- (greater << greater << equal) | (lesser << lesser << equal) |
62
- (ampersand << equal) | (pipe << equal) | (caret << equal) |
63
- (pipe << pipe << equal) | (ampersand << ampersand << equal)
64
- end
65
- end
66
- end
67
- end