template-ruby 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile +2 -1
- data/Gemfile.lock +27 -54
- data/TODO +17 -0
- data/bin/code +56 -31
- data/bin/format +3 -0
- data/bin/template +62 -20
- data/bin/test +17 -0
- data/code-ruby.gemspec +1 -3
- data/docs/class.code +9 -0
- data/docs/euler/1.template +1 -5
- data/docs/euler/5.template +0 -1
- data/docs/meetup.code +12 -0
- data/docs/precedence.template +6 -39
- data/docs/rain.code +22 -0
- data/docs/slack.code +17 -0
- data/docs/stripe.code +7 -0
- data/docs/twitter.code +9 -0
- data/language-ruby.gemspec +18 -0
- data/lib/code/node/base_10.rb +29 -0
- data/lib/code/node/base_16.rb +13 -0
- data/lib/code/node/base_2.rb +13 -0
- data/lib/code/node/base_8.rb +13 -0
- data/lib/code/node/boolean.rb +7 -7
- data/lib/code/node/call.rb +32 -38
- data/lib/code/node/call_argument.rb +11 -27
- data/lib/code/node/chained_call.rb +10 -27
- data/lib/code/node/code.rb +4 -6
- data/lib/code/node/decimal.rb +26 -0
- data/lib/code/node/dictionnary.rb +20 -9
- data/lib/code/node/equal.rb +18 -20
- data/lib/code/node/function.rb +10 -7
- data/lib/code/node/function_parameter.rb +31 -0
- data/lib/code/node/if.rb +36 -32
- data/lib/code/node/if_modifier.rb +35 -36
- data/lib/code/node/list.rb +6 -8
- data/lib/code/node/negation.rb +5 -23
- data/lib/code/node/not.rb +15 -0
- data/lib/code/node/nothing.rb +1 -1
- data/lib/code/node/number.rb +14 -12
- data/lib/code/node/operation.rb +21 -16
- data/lib/code/node/power.rb +10 -6
- data/lib/code/node/rescue.rb +4 -3
- data/lib/code/node/splat.rb +15 -0
- data/lib/code/node/statement.rb +48 -70
- data/lib/code/node/string.rb +42 -16
- data/lib/code/node/ternary.rb +7 -9
- data/lib/code/node/unary_minus.rb +5 -12
- data/lib/code/node/while.rb +17 -24
- data/lib/code/node.rb +7 -8
- data/lib/code/object/argument.rb +2 -11
- data/lib/code/object/decimal.rb +45 -30
- data/lib/code/object/dictionnary.rb +6 -5
- data/lib/code/object/function.rb +20 -23
- data/lib/code/object/global.rb +11 -6
- data/lib/code/object/integer.rb +73 -30
- data/lib/code/object/list.rb +40 -34
- data/lib/code/object/range.rb +18 -17
- data/lib/code/object/ruby_function.rb +12 -6
- data/lib/code/object/string.rb +22 -12
- data/lib/code/object.rb +82 -24
- data/lib/code/parser/addition.rb +12 -20
- data/lib/code/parser/and_operator.rb +9 -20
- data/lib/code/parser/bitwise_and.rb +9 -20
- data/lib/code/parser/bitwise_or.rb +12 -20
- data/lib/code/parser/boolean.rb +10 -7
- data/lib/code/parser/call.rb +92 -60
- data/lib/code/parser/chained_call.rb +47 -0
- data/lib/code/parser/class.rb +45 -0
- data/lib/code/parser/code.rb +17 -10
- data/lib/code/parser/dictionnary.rb +56 -30
- data/lib/code/parser/equal.rb +87 -35
- data/lib/code/parser/equality.rb +23 -24
- data/lib/code/parser/equality_lower.rb +9 -0
- data/lib/code/parser/function.rb +67 -42
- data/lib/code/parser/greater.rb +25 -0
- data/lib/code/parser/group.rb +13 -8
- data/lib/code/parser/if.rb +51 -21
- data/lib/code/parser/if_modifier.rb +43 -16
- data/lib/code/parser/list.rb +32 -19
- data/lib/code/parser/multiplication.rb +15 -20
- data/lib/code/parser/name.rb +96 -84
- data/lib/code/parser/negation.rb +20 -9
- data/lib/code/parser/not_keyword.rb +14 -12
- data/lib/code/parser/nothing.rb +13 -8
- data/lib/code/parser/number.rb +124 -68
- data/lib/code/parser/operation.rb +35 -0
- data/lib/code/parser/or_keyword.rb +12 -20
- data/lib/code/parser/or_operator.rb +9 -20
- data/lib/code/parser/power.rb +32 -14
- data/lib/code/parser/range.rb +9 -17
- data/lib/code/parser/rescue.rb +29 -13
- data/lib/code/parser/shift.rb +11 -21
- data/lib/code/parser/splat.rb +31 -0
- data/lib/code/parser/statement.rb +4 -3
- data/lib/code/parser/string.rb +53 -62
- data/lib/code/parser/ternary.rb +36 -15
- data/lib/code/parser/unary_minus.rb +23 -5
- data/lib/code/parser/while.rb +26 -15
- data/lib/code/parser/whitespace.rb +49 -0
- data/lib/code/parser.rb +15 -0
- data/lib/code/ruby.rb +13 -12
- data/lib/code-ruby.rb +2 -11
- data/lib/code.rb +16 -13
- data/lib/language/atom.rb +343 -0
- data/lib/language/output.rb +130 -0
- data/lib/language/parser/absent/present.rb +8 -0
- data/lib/language/parser/absent.rb +6 -0
- data/lib/language/parser/end_of_input.rb +6 -0
- data/lib/language/parser/interuption.rb +38 -0
- data/lib/language/parser/not_end_of_input.rb +6 -0
- data/lib/language/parser/str/not_found.rb +16 -0
- data/lib/language/parser/str.rb +6 -0
- data/lib/language/parser.rb +53 -0
- data/lib/language-ruby.rb +10 -0
- data/lib/language.rb +80 -0
- data/lib/template/node/code_part.rb +1 -1
- data/lib/template/node/part.rb +1 -1
- data/lib/template/node/template.rb +1 -1
- data/lib/template/node/text_part.rb +1 -1
- data/lib/template/node.rb +1 -1
- data/lib/template/parser/template.rb +26 -17
- data/lib/template/parser.rb +15 -0
- data/lib/template/version.rb +1 -1
- data/lib/template-ruby.rb +2 -11
- data/lib/template.rb +6 -11
- data/spec/code/addition_spec.rb +13 -0
- data/spec/code/and_operator_spec.rb +13 -0
- data/spec/code/bitwise_and_spec.rb +13 -0
- data/spec/code/bitwise_or_spec.rb +13 -0
- data/spec/code/boolean_spec.rb +13 -0
- data/spec/code/call_spec.rb +21 -0
- data/spec/code/chained_call_spec.rb +16 -0
- data/spec/code/dictionnary_spec.rb +17 -0
- data/spec/code/equal_spec.rb +26 -0
- data/spec/code/equality_spec.rb +13 -0
- data/spec/code/function_spec.rb +18 -0
- data/spec/code/greater_spec.rb +18 -0
- data/spec/code/group_spec.rb +12 -0
- data/spec/code/if_modifier_spec.rb +20 -0
- data/spec/code/if_spec.rb +25 -0
- data/spec/code/list_spec.rb +17 -0
- data/spec/code/multiplication_spec.rb +18 -0
- data/spec/code/negation_spec.rb +20 -0
- data/spec/code/not_keyword_spec.rb +13 -0
- data/spec/code/nothing_spec.rb +17 -0
- data/spec/code/number_spec.rb +22 -0
- data/spec/code/or_keyword_spec.rb +17 -0
- data/spec/code/or_operator_spec.rb +16 -0
- data/spec/code/parser/boolean_spec.rb +5 -7
- data/spec/code/parser/call_spec.rb +16 -56
- data/spec/code/parser/chained_call.rb +17 -0
- data/spec/code/parser/dictionnary_spec.rb +8 -9
- data/spec/code/parser/function_spec.rb +5 -21
- data/spec/code/parser/group_spec.rb +18 -0
- data/spec/code/parser/list_spec.rb +9 -20
- data/spec/code/parser/number_spec.rb +4 -109
- data/spec/code/parser/string_spec.rb +9 -17
- data/spec/code/parser_spec.rb +23 -0
- data/spec/code/power_spec.rb +13 -0
- data/spec/code/range_spec.rb +16 -0
- data/spec/code/rescue_spec.rb +13 -0
- data/spec/code/shift_spec.rb +13 -0
- data/spec/code/splat_spec.rb +13 -0
- data/spec/code/string_spec.rb +25 -0
- data/spec/code/ternary_spec.rb +18 -0
- data/spec/code/unary_minus_spec.rb +13 -0
- data/spec/code/while_spec.rb +18 -0
- data/spec/spec_helper.rb +4 -1
- data/template-ruby.gemspec +2 -4
- metadata +112 -72
- data/lib/code/node/base_10_decimal.rb +0 -32
- data/lib/code/node/base_10_integer.rb +0 -32
- data/lib/code/node/base_10_number.rb +0 -19
- data/lib/code/node/base_16_number.rb +0 -19
- data/lib/code/node/base_2_number.rb +0 -19
- data/lib/code/node/base_8_number.rb +0 -19
- data/lib/code/node/block.rb +0 -17
- data/lib/code/node/defined.rb +0 -19
- data/lib/code/node/dictionnary_key_value.rb +0 -23
- data/lib/code/node/function_argument.rb +0 -45
- data/lib/code/node/group.rb +0 -13
- data/lib/code/node/keyword_call_argument.rb +0 -30
- data/lib/code/node/keyword_function_argument.rb +0 -33
- data/lib/code/node/name.rb +0 -28
- data/lib/code/node/not_keyword.rb +0 -13
- data/lib/code/node/or_keyword.rb +0 -34
- data/lib/code/node/range.rb +0 -31
- data/lib/code/node/regular_call_argument.rb +0 -34
- data/lib/code/node/regular_function_argument.rb +0 -36
- data/lib/code/node/string_characters.rb +0 -13
- data/lib/code/node/string_component.rb +0 -23
- data/lib/code/node/string_interpolation.rb +0 -13
- data/lib/code/parser/defined.rb +0 -20
- data/lib/code/parser/greater_than.rb +0 -33
- data/spec/call_spec.rb +0 -22
- data/spec/code/error/type_error_spec.rb +0 -63
- data/spec/code/parser/name_spec.rb +0 -15
- data/spec/code/parser/nothing_spec.rb +0 -19
- data/spec/code_spec.rb +0 -182
- data/spec/function_spec.rb +0 -26
- data/spec/template/parser/template_spec.rb +0 -19
- data/spec/template_spec.rb +0 -52
data/lib/code/parser/list.rb
CHANGED
@@ -1,29 +1,42 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class List <
|
4
|
-
|
5
|
-
|
3
|
+
class List < Language
|
4
|
+
def code
|
5
|
+
::Code::Parser::Code.new.present
|
6
|
+
end
|
7
|
+
|
8
|
+
def whitespace
|
9
|
+
::Code::Parser::Whitespace
|
10
|
+
end
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
12
|
+
def whitespace?
|
13
|
+
whitespace.maybe
|
14
|
+
end
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
rule(:whitespace?) { whitespace.maybe }
|
16
|
+
def opening_square_bracket
|
17
|
+
str("[")
|
18
|
+
end
|
15
19
|
|
16
|
-
|
17
|
-
(
|
18
|
-
opening_square_bracket.ignore >> whitespace?.ignore >>
|
19
|
-
code.as(:code).repeat(0, 1) >>
|
20
|
-
(whitespace? >> comma >> whitespace? >> code.as(:code)).repeat >>
|
21
|
-
whitespace?.ignore >> comma.maybe.ignore >> whitespace?.ignore >>
|
22
|
-
closing_square_bracket.ignore
|
23
|
-
).as(:list) | string
|
20
|
+
def closing_square_bracket
|
21
|
+
str("]")
|
24
22
|
end
|
25
23
|
|
26
|
-
|
24
|
+
def comma
|
25
|
+
str(",")
|
26
|
+
end
|
27
|
+
|
28
|
+
def element
|
29
|
+
code
|
30
|
+
end
|
31
|
+
|
32
|
+
def root
|
33
|
+
(
|
34
|
+
opening_square_bracket.ignore << whitespace? <<
|
35
|
+
element.repeat(0, 1) <<
|
36
|
+
(whitespace? << comma << whitespace? << element).repeat <<
|
37
|
+
(whitespace? << closing_square_bracket.ignore).maybe
|
38
|
+
).aka(:list) | ::Code::Parser::String
|
39
|
+
end
|
27
40
|
end
|
28
41
|
end
|
29
42
|
end
|
@@ -1,30 +1,25 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class Multiplication <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
rule(:slash) { str("/") }
|
8
|
-
rule(:percent) { str("%") }
|
3
|
+
class Multiplication < Operation
|
4
|
+
def statement
|
5
|
+
::Code::Parser::UnaryMinus
|
6
|
+
end
|
9
7
|
|
10
|
-
|
8
|
+
def asterisk
|
9
|
+
str("*")
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
rule(:whitespace?) { whitespace.maybe }
|
12
|
+
def slash
|
13
|
+
str("/")
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
(
|
19
|
-
unary_minus.as(:first) >>
|
20
|
-
(
|
21
|
-
whitespace? >> operator.as(:operator) >> whitespace? >>
|
22
|
-
unary_minus.as(:statement)
|
23
|
-
).repeat(1).as(:rest)
|
24
|
-
).as(:multiplication) | unary_minus
|
16
|
+
def percent
|
17
|
+
str("%")
|
25
18
|
end
|
26
19
|
|
27
|
-
|
20
|
+
def operator
|
21
|
+
asterisk | slash | percent
|
22
|
+
end
|
28
23
|
end
|
29
24
|
end
|
30
25
|
end
|
data/lib/code/parser/name.rb
CHANGED
@@ -1,89 +1,101 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class Name <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
3
|
+
class Name < Language
|
4
|
+
def space
|
5
|
+
str(" ")
|
6
|
+
end
|
7
|
+
|
8
|
+
def newline
|
9
|
+
str("\n")
|
10
|
+
end
|
11
|
+
|
12
|
+
def comma
|
13
|
+
str(",")
|
14
|
+
end
|
15
|
+
|
16
|
+
def equal
|
17
|
+
str("=")
|
18
|
+
end
|
19
|
+
|
20
|
+
def colon
|
21
|
+
str(":")
|
22
|
+
end
|
23
|
+
|
24
|
+
def opening_curly_bracket
|
25
|
+
str("{")
|
26
|
+
end
|
27
|
+
|
28
|
+
def closing_curly_bracket
|
29
|
+
str("}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def opening_square_bracket
|
33
|
+
str("[")
|
34
|
+
end
|
35
|
+
|
36
|
+
def closing_square_bracket
|
37
|
+
str("]")
|
38
|
+
end
|
39
|
+
|
40
|
+
def opening_parenthesis
|
41
|
+
str("(")
|
42
|
+
end
|
43
|
+
|
44
|
+
def closing_parenthesis
|
45
|
+
str(")")
|
46
|
+
end
|
47
|
+
|
48
|
+
def single_quote
|
49
|
+
str("'")
|
50
|
+
end
|
51
|
+
|
52
|
+
def double_quote
|
53
|
+
str('"')
|
54
|
+
end
|
55
|
+
|
56
|
+
def dot
|
57
|
+
str(".")
|
58
|
+
end
|
59
|
+
|
60
|
+
def pipe
|
61
|
+
str("|")
|
62
|
+
end
|
63
|
+
|
64
|
+
def ampersand
|
65
|
+
str("&")
|
66
|
+
end
|
67
|
+
|
68
|
+
def do_keyword
|
69
|
+
str("do")
|
70
|
+
end
|
71
|
+
|
72
|
+
def end_keyword
|
73
|
+
str("end")
|
74
|
+
end
|
75
|
+
|
76
|
+
def elsif_keyword
|
77
|
+
str("elsif")
|
78
|
+
end
|
79
|
+
|
80
|
+
def else_keyword
|
81
|
+
str("else")
|
82
|
+
end
|
83
|
+
|
84
|
+
def special_character
|
85
|
+
ampersand | equal | pipe | dot | colon | comma | space | newline |
|
86
|
+
opening_curly_bracket | closing_curly_bracket | opening_parenthesis |
|
87
|
+
closing_parenthesis | opening_square_bracket |
|
88
|
+
closing_square_bracket | single_quote | double_quote
|
89
|
+
end
|
90
|
+
|
91
|
+
def character
|
92
|
+
special_character.absent << any
|
93
|
+
end
|
94
|
+
|
95
|
+
def root
|
96
|
+
do_keyword.absent << end_keyword.absent << elsif_keyword.absent <<
|
97
|
+
else_keyword.absent << character.repeat(1)
|
98
|
+
end
|
87
99
|
end
|
88
100
|
end
|
89
101
|
end
|
data/lib/code/parser/negation.rb
CHANGED
@@ -1,19 +1,30 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class Negation <
|
4
|
-
|
3
|
+
class Negation < Language
|
4
|
+
def exclamation_point
|
5
|
+
str("!")
|
6
|
+
end
|
7
|
+
|
8
|
+
def tilde
|
9
|
+
str("~")
|
10
|
+
end
|
5
11
|
|
6
|
-
|
7
|
-
|
12
|
+
def plus
|
13
|
+
str("+")
|
14
|
+
end
|
8
15
|
|
9
|
-
|
16
|
+
def operator
|
17
|
+
exclamation_point | tilde | plus
|
18
|
+
end
|
10
19
|
|
11
|
-
|
12
|
-
|
13
|
-
function
|
20
|
+
def negation
|
21
|
+
::Code::Parser::Negation
|
14
22
|
end
|
15
23
|
|
16
|
-
root
|
24
|
+
def root
|
25
|
+
(operator.aka(:operator) << negation.aka(:right)).aka(:negation) |
|
26
|
+
::Code::Parser::Function
|
27
|
+
end
|
17
28
|
end
|
18
29
|
end
|
19
30
|
end
|
@@ -1,21 +1,23 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class NotKeyword <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
rule(:operator) { not_keyword }
|
3
|
+
class NotKeyword < Language
|
4
|
+
def not_class
|
5
|
+
::Code::Parser::NotKeyword
|
6
|
+
end
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def whitespace
|
9
|
+
::Code::Parser::Whitespace
|
10
|
+
end
|
13
11
|
|
14
|
-
|
15
|
-
(
|
12
|
+
def not_keyword
|
13
|
+
str("not")
|
16
14
|
end
|
17
15
|
|
18
|
-
root
|
16
|
+
def root
|
17
|
+
(not_keyword.aka(:operator) << whitespace << not_class.aka(:right)).aka(
|
18
|
+
:not
|
19
|
+
) | ::Code::Parser::Equal
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
data/lib/code/parser/nothing.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class Nothing <
|
4
|
-
|
3
|
+
class Nothing < Language
|
4
|
+
def nothing_keyword
|
5
|
+
str("nothing")
|
6
|
+
end
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
def null_keyword
|
9
|
+
str("null")
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
(
|
12
|
+
def nil_keyword
|
13
|
+
str("nil")
|
12
14
|
end
|
13
15
|
|
14
|
-
root
|
16
|
+
def root
|
17
|
+
(nothing_keyword | null_keyword | nil_keyword).aka(:nothing) |
|
18
|
+
::Code::Parser::Group
|
19
|
+
end
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
data/lib/code/parser/number.rb
CHANGED
@@ -1,98 +1,154 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class Number <
|
4
|
-
|
5
|
-
|
6
|
-
rule(:dot) { str(".") }
|
7
|
-
rule(:plus) { str("+") }
|
8
|
-
rule(:minus) { str("-") }
|
9
|
-
|
10
|
-
rule(:zero) { str("0") }
|
11
|
-
rule(:one) { str("1") }
|
12
|
-
rule(:two) { str("2") }
|
13
|
-
rule(:three) { str("3") }
|
14
|
-
rule(:four) { str("4") }
|
15
|
-
rule(:five) { str("5") }
|
16
|
-
rule(:six) { str("6") }
|
17
|
-
rule(:seven) { str("7") }
|
18
|
-
rule(:eight) { str("8") }
|
19
|
-
rule(:nine) { str("9") }
|
20
|
-
rule(:a) { str("a") | str("A") }
|
21
|
-
rule(:b) { str("b") | str("B") }
|
22
|
-
rule(:b) { str("b") | str("B") }
|
23
|
-
rule(:c) { str("c") | str("C") }
|
24
|
-
rule(:d) { str("d") | str("D") }
|
25
|
-
rule(:e) { str("e") | str("E") }
|
26
|
-
rule(:f) { str("f") | str("F") }
|
27
|
-
rule(:o) { str("o") | str("O") }
|
28
|
-
rule(:x) { str("x") | str("X") }
|
29
|
-
|
30
|
-
# sign
|
31
|
-
|
32
|
-
rule(:sign) { plus | minus }
|
33
|
-
|
34
|
-
# base 2
|
35
|
-
|
36
|
-
rule(:base_2_digit) { zero | one }
|
37
|
-
|
38
|
-
rule(:base_2_number) { zero.ignore >> b.ignore >> base_2_digit.repeat(1) }
|
39
|
-
|
40
|
-
# base 8
|
41
|
-
|
42
|
-
rule(:base_8_digit) do
|
43
|
-
zero | one | two | three | four | five | six | seven
|
3
|
+
class Number < Language
|
4
|
+
def number
|
5
|
+
::Code::Parser::Number
|
44
6
|
end
|
45
7
|
|
46
|
-
|
8
|
+
def zero
|
9
|
+
str("0")
|
10
|
+
end
|
47
11
|
|
48
|
-
|
12
|
+
def one
|
13
|
+
str("1")
|
14
|
+
end
|
49
15
|
|
50
|
-
|
51
|
-
|
16
|
+
def two
|
17
|
+
str("2")
|
18
|
+
end
|
19
|
+
|
20
|
+
def three
|
21
|
+
str("3")
|
22
|
+
end
|
23
|
+
|
24
|
+
def four
|
25
|
+
str("4")
|
26
|
+
end
|
27
|
+
|
28
|
+
def five
|
29
|
+
str("5")
|
52
30
|
end
|
53
31
|
|
54
|
-
|
32
|
+
def six
|
33
|
+
str("6")
|
34
|
+
end
|
55
35
|
|
56
|
-
|
36
|
+
def seven
|
37
|
+
str("7")
|
38
|
+
end
|
39
|
+
|
40
|
+
def eight
|
41
|
+
str("8")
|
42
|
+
end
|
57
43
|
|
58
|
-
|
59
|
-
|
60
|
-
base_10_exponent.as(:exponent).maybe
|
44
|
+
def nine
|
45
|
+
str("9")
|
61
46
|
end
|
62
47
|
|
63
|
-
|
48
|
+
def dot
|
49
|
+
str(".")
|
50
|
+
end
|
51
|
+
|
52
|
+
def a
|
53
|
+
str("a") | str("A")
|
54
|
+
end
|
55
|
+
|
56
|
+
def b
|
57
|
+
str("b") | str("B")
|
58
|
+
end
|
59
|
+
|
60
|
+
def c
|
61
|
+
str("c") | str("C")
|
62
|
+
end
|
63
|
+
|
64
|
+
def d
|
65
|
+
str("d") | str("D")
|
66
|
+
end
|
67
|
+
|
68
|
+
def e
|
69
|
+
str("e") | str("E")
|
70
|
+
end
|
71
|
+
|
72
|
+
def f
|
73
|
+
str("f") | str("F")
|
74
|
+
end
|
64
75
|
|
65
|
-
|
66
|
-
|
67
|
-
base_10_decimal_decimal.as(:decimal) >>
|
68
|
-
base_10_exponent.as(:exponent).maybe
|
76
|
+
def o
|
77
|
+
str("o") | str("O")
|
69
78
|
end
|
70
79
|
|
71
|
-
|
72
|
-
|
80
|
+
def x
|
81
|
+
str("x") | str("X")
|
73
82
|
end
|
74
83
|
|
75
|
-
|
84
|
+
def underscore
|
85
|
+
str("_")
|
86
|
+
end
|
76
87
|
|
77
|
-
|
88
|
+
def base_16_digit
|
78
89
|
zero | one | two | three | four | five | six | seven | eight | nine |
|
79
90
|
a | b | c | d | e | f
|
80
91
|
end
|
81
92
|
|
82
|
-
|
83
|
-
zero
|
93
|
+
def base_10_digit
|
94
|
+
zero | one | two | three | four | five | six | seven | eight | nine
|
84
95
|
end
|
85
96
|
|
86
|
-
|
97
|
+
def base_8_digit
|
98
|
+
zero | one | two | three | four | five | six | seven
|
99
|
+
end
|
87
100
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
101
|
+
def base_2_digit
|
102
|
+
zero | one
|
103
|
+
end
|
104
|
+
|
105
|
+
def base_16_whole
|
106
|
+
base_16_digit << (underscore.ignore | base_16_digit).repeat
|
93
107
|
end
|
94
108
|
|
95
|
-
|
109
|
+
def base_10_whole
|
110
|
+
base_10_digit << (underscore.ignore | base_10_digit).repeat
|
111
|
+
end
|
112
|
+
|
113
|
+
def base_8_whole
|
114
|
+
base_8_digit << (underscore.ignore | base_8_digit).repeat
|
115
|
+
end
|
116
|
+
|
117
|
+
def base_2_whole
|
118
|
+
base_2_digit << (underscore.ignore | base_2_digit).repeat
|
119
|
+
end
|
120
|
+
|
121
|
+
def exponent
|
122
|
+
(e << number).aka(:exponent)
|
123
|
+
end
|
124
|
+
|
125
|
+
def decimal
|
126
|
+
(base_10_whole << dot << base_10_whole).aka(:decimal) << exponent.maybe
|
127
|
+
end
|
128
|
+
|
129
|
+
def base_16_number
|
130
|
+
zero.ignore << x.ignore << base_16_whole
|
131
|
+
end
|
132
|
+
|
133
|
+
def base_10_number
|
134
|
+
base_10_whole.aka(:whole) << exponent.maybe
|
135
|
+
end
|
136
|
+
|
137
|
+
def base_8_number
|
138
|
+
zero.ignore << o.ignore << base_8_whole
|
139
|
+
end
|
140
|
+
|
141
|
+
def base_2_number
|
142
|
+
zero.ignore << b.ignore << base_2_whole
|
143
|
+
end
|
144
|
+
|
145
|
+
def root
|
146
|
+
(
|
147
|
+
decimal.aka(:decimal) | base_16_number.aka(:base_16) |
|
148
|
+
base_8_number.aka(:base_8) | base_2_number.aka(:base_2) |
|
149
|
+
base_10_number.aka(:base_10)
|
150
|
+
).aka(:number) | ::Code::Parser::Boolean
|
151
|
+
end
|
96
152
|
end
|
97
153
|
end
|
98
154
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Code
|
2
|
+
class Parser
|
3
|
+
class Operation < Language
|
4
|
+
def statement
|
5
|
+
raise NotImplementedError
|
6
|
+
end
|
7
|
+
|
8
|
+
def whitespace
|
9
|
+
::Code::Parser::Whitespace
|
10
|
+
end
|
11
|
+
|
12
|
+
def whitespace?
|
13
|
+
whitespace.maybe
|
14
|
+
end
|
15
|
+
|
16
|
+
def operator
|
17
|
+
raise NotImplementedError
|
18
|
+
end
|
19
|
+
|
20
|
+
def root
|
21
|
+
(
|
22
|
+
statement.aka(:first) <<
|
23
|
+
(
|
24
|
+
whitespace? << operator.aka(:operator) << whitespace? <<
|
25
|
+
statement.aka(:statement)
|
26
|
+
).repeat(1).aka(:others).maybe
|
27
|
+
)
|
28
|
+
.aka(:operation)
|
29
|
+
.then do |output|
|
30
|
+
output[:operation][:others] ? output : output[:operation][:first]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|