code-ruby 2.0.1 → 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 (58) 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 +10 -0
  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 +3 -2
  11. data/spec/code/parser/function_spec.rb +3 -2
  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 +2 -1
  18. metadata +1 -41
  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 -161
  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 -72
  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 -131
  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/left_operation.rb +0 -44
  37. data/lib/code/parser/list.rb +0 -47
  38. data/lib/code/parser/multiplication.rb +0 -39
  39. data/lib/code/parser/name.rb +0 -188
  40. data/lib/code/parser/negation.rb +0 -32
  41. data/lib/code/parser/not_keyword.rb +0 -29
  42. data/lib/code/parser/nothing.rb +0 -19
  43. data/lib/code/parser/number.rb +0 -156
  44. data/lib/code/parser/or_keyword.rb +0 -27
  45. data/lib/code/parser/or_operator.rb +0 -19
  46. data/lib/code/parser/power.rb +0 -19
  47. data/lib/code/parser/range.rb +0 -19
  48. data/lib/code/parser/rescue.rb +0 -19
  49. data/lib/code/parser/right_operation.rb +0 -44
  50. data/lib/code/parser/shift.rb +0 -23
  51. data/lib/code/parser/splat.rb +0 -33
  52. data/lib/code/parser/square_bracket.rb +0 -44
  53. data/lib/code/parser/statement.rb +0 -11
  54. data/lib/code/parser/string.rb +0 -81
  55. data/lib/code/parser/ternary.rb +0 -45
  56. data/lib/code/parser/unary_minus.rb +0 -33
  57. data/lib/code/parser/while.rb +0 -81
  58. data/lib/code/parser/whitespace.rb +0 -51
@@ -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
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class Equality < LeftOperation
6
- def statement
7
- Greater
8
- end
9
-
10
- def equal
11
- str("=")
12
- end
13
-
14
- def greater
15
- str(">")
16
- end
17
-
18
- def lesser
19
- str("<")
20
- end
21
-
22
- def exclamation_mark
23
- str("!")
24
- end
25
-
26
- def tilde
27
- str("~")
28
- end
29
-
30
- def right_statement
31
- Greater
32
- end
33
-
34
- def operator
35
- (exclamation_mark << equal << equal) | (equal << equal << equal) |
36
- (equal << equal) | (lesser << equal << greater) |
37
- (exclamation_mark << equal) | (equal << tilde) | (tilde << equal) |
38
- (exclamation_mark << tilde)
39
- end
40
- end
41
- end
42
- end
@@ -1,131 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class Function < Language
6
- def name
7
- Name
8
- end
9
-
10
- def code
11
- Code
12
- end
13
-
14
- def code_present
15
- Code.new.present
16
- end
17
-
18
- def whitespace
19
- Whitespace
20
- end
21
-
22
- def whitespace?
23
- whitespace.maybe
24
- end
25
-
26
- def separator
27
- Name.new.separator
28
- end
29
-
30
- def do_keyword
31
- str("do") << separator.present
32
- end
33
-
34
- def begin_keyword
35
- str("begin") << separator.present
36
- end
37
-
38
- def end_keyword
39
- str("end") << separator.present
40
- end
41
-
42
- def spread_operator
43
- str("...") | str("..") | str(".")
44
- end
45
-
46
- def opening_parenthesis
47
- str("(")
48
- end
49
-
50
- def closing_parenthesis
51
- str(")")
52
- end
53
-
54
- def colon
55
- str(":")
56
- end
57
-
58
- def comma
59
- str(",")
60
- end
61
-
62
- def equal
63
- str("=")
64
- end
65
-
66
- def greater
67
- str(">")
68
- end
69
-
70
- def opening_curly_bracket
71
- str("{")
72
- end
73
-
74
- def closing_curly_bracket
75
- str("}")
76
- end
77
-
78
- def asterisk
79
- str("*")
80
- end
81
-
82
- def ampersand
83
- str("&")
84
- end
85
-
86
- def prefix
87
- (asterisk << asterisk).aka(:keyword_splat) |
88
- asterisk.aka(:regular_splat) | ampersand.aka(:block) |
89
- spread_operator.aka(:spread)
90
- end
91
-
92
- def keyword_parameter
93
- name.aka(:name) << whitespace? << colon.aka(:keyword) <<
94
- code_present.aka(:default).maybe
95
- end
96
-
97
- def regular_parameter
98
- ((prefix.maybe << name.aka(:name)) | prefix) << whitespace? <<
99
- (equal << whitespace? << code_present.aka(:default)).maybe
100
- end
101
-
102
- def parameter
103
- keyword_parameter | regular_parameter
104
- end
105
-
106
- def parameters
107
- opening_parenthesis.ignore << whitespace? <<
108
- (whitespace? << parameter << (whitespace? << comma).maybe).repeat <<
109
- (whitespace? << closing_parenthesis.ignore).maybe
110
- end
111
-
112
- def body
113
- (
114
- (begin_keyword | do_keyword).ignore << whitespace << code <<
115
- (whitespace? << end_keyword).maybe.ignore
116
- ) |
117
- (
118
- opening_curly_bracket.ignore << whitespace? << code <<
119
- (whitespace? << closing_curly_bracket).maybe.ignore
120
- ) | (code << (whitespace? << end_keyword).maybe.ignore)
121
- end
122
-
123
- def root
124
- (
125
- parameters.aka(:parameters) << whitespace? << equal << greater <<
126
- whitespace? << body.aka(:body)
127
- ).aka(:function) | Dictionary
128
- end
129
- end
130
- end
131
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class Greater < LeftOperation
6
- def statement
7
- BitwiseOr
8
- end
9
-
10
- def right_statement
11
- Greater
12
- end
13
-
14
- def greater
15
- str(">")
16
- end
17
-
18
- def lesser
19
- str("<")
20
- end
21
-
22
- def equal
23
- str("=")
24
- end
25
-
26
- def operator
27
- (greater << equal) | (lesser << equal << greater.absent) |
28
- (greater << equal.absent) | lesser
29
- end
30
- end
31
- end
32
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class Group < Language
6
- def code
7
- Code
8
- end
9
-
10
- def whitespace
11
- Whitespace
12
- end
13
-
14
- def whitespace?
15
- whitespace.maybe
16
- end
17
-
18
- def opening_parenthesis
19
- str("(")
20
- end
21
-
22
- def closing_parenthesis
23
- str(")")
24
- end
25
-
26
- def separator
27
- Name.new.separator
28
- end
29
-
30
- def end_keyword
31
- str("end") << separator.present
32
- end
33
-
34
- def do_keyword
35
- str("do") << separator.present
36
- end
37
-
38
- def begin_keyword
39
- str("begin") << separator.present
40
- end
41
-
42
- def root
43
- (
44
- opening_parenthesis.ignore << whitespace? << code <<
45
- (whitespace? << closing_parenthesis).maybe.ignore
46
- ).aka(:group) |
47
- (
48
- begin_keyword.ignore << whitespace << code <<
49
- (whitespace? << end_keyword).maybe.ignore
50
- ).aka(:group) |
51
- (
52
- do_keyword.ignore << whitespace << code <<
53
- (whitespace? << end_keyword).maybe.ignore
54
- ).aka(:group) | Call
55
- end
56
- end
57
- end
58
- end
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class If < Language
6
- def statement
7
- IfModifier
8
- end
9
-
10
- def if_class
11
- If
12
- end
13
-
14
- def whitespace
15
- Whitespace
16
- end
17
-
18
- def code
19
- Code
20
- end
21
-
22
- def whitespace?
23
- whitespace.maybe
24
- end
25
-
26
- def separator
27
- Name.new.separator
28
- end
29
-
30
- def do_keyword
31
- str("do") << separator.present
32
- end
33
-
34
- def begin_keyword
35
- str("begin") << separator.present
36
- end
37
-
38
- def opening_curly_bracket
39
- str("{")
40
- end
41
-
42
- def closing_curly_bracket
43
- str("}")
44
- end
45
-
46
- def if_keyword
47
- str("if") << separator.present
48
- end
49
-
50
- def unless_keyword
51
- str("unless") << separator.present
52
- end
53
-
54
- def elsif_keyword
55
- str("elsif") << separator.present
56
- end
57
-
58
- def elsunless_keyword
59
- str("elsunless") << separator.present
60
- end
61
-
62
- def else_keyword
63
- str("else") << separator.present
64
- end
65
-
66
- def end_keyword
67
- str("end") << separator.present
68
- end
69
-
70
- def body
71
- (
72
- (begin_keyword | do_keyword).ignore << whitespace << code <<
73
- (whitespace? << end_keyword).maybe.ignore
74
- ) |
75
- (
76
- opening_curly_bracket.ignore << whitespace? << code <<
77
- (whitespace? << closing_curly_bracket).maybe.ignore
78
- ) | (code << (whitespace? << end_keyword).maybe.ignore)
79
- end
80
-
81
- def root
82
- (
83
- (if_keyword | unless_keyword).aka(:first_operator) << whitespace <<
84
- statement.aka(:first_statement) << body.aka(:first_body) <<
85
- (
86
- (
87
- (elsif_keyword | elsunless_keyword).aka(
88
- :operator
89
- ) << whitespace << statement.aka(:statement) << body.aka(:body)
90
- ) |
91
- (
92
- else_keyword << whitespace <<
93
- (if_keyword | unless_keyword).aka(:operator) <<
94
- whitespace << statement.aka(:statement) << body.aka(:body)
95
- ) | (else_keyword.aka(:operator) << body.aka(:body))
96
- ).repeat(1).aka(:elses).maybe << end_keyword.maybe
97
- ).aka(:if) | statement
98
- end
99
- end
100
- end
101
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class IfModifier < RightOperation
6
- def statement
7
- OrKeyword
8
- end
9
-
10
- def whitespace
11
- Whitespace.new.without_newline
12
- end
13
-
14
- def separator
15
- Name.new.separator
16
- end
17
-
18
- def if_keyword
19
- str("if") << separator.present
20
- end
21
-
22
- def unless_keyword
23
- str("unless") << separator.present
24
- end
25
-
26
- def while_keyword
27
- str("while") << separator.present
28
- end
29
-
30
- def until_keyword
31
- str("until") << separator.present
32
- end
33
-
34
- def operator
35
- if_keyword | unless_keyword | while_keyword | until_keyword
36
- end
37
- end
38
- end
39
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class LeftOperation < Language
6
- def statement
7
- Statement
8
- end
9
-
10
- def whitespace
11
- Whitespace
12
- end
13
-
14
- def whitespace?
15
- whitespace.maybe
16
- end
17
-
18
- def operator
19
- str("")
20
- end
21
-
22
- def right_statement
23
- Statement
24
- end
25
-
26
- def root
27
- (
28
- statement.aka(:first) << (
29
- whitespace? << operator.aka(:operator) << whitespace? <<
30
- right_statement.aka(:statement)
31
- ).repeat(1).aka(:others).maybe
32
- )
33
- .aka(:left_operation)
34
- .then do |output|
35
- if output[:left_operation][:others]
36
- output
37
- else
38
- output[:left_operation][:first]
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class List < Language
6
- def code
7
- Code
8
- end
9
-
10
- def code_present
11
- Code.new.present
12
- end
13
-
14
- def whitespace
15
- Whitespace
16
- end
17
-
18
- def whitespace?
19
- whitespace.maybe
20
- end
21
-
22
- def opening_square_bracket
23
- str("[")
24
- end
25
-
26
- def closing_square_bracket
27
- str("]")
28
- end
29
-
30
- def comma
31
- str(",")
32
- end
33
-
34
- def element
35
- (whitespace? << code_present << (whitespace? << comma.ignore).maybe) |
36
- (whitespace? << code << whitespace? << comma.ignore)
37
- end
38
-
39
- def root
40
- (
41
- opening_square_bracket.ignore << whitespace? << element.repeat <<
42
- (whitespace? << closing_square_bracket.ignore).maybe
43
- ).aka(:list) | String
44
- end
45
- end
46
- end
47
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class Multiplication < LeftOperation
6
- def statement
7
- Negation
8
- end
9
-
10
- def asterisk
11
- str("*")
12
- end
13
-
14
- def multiplication_sign
15
- str("×")
16
- end
17
-
18
- def slash
19
- str("/")
20
- end
21
-
22
- def percent
23
- str("%")
24
- end
25
-
26
- def division_sign
27
- str("÷")
28
- end
29
-
30
- def right_statement
31
- Negation
32
- end
33
-
34
- def operator
35
- asterisk | slash | percent | multiplication_sign | division_sign
36
- end
37
- end
38
- end
39
- end