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
@@ -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,135 +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 label_name
11
- LabelName
12
- end
13
-
14
- def code
15
- Code
16
- end
17
-
18
- def code_present
19
- Code.new.present
20
- end
21
-
22
- def whitespace
23
- Whitespace
24
- end
25
-
26
- def whitespace?
27
- whitespace.maybe
28
- end
29
-
30
- def separator
31
- Name.new.separator
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 end_keyword
43
- str("end") << separator.present
44
- end
45
-
46
- def spread_operator
47
- str("...") | str("..") | str(".")
48
- end
49
-
50
- def opening_parenthesis
51
- str("(")
52
- end
53
-
54
- def closing_parenthesis
55
- str(")")
56
- end
57
-
58
- def colon
59
- str(":")
60
- end
61
-
62
- def comma
63
- str(",")
64
- end
65
-
66
- def equal
67
- str("=")
68
- end
69
-
70
- def greater
71
- str(">")
72
- end
73
-
74
- def opening_curly_bracket
75
- str("{")
76
- end
77
-
78
- def closing_curly_bracket
79
- str("}")
80
- end
81
-
82
- def asterisk
83
- str("*")
84
- end
85
-
86
- def ampersand
87
- str("&")
88
- end
89
-
90
- def prefix
91
- (asterisk << asterisk).aka(:keyword_splat) |
92
- asterisk.aka(:regular_splat) | ampersand.aka(:block) |
93
- spread_operator.aka(:spread)
94
- end
95
-
96
- def keyword_parameter
97
- label_name.aka(:name) << whitespace? << colon.aka(:keyword) <<
98
- code_present.aka(:default).maybe
99
- end
100
-
101
- def regular_parameter
102
- ((prefix.maybe << name.aka(:name)) | prefix) << whitespace? <<
103
- (equal << whitespace? << code_present.aka(:default)).maybe
104
- end
105
-
106
- def parameter
107
- keyword_parameter | regular_parameter
108
- end
109
-
110
- def parameters
111
- opening_parenthesis.ignore << whitespace? <<
112
- (whitespace? << parameter << (whitespace? << comma).maybe).repeat <<
113
- (whitespace? << closing_parenthesis.ignore).maybe
114
- end
115
-
116
- def body
117
- (
118
- (begin_keyword | do_keyword).ignore << whitespace << code <<
119
- (whitespace? << end_keyword).maybe.ignore
120
- ) |
121
- (
122
- opening_curly_bracket.ignore << whitespace? << code <<
123
- (whitespace? << closing_curly_bracket).maybe.ignore
124
- ) | (code << (whitespace? << end_keyword).maybe.ignore)
125
- end
126
-
127
- def root
128
- (
129
- parameters.aka(:parameters) << whitespace? << equal << greater <<
130
- whitespace? << body.aka(:body)
131
- ).aka(:function) | Dictionary
132
- end
133
- end
134
- end
135
- 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,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Code
4
- class Parser
5
- class LabelName < Name
6
- def root
7
- (
8
- (special_name << separator.ignore) |
9
- (special_characters.absent << character.repeat(1))
10
- )
11
- end
12
- end
13
- end
14
- 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