code-ruby 0.5.6 → 0.6.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.
- checksums.yaml +4 -4
- data/Gemfile +1 -4
- data/Gemfile.lock +10 -22
- data/code-ruby.gemspec +4 -3
- data/lib/code/error.rb +16 -5
- data/lib/code/node/base_10.rb +4 -2
- data/lib/code/node/base_16.rb +3 -1
- data/lib/code/node/base_2.rb +3 -1
- data/lib/code/node/base_8.rb +3 -1
- data/lib/code/node/boolean.rb +4 -2
- data/lib/code/node/call.rb +35 -12
- data/lib/code/node/call_argument.rb +16 -5
- data/lib/code/node/code.rb +5 -4
- data/lib/code/node/decimal.rb +2 -0
- data/lib/code/node/{dictionnary.rb → dictionary.rb} +14 -5
- data/lib/code/node/function.rb +7 -4
- data/lib/code/node/function_parameter.rb +3 -1
- data/lib/code/node/if.rb +5 -3
- data/lib/code/node/left_operation.rb +63 -0
- data/lib/code/node/list.rb +2 -0
- data/lib/code/node/negation.rb +2 -0
- data/lib/code/node/not.rb +2 -0
- data/lib/code/node/nothing.rb +3 -1
- data/lib/code/node/number.rb +2 -0
- data/lib/code/node/right_operation.rb +70 -0
- data/lib/code/node/splat.rb +2 -0
- data/lib/code/node/square_bracket.rb +37 -0
- data/lib/code/node/statement.rb +13 -5
- data/lib/code/node/string.rb +3 -1
- data/lib/code/node/ternary.rb +5 -3
- data/lib/code/node/unary_minus.rb +2 -0
- data/lib/code/node/while.rb +6 -4
- data/lib/code/node.rb +11 -5
- data/lib/code/object/argument.rb +13 -7
- data/lib/code/object/boolean.rb +43 -5
- data/lib/code/object/class.rb +17 -0
- data/lib/code/object/context.rb +36 -0
- data/lib/code/object/decimal.rb +252 -100
- data/lib/code/object/dictionary.rb +641 -0
- data/lib/code/object/function.rb +54 -27
- data/lib/code/object/global.rb +65 -19
- data/lib/code/object/identifier_list.rb +47 -0
- data/lib/code/object/integer.rb +320 -137
- data/lib/code/object/list.rb +140 -138
- data/lib/code/object/nothing.rb +10 -4
- data/lib/code/object/number.rb +6 -1
- data/lib/code/object/range.rb +85 -88
- data/lib/code/object/ruby_function.rb +11 -6
- data/lib/code/object/string.rb +51 -48
- data/lib/code/object.rb +117 -139
- data/lib/code/parser/addition.rb +4 -2
- data/lib/code/parser/and_operator.rb +4 -2
- data/lib/code/parser/bitwise_and.rb +4 -2
- data/lib/code/parser/bitwise_or.rb +4 -2
- data/lib/code/parser/boolean.rb +3 -1
- data/lib/code/parser/call.rb +17 -11
- data/lib/code/parser/chained_call.rb +10 -22
- data/lib/code/parser/class.rb +9 -6
- data/lib/code/parser/code.rb +6 -4
- data/lib/code/parser/{dictionnary.rb → dictionary.rb} +16 -13
- data/lib/code/parser/equal.rb +9 -36
- data/lib/code/parser/equality.rb +4 -2
- data/lib/code/parser/function.rb +24 -9
- data/lib/code/parser/greater.rb +6 -3
- data/lib/code/parser/group.rb +4 -2
- data/lib/code/parser/if.rb +6 -4
- data/lib/code/parser/if_modifier.rb +5 -25
- data/lib/code/parser/left_operation.rb +40 -0
- data/lib/code/parser/list.rb +6 -5
- data/lib/code/parser/multiplication.rb +4 -2
- data/lib/code/parser/name.rb +19 -4
- data/lib/code/parser/negation.rb +4 -2
- data/lib/code/parser/not_keyword.rb +5 -3
- data/lib/code/parser/nothing.rb +3 -10
- data/lib/code/parser/number.rb +4 -2
- data/lib/code/parser/or_keyword.rb +4 -2
- data/lib/code/parser/or_operator.rb +4 -2
- data/lib/code/parser/power.rb +4 -28
- data/lib/code/parser/range.rb +4 -2
- data/lib/code/parser/rescue.rb +6 -26
- data/lib/code/parser/right_operation.rb +40 -0
- data/lib/code/parser/shift.rb +4 -2
- data/lib/code/parser/splat.rb +5 -3
- data/lib/code/parser/square_bracket.rb +48 -0
- data/lib/code/parser/statement.rb +3 -1
- data/lib/code/parser/string.rb +12 -10
- data/lib/code/parser/ternary.rb +10 -11
- data/lib/code/parser/unary_minus.rb +5 -3
- data/lib/code/parser/while.rb +5 -3
- data/lib/code/parser/whitespace.rb +2 -0
- data/lib/code/parser.rb +10 -3
- data/lib/code/ruby.rb +4 -2
- data/lib/code/type/hash.rb +38 -0
- data/lib/code/type/maybe.rb +29 -0
- data/lib/code/type/or.rb +38 -0
- data/lib/code/type/repeat.rb +38 -0
- data/lib/code/type/sig.rb +130 -0
- data/lib/code/type.rb +25 -0
- data/lib/code/version.rb +3 -0
- data/lib/code-ruby.rb +1 -2
- data/lib/code.rb +15 -16
- data/spec/code/node/call_spec.rb +39 -0
- data/spec/code/object/boolean_spec.rb +18 -0
- data/spec/code/object/decimal_spec.rb +51 -0
- data/spec/code/object/dictionary_spec.rb +98 -0
- data/spec/code/object/function_spec.rb +42 -0
- data/spec/code/object/integer_spec.rb +43 -0
- data/spec/code/object/nothing_spec.rb +14 -0
- data/spec/code/object/range_spec.rb +23 -0
- data/spec/code/parser/boolean_spec.rb +5 -10
- data/spec/code/parser/chained_call.rb +4 -5
- data/spec/code/parser/{dictionnary_spec.rb → dictionary_spec.rb} +5 -6
- data/spec/code/parser/function_spec.rb +4 -5
- data/spec/code/parser/group_spec.rb +5 -12
- data/spec/code/parser/if_modifier_spec.rb +18 -0
- data/spec/code/parser/list_spec.rb +4 -5
- data/spec/code/parser/number_spec.rb +4 -5
- data/spec/code/parser/string_spec.rb +4 -5
- data/spec/code/parser_spec.rb +22 -16
- data/spec/code/type_spec.rb +21 -0
- data/spec/code_spec.rb +171 -0
- data/spec/spec_helper.rb +1 -6
- metadata +61 -137
- data/.cherry.js +0 -21
- data/.editorconfig +0 -9
- data/.github/workflows/rspec.yml +0 -14
- data/.gitignore +0 -2
- data/.prettierrc +0 -3
- data/.tool-versions +0 -1
- data/CHANGELOG.md +0 -55
- data/LICENSE +0 -7
- data/README.md +0 -103
- data/TODO +0 -17
- data/bin/code +0 -76
- data/bin/format +0 -3
- data/bin/publish +0 -19
- data/bin/template +0 -85
- data/bin/test +0 -17
- data/docs/class.code +0 -9
- data/docs/euler/1.template +0 -10
- data/docs/euler/2.template +0 -16
- data/docs/euler/3.template +0 -16
- data/docs/euler/4.template +0 -10
- data/docs/euler/5.template +0 -13
- data/docs/fibonnaci.template +0 -14
- data/docs/meetup.code +0 -12
- data/docs/precedence.template +0 -36
- data/docs/rain.code +0 -22
- data/docs/slack.code +0 -17
- data/docs/stripe.code +0 -7
- data/docs/twitter.code +0 -9
- data/language-ruby.gemspec +0 -17
- data/lib/code/node/chained_call.rb +0 -23
- data/lib/code/node/equal.rb +0 -34
- data/lib/code/node/if_modifier.rb +0 -47
- data/lib/code/node/operation.rb +0 -38
- data/lib/code/node/power.rb +0 -20
- data/lib/code/node/rescue.rb +0 -17
- data/lib/code/object/dictionnary.rb +0 -96
- data/lib/code/parser/equality_lower.rb +0 -9
- data/lib/code/parser/operation.rb +0 -35
- data/lib/language/atom.rb +0 -342
- data/lib/language/output.rb +0 -130
- data/lib/language/parser/absent/present.rb +0 -8
- data/lib/language/parser/absent.rb +0 -6
- data/lib/language/parser/end_of_input.rb +0 -6
- data/lib/language/parser/interuption.rb +0 -38
- data/lib/language/parser/not_end_of_input.rb +0 -6
- data/lib/language/parser/str/not_found.rb +0 -16
- data/lib/language/parser/str.rb +0 -6
- data/lib/language/parser.rb +0 -53
- data/lib/language-ruby.rb +0 -10
- data/lib/language.rb +0 -80
- data/lib/template/node/code_part.rb +0 -13
- data/lib/template/node/part.rb +0 -19
- data/lib/template/node/template.rb +0 -15
- data/lib/template/node/text_part.rb +0 -13
- data/lib/template/node.rb +0 -4
- data/lib/template/parser/template.rb +0 -39
- data/lib/template/parser.rb +0 -19
- data/lib/template/version.rb +0 -3
- data/lib/template-ruby.rb +0 -10
- data/lib/template.rb +0 -50
- data/spec/code/addition_spec.rb +0 -13
- data/spec/code/and_operator_spec.rb +0 -13
- data/spec/code/bitwise_and_spec.rb +0 -13
- data/spec/code/bitwise_or_spec.rb +0 -13
- data/spec/code/boolean_spec.rb +0 -13
- data/spec/code/call_spec.rb +0 -21
- data/spec/code/chained_call_spec.rb +0 -16
- data/spec/code/code_spec.rb +0 -29
- data/spec/code/dictionnary_spec.rb +0 -17
- data/spec/code/equal_spec.rb +0 -26
- data/spec/code/equality_spec.rb +0 -13
- data/spec/code/function_spec.rb +0 -18
- data/spec/code/greater_spec.rb +0 -18
- data/spec/code/group_spec.rb +0 -12
- data/spec/code/if_modifier_spec.rb +0 -20
- data/spec/code/if_spec.rb +0 -25
- data/spec/code/list_spec.rb +0 -19
- data/spec/code/multiplication_spec.rb +0 -18
- data/spec/code/negation_spec.rb +0 -20
- data/spec/code/not_keyword_spec.rb +0 -13
- data/spec/code/nothing_spec.rb +0 -17
- data/spec/code/number_spec.rb +0 -22
- data/spec/code/or_keyword_spec.rb +0 -17
- data/spec/code/or_operator_spec.rb +0 -16
- data/spec/code/parser/call_spec.rb +0 -26
- data/spec/code/power_spec.rb +0 -13
- data/spec/code/range_spec.rb +0 -16
- data/spec/code/rescue_spec.rb +0 -13
- data/spec/code/shift_spec.rb +0 -13
- data/spec/code/splat_spec.rb +0 -13
- data/spec/code/string_spec.rb +0 -27
- data/spec/code/ternary_spec.rb +0 -18
- data/spec/code/unary_minus_spec.rb +0 -13
- data/spec/code/while_spec.rb +0 -18
- data/template-ruby.gemspec +0 -19
data/lib/code/parser/class.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
5
|
class Class < Language
|
4
6
|
def statement
|
5
|
-
|
7
|
+
While
|
6
8
|
end
|
7
9
|
|
8
10
|
def name
|
9
|
-
|
11
|
+
Name
|
10
12
|
end
|
11
13
|
|
12
14
|
def code
|
13
|
-
|
15
|
+
Code
|
14
16
|
end
|
15
17
|
|
16
18
|
def whitespace
|
17
|
-
|
19
|
+
Whitespace
|
18
20
|
end
|
19
21
|
|
20
22
|
def whitespace?
|
@@ -36,8 +38,9 @@ class Code
|
|
36
38
|
def root
|
37
39
|
(
|
38
40
|
class_keyword << whitespace? << name.aka(:name) <<
|
39
|
-
|
40
|
-
|
41
|
+
(
|
42
|
+
whitespace? << lesser << whitespace? << name.aka(:superclass)
|
43
|
+
).maybe << code.aka(:body) << end_keyword.maybe
|
41
44
|
).aka(:class) | statement
|
42
45
|
end
|
43
46
|
end
|
data/lib/code/parser/code.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
5
|
class Code < Language
|
4
6
|
def whitespace
|
5
|
-
|
7
|
+
Whitespace
|
6
8
|
end
|
7
9
|
|
8
|
-
def whitespace?
|
9
|
-
whitespace.maybe
|
10
|
+
def whitespace?
|
11
|
+
whitespace.maybe
|
10
12
|
end
|
11
13
|
|
12
14
|
def statement
|
13
|
-
|
15
|
+
Statement
|
14
16
|
end
|
15
17
|
|
16
18
|
def present
|
@@ -1,20 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
|
-
class
|
4
|
-
def
|
5
|
-
|
5
|
+
class Dictionary < Language
|
6
|
+
def code_present
|
7
|
+
Code.new.present
|
6
8
|
end
|
7
9
|
|
8
10
|
def statement
|
9
|
-
|
11
|
+
Statement
|
10
12
|
end
|
11
13
|
|
12
14
|
def name
|
13
|
-
|
15
|
+
Name
|
14
16
|
end
|
15
17
|
|
16
18
|
def whitespace
|
17
|
-
|
19
|
+
Whitespace
|
18
20
|
end
|
19
21
|
|
20
22
|
def whitespace?
|
@@ -46,21 +48,22 @@ class Code
|
|
46
48
|
end
|
47
49
|
|
48
50
|
def key_value
|
49
|
-
(name.aka(:name) << colon <<
|
50
|
-
(
|
51
|
+
(name.aka(:name) << colon << code_present.aka(:value).maybe) |
|
52
|
+
(
|
53
|
+
statement.aka(:statement) << colon << code_present.aka(:value).maybe
|
54
|
+
) |
|
51
55
|
(
|
52
56
|
statement.aka(:statement) << whitespace? << equal << greater <<
|
53
|
-
|
54
|
-
)
|
57
|
+
code_present.aka(:value).maybe
|
58
|
+
) | statement.aka(:statement)
|
55
59
|
end
|
56
60
|
|
57
61
|
def root
|
58
62
|
(
|
59
63
|
opening_curly_bracket.ignore << whitespace? <<
|
60
|
-
key_value
|
61
|
-
(whitespace? << comma << whitespace? << key_value).repeat <<
|
64
|
+
(whitespace? << key_value << (whitespace? << comma).maybe).repeat <<
|
62
65
|
(whitespace? << closing_curly_bracket.ignore).maybe
|
63
|
-
).aka(:dictionnary) |
|
66
|
+
).aka(:dictionnary) | List
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
data/lib/code/parser/equal.rb
CHANGED
@@ -1,24 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
|
-
class Equal <
|
5
|
+
class Equal < RightOperation
|
4
6
|
def statement
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
def name
|
9
|
-
::Code::Parser::Name
|
10
|
-
end
|
11
|
-
|
12
|
-
def equal_class
|
13
|
-
::Code::Parser::Equal
|
14
|
-
end
|
15
|
-
|
16
|
-
def whitespace
|
17
|
-
::Code::Parser::Whitespace
|
18
|
-
end
|
19
|
-
|
20
|
-
def whitespace?
|
21
|
-
whitespace.maybe
|
7
|
+
Rescue
|
22
8
|
end
|
23
9
|
|
24
10
|
def equal
|
@@ -70,24 +56,11 @@ class Code
|
|
70
56
|
end
|
71
57
|
|
72
58
|
def operator
|
73
|
-
equal
|
74
|
-
(
|
75
|
-
(
|
76
|
-
(
|
77
|
-
(pipe << equal
|
78
|
-
(pipe << pipe << equal.ignore) |
|
79
|
-
(ampersand << ampersand << equal.ignore)
|
80
|
-
end
|
81
|
-
|
82
|
-
def names
|
83
|
-
name << (dot << name).repeat
|
84
|
-
end
|
85
|
-
|
86
|
-
def root
|
87
|
-
(
|
88
|
-
names.aka(:left) << whitespace? << operator.aka(:operator) <<
|
89
|
-
whitespace? << equal_class.aka(:right)
|
90
|
-
).aka(:equal) | statement
|
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)
|
91
64
|
end
|
92
65
|
end
|
93
66
|
end
|
data/lib/code/parser/equality.rb
CHANGED
data/lib/code/parser/function.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
5
|
class Function < Language
|
4
6
|
def name
|
5
|
-
|
7
|
+
Name
|
6
8
|
end
|
7
9
|
|
8
10
|
def code
|
9
|
-
|
11
|
+
Code
|
10
12
|
end
|
11
13
|
|
12
14
|
def code_present
|
13
|
-
|
15
|
+
Code.new.present
|
14
16
|
end
|
15
17
|
|
16
18
|
def whitespace
|
17
|
-
|
19
|
+
Whitespace
|
18
20
|
end
|
19
21
|
|
20
22
|
def whitespace?
|
@@ -53,13 +55,26 @@ class Code
|
|
53
55
|
str("}")
|
54
56
|
end
|
55
57
|
|
58
|
+
def asterisk
|
59
|
+
str("*")
|
60
|
+
end
|
61
|
+
|
62
|
+
def ampersand
|
63
|
+
str("&")
|
64
|
+
end
|
65
|
+
|
66
|
+
def prefix
|
67
|
+
(asterisk << asterisk).aka(:keyword_splat) |
|
68
|
+
asterisk.aka(:regular_splat) | ampersand.aka(:block)
|
69
|
+
end
|
70
|
+
|
56
71
|
def keyword_parameter
|
57
72
|
name.aka(:name) << whitespace? << colon.aka(:keyword) <<
|
58
73
|
code_present.aka(:default).maybe
|
59
74
|
end
|
60
75
|
|
61
76
|
def regular_parameter
|
62
|
-
name.aka(:name) << whitespace? <<
|
77
|
+
prefix.maybe << name.aka(:name) << whitespace? <<
|
63
78
|
(equal << whitespace? << code_present.aka(:default)).maybe
|
64
79
|
end
|
65
80
|
|
@@ -68,9 +83,9 @@ class Code
|
|
68
83
|
end
|
69
84
|
|
70
85
|
def parameters
|
71
|
-
opening_parenthesis.ignore << whitespace? <<
|
72
|
-
(whitespace? <<
|
73
|
-
whitespace? << closing_parenthesis.ignore.maybe
|
86
|
+
opening_parenthesis.ignore << whitespace? <<
|
87
|
+
(whitespace? << parameter << (whitespace? << comma).maybe).repeat <<
|
88
|
+
(whitespace? << closing_parenthesis.ignore).maybe
|
74
89
|
end
|
75
90
|
|
76
91
|
def root
|
@@ -78,7 +93,7 @@ class Code
|
|
78
93
|
parameters.aka(:parameters) << whitespace? << equal << greater <<
|
79
94
|
whitespace? << opening_curly_bracket << code.aka(:body) <<
|
80
95
|
closing_curly_bracket.maybe
|
81
|
-
).aka(:function) |
|
96
|
+
).aka(:function) | Dictionary
|
82
97
|
end
|
83
98
|
end
|
84
99
|
end
|
data/lib/code/parser/greater.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
|
-
class Greater <
|
5
|
+
class Greater < LeftOperation
|
4
6
|
def statement
|
5
|
-
|
7
|
+
BitwiseOr
|
6
8
|
end
|
7
9
|
|
8
10
|
def greater
|
@@ -18,7 +20,8 @@ class Code
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def operator
|
21
|
-
(greater << equal) | (lesser << equal
|
23
|
+
(greater << equal) | (lesser << equal << greater.absent) |
|
24
|
+
(greater << equal.absent) | lesser
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
data/lib/code/parser/group.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
5
|
class Group < Language
|
4
6
|
def code
|
5
|
-
|
7
|
+
Code
|
6
8
|
end
|
7
9
|
|
8
10
|
def opening_parenthesis
|
@@ -15,7 +17,7 @@ class Code
|
|
15
17
|
|
16
18
|
def root
|
17
19
|
(opening_parenthesis << code << closing_parenthesis.maybe).aka(:group) |
|
18
|
-
|
20
|
+
Call
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
data/lib/code/parser/if.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
5
|
class If < Language
|
4
6
|
def statement
|
5
|
-
|
7
|
+
IfModifier
|
6
8
|
end
|
7
9
|
|
8
10
|
def if_class
|
9
|
-
|
11
|
+
If
|
10
12
|
end
|
11
13
|
|
12
14
|
def whitespace
|
13
|
-
|
15
|
+
Whitespace
|
14
16
|
end
|
15
17
|
|
16
18
|
def code
|
17
|
-
|
19
|
+
Code
|
18
20
|
end
|
19
21
|
|
20
22
|
def whitespace?
|
@@ -1,20 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
|
-
class IfModifier <
|
5
|
+
class IfModifier < RightOperation
|
4
6
|
def statement
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
def if_modifier
|
9
|
-
::Code::Parser::IfModifier
|
7
|
+
OrKeyword
|
10
8
|
end
|
11
9
|
|
12
10
|
def whitespace
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def whitespace?
|
17
|
-
whitespace.maybe
|
11
|
+
Whitespace.new.without_newline
|
18
12
|
end
|
19
13
|
|
20
14
|
def if_keyword
|
@@ -36,20 +30,6 @@ class Code
|
|
36
30
|
def operator
|
37
31
|
if_keyword | unless_keyword | while_keyword | until_keyword
|
38
32
|
end
|
39
|
-
|
40
|
-
def root
|
41
|
-
(
|
42
|
-
statement.aka(:left) <<
|
43
|
-
(
|
44
|
-
whitespace? << operator.aka(:operator) << whitespace? <<
|
45
|
-
if_modifier.aka(:right)
|
46
|
-
).maybe
|
47
|
-
)
|
48
|
-
.aka(:if_modifier)
|
49
|
-
.then do |output|
|
50
|
-
output[:if_modifier][:right] ? output : output[:if_modifier][:left]
|
51
|
-
end
|
52
|
-
end
|
53
33
|
end
|
54
34
|
end
|
55
35
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Code
|
4
|
+
class Parser
|
5
|
+
class LeftOperation < Language
|
6
|
+
def statement
|
7
|
+
raise NotImplementedError
|
8
|
+
end
|
9
|
+
|
10
|
+
def whitespace
|
11
|
+
Whitespace
|
12
|
+
end
|
13
|
+
|
14
|
+
def whitespace?
|
15
|
+
whitespace.maybe
|
16
|
+
end
|
17
|
+
|
18
|
+
def operator
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
21
|
+
|
22
|
+
def root
|
23
|
+
(
|
24
|
+
statement.aka(:first) << (
|
25
|
+
whitespace? << operator.aka(:operator) << whitespace? <<
|
26
|
+
statement.aka(:statement)
|
27
|
+
).repeat(1).aka(:others).maybe
|
28
|
+
)
|
29
|
+
.aka(:left_operation)
|
30
|
+
.then do |output|
|
31
|
+
if output[:left_operation][:others]
|
32
|
+
output
|
33
|
+
else
|
34
|
+
output[:left_operation][:first]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/code/parser/list.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
5
|
class List < Language
|
4
6
|
def code
|
5
|
-
|
7
|
+
Code.new.present
|
6
8
|
end
|
7
9
|
|
8
10
|
def whitespace
|
9
|
-
|
11
|
+
Whitespace
|
10
12
|
end
|
11
13
|
|
12
14
|
def whitespace?
|
@@ -32,10 +34,9 @@ class Code
|
|
32
34
|
def root
|
33
35
|
(
|
34
36
|
opening_square_bracket.ignore << whitespace? <<
|
35
|
-
element
|
36
|
-
(whitespace? << comma << whitespace? << element).repeat <<
|
37
|
+
(whitespace? << element << (whitespace? << comma).maybe).repeat <<
|
37
38
|
(whitespace? << closing_square_bracket.ignore).maybe
|
38
|
-
).aka(:list) |
|
39
|
+
).aka(:list) | String
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
data/lib/code/parser/name.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
5
|
class Name < Language
|
@@ -65,6 +67,18 @@ class Code
|
|
65
67
|
str("&")
|
66
68
|
end
|
67
69
|
|
70
|
+
def lesser
|
71
|
+
str("<")
|
72
|
+
end
|
73
|
+
|
74
|
+
def greater
|
75
|
+
str(">")
|
76
|
+
end
|
77
|
+
|
78
|
+
def asterisk
|
79
|
+
str("*")
|
80
|
+
end
|
81
|
+
|
68
82
|
def do_keyword
|
69
83
|
str("do")
|
70
84
|
end
|
@@ -85,7 +99,8 @@ class Code
|
|
85
99
|
ampersand | equal | pipe | dot | colon | comma | space | newline |
|
86
100
|
opening_curly_bracket | closing_curly_bracket | opening_parenthesis |
|
87
101
|
closing_parenthesis | opening_square_bracket |
|
88
|
-
closing_square_bracket | single_quote | double_quote
|
102
|
+
closing_square_bracket | single_quote | double_quote | lesser |
|
103
|
+
greater | asterisk
|
89
104
|
end
|
90
105
|
|
91
106
|
def character
|
@@ -97,9 +112,9 @@ class Code
|
|
97
112
|
end
|
98
113
|
|
99
114
|
def root
|
100
|
-
(do_keyword << separator).absent <<
|
101
|
-
|
102
|
-
|
115
|
+
(do_keyword << separator).absent << (
|
116
|
+
else_keyword << separator
|
117
|
+
).absent << (elsif_keyword << separator).absent <<
|
103
118
|
(end_keyword << separator).absent << character.repeat(1)
|
104
119
|
end
|
105
120
|
end
|
data/lib/code/parser/negation.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
5
|
class Negation < Language
|
@@ -18,12 +20,12 @@ class Code
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def negation
|
21
|
-
|
23
|
+
Negation
|
22
24
|
end
|
23
25
|
|
24
26
|
def root
|
25
27
|
(operator.aka(:operator) << negation.aka(:right)).aka(:negation) |
|
26
|
-
|
28
|
+
ChainedCall
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
5
|
class NotKeyword < Language
|
4
6
|
def not_class
|
5
|
-
|
7
|
+
NotKeyword
|
6
8
|
end
|
7
9
|
|
8
10
|
def whitespace
|
9
|
-
|
11
|
+
Whitespace
|
10
12
|
end
|
11
13
|
|
12
14
|
def not_keyword
|
@@ -16,7 +18,7 @@ class Code
|
|
16
18
|
def root
|
17
19
|
(not_keyword.aka(:operator) << whitespace << not_class.aka(:right)).aka(
|
18
20
|
:not
|
19
|
-
) |
|
21
|
+
) | Equal
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/code/parser/nothing.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
5
|
class Nothing < Language
|
@@ -5,17 +7,8 @@ class Code
|
|
5
7
|
str("nothing")
|
6
8
|
end
|
7
9
|
|
8
|
-
def null_keyword
|
9
|
-
str("null")
|
10
|
-
end
|
11
|
-
|
12
|
-
def nil_keyword
|
13
|
-
str("nil")
|
14
|
-
end
|
15
|
-
|
16
10
|
def root
|
17
|
-
|
18
|
-
::Code::Parser::Group
|
11
|
+
nothing_keyword.aka(:nothing) | Group
|
19
12
|
end
|
20
13
|
end
|
21
14
|
end
|
data/lib/code/parser/number.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
5
|
class Number < Language
|
4
6
|
def number
|
5
|
-
|
7
|
+
Number
|
6
8
|
end
|
7
9
|
|
8
10
|
def zero
|
@@ -147,7 +149,7 @@ class Code
|
|
147
149
|
decimal.aka(:decimal) | base_16_number.aka(:base_16) |
|
148
150
|
base_8_number.aka(:base_8) | base_2_number.aka(:base_2) |
|
149
151
|
base_10_number.aka(:base_10)
|
150
|
-
).aka(:number) |
|
152
|
+
).aka(:number) | Boolean
|
151
153
|
end
|
152
154
|
end
|
153
155
|
end
|
data/lib/code/parser/power.rb
CHANGED
@@ -1,20 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Parser
|
3
|
-
class Power <
|
4
|
-
def power
|
5
|
-
::Code::Parser::Power
|
6
|
-
end
|
7
|
-
|
5
|
+
class Power < RightOperation
|
8
6
|
def statement
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def whitespace
|
13
|
-
::Code::Parser::Whitespace
|
14
|
-
end
|
15
|
-
|
16
|
-
def whitespace?
|
17
|
-
whitespace.maybe
|
7
|
+
Function
|
18
8
|
end
|
19
9
|
|
20
10
|
def asterisk
|
@@ -24,20 +14,6 @@ class Code
|
|
24
14
|
def operator
|
25
15
|
asterisk << asterisk
|
26
16
|
end
|
27
|
-
|
28
|
-
def root
|
29
|
-
(
|
30
|
-
statement.aka(:left) <<
|
31
|
-
(
|
32
|
-
whitespace? << operator.aka(:operator) << whitespace? <<
|
33
|
-
power.aka(:right)
|
34
|
-
).maybe
|
35
|
-
)
|
36
|
-
.aka(:power)
|
37
|
-
.then do |output|
|
38
|
-
output[:power][:right] ? output : output[:power][:left]
|
39
|
-
end
|
40
|
-
end
|
41
17
|
end
|
42
18
|
end
|
43
19
|
end
|