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
@@ -1,41 +1,67 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class Dictionnary <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
3
|
+
class Dictionnary < Language
|
4
|
+
def code
|
5
|
+
::Code::Parser::Code.new.present
|
6
|
+
end
|
7
|
+
|
8
|
+
def statement
|
9
|
+
::Code::Parser::Statement
|
10
|
+
end
|
11
|
+
|
12
|
+
def name
|
13
|
+
::Code::Parser::Name
|
14
|
+
end
|
15
|
+
|
16
|
+
def whitespace
|
17
|
+
::Code::Parser::Whitespace
|
18
|
+
end
|
19
|
+
|
20
|
+
def whitespace?
|
21
|
+
whitespace.maybe
|
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 comma
|
33
|
+
str(",")
|
34
|
+
end
|
35
|
+
|
36
|
+
def colon
|
37
|
+
str(":")
|
38
|
+
end
|
39
|
+
|
40
|
+
def equal
|
41
|
+
str("=")
|
42
|
+
end
|
43
|
+
|
44
|
+
def greater
|
45
|
+
str(">")
|
46
|
+
end
|
47
|
+
|
48
|
+
def key_value
|
49
|
+
(name.aka(:name) << colon << code.aka(:value)) |
|
50
|
+
(statement.aka(:statement) << colon << code.aka(:value)) |
|
22
51
|
(
|
23
|
-
|
24
|
-
|
52
|
+
statement.aka(:statement) << whitespace? << equal << greater <<
|
53
|
+
code.aka(:value)
|
25
54
|
)
|
26
55
|
end
|
27
56
|
|
28
|
-
|
57
|
+
def root
|
29
58
|
(
|
30
|
-
opening_curly_bracket.ignore
|
31
|
-
key_value.repeat(0, 1)
|
32
|
-
(whitespace?
|
33
|
-
whitespace
|
34
|
-
|
35
|
-
).as(:dictionnary) | list
|
59
|
+
opening_curly_bracket.ignore << whitespace? <<
|
60
|
+
key_value.repeat(0, 1) <<
|
61
|
+
(whitespace? << comma << whitespace? << key_value).repeat <<
|
62
|
+
(whitespace? << closing_curly_bracket.ignore).maybe
|
63
|
+
).aka(:dictionnary) | ::Code::Parser::List
|
36
64
|
end
|
37
|
-
|
38
|
-
root(:dictionnary)
|
39
65
|
end
|
40
66
|
end
|
41
67
|
end
|
data/lib/code/parser/equal.rb
CHANGED
@@ -1,42 +1,94 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class Equal <
|
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
|
-
name.as(:left) >> whitespace? >> operator.as(:operator) >>
|
35
|
-
whitespace? >> rescue_rule.as(:right)
|
36
|
-
).as(:equal) | rescue_rule
|
3
|
+
class Equal < Language
|
4
|
+
def statement
|
5
|
+
::Code::Parser::Rescue
|
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
|
22
|
+
end
|
23
|
+
|
24
|
+
def equal
|
25
|
+
str("=")
|
26
|
+
end
|
27
|
+
|
28
|
+
def plus
|
29
|
+
str("+")
|
30
|
+
end
|
31
|
+
|
32
|
+
def minus
|
33
|
+
str("-")
|
37
34
|
end
|
38
35
|
|
39
|
-
|
36
|
+
def asterisk
|
37
|
+
str("*")
|
38
|
+
end
|
39
|
+
|
40
|
+
def slash
|
41
|
+
str("/")
|
42
|
+
end
|
43
|
+
|
44
|
+
def percent
|
45
|
+
str("%")
|
46
|
+
end
|
47
|
+
|
48
|
+
def greater
|
49
|
+
str(">")
|
50
|
+
end
|
51
|
+
|
52
|
+
def lesser
|
53
|
+
str("<")
|
54
|
+
end
|
55
|
+
|
56
|
+
def ampersand
|
57
|
+
str("&")
|
58
|
+
end
|
59
|
+
|
60
|
+
def pipe
|
61
|
+
str("|")
|
62
|
+
end
|
63
|
+
|
64
|
+
def caret
|
65
|
+
str("^")
|
66
|
+
end
|
67
|
+
|
68
|
+
def dot
|
69
|
+
str(".")
|
70
|
+
end
|
71
|
+
|
72
|
+
def operator
|
73
|
+
equal.ignore | (plus << equal.ignore) | (minus << equal.ignore) |
|
74
|
+
(asterisk << equal.ignore) | (slash << equal.ignore) |
|
75
|
+
(percent << equal.ignore) | (greater << greater << equal.ignore) |
|
76
|
+
(lesser << lesser << equal.ignore) | (ampersand << equal.ignore) |
|
77
|
+
(pipe << equal.ignore) | (caret << equal.ignore) |
|
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
|
91
|
+
end
|
40
92
|
end
|
41
93
|
end
|
42
94
|
end
|
data/lib/code/parser/equality.rb
CHANGED
@@ -1,36 +1,35 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class Equality <
|
4
|
-
|
3
|
+
class Equality < Operation
|
4
|
+
def statement
|
5
|
+
::Code::Parser::Splat
|
6
|
+
end
|
7
|
+
|
8
|
+
def equal
|
9
|
+
str("=")
|
10
|
+
end
|
5
11
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
rule(:exclamation_point) { str("!") }
|
10
|
-
rule(:tilde) { str("~") }
|
12
|
+
def greater
|
13
|
+
str(">")
|
14
|
+
end
|
11
15
|
|
12
|
-
|
13
|
-
(
|
14
|
-
(equal >> equal) | (exclamation_point >> equal) | (equal >> tilde) |
|
15
|
-
(exclamation_point >> tilde)
|
16
|
+
def lesser
|
17
|
+
str("<")
|
16
18
|
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
rule(:whitespace?) { whitespace.maybe }
|
20
|
+
def exclamation_point
|
21
|
+
str("!")
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
(
|
25
|
-
while_parser.as(:first) >>
|
26
|
-
(
|
27
|
-
whitespace? >> operator.as(:operator) >> whitespace? >>
|
28
|
-
while_parser.as(:statement)
|
29
|
-
).repeat(1).as(:rest)
|
30
|
-
).as(:equality) | while_parser
|
24
|
+
def tilde
|
25
|
+
str("~")
|
31
26
|
end
|
32
27
|
|
33
|
-
|
28
|
+
def operator
|
29
|
+
(equal << equal << equal) | (equal << equal) |
|
30
|
+
(lesser << equal << greater) | (exclamation_point << equal) |
|
31
|
+
(equal << tilde) | (tilde << equal) | (exclamation_point << tilde)
|
32
|
+
end
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
data/lib/code/parser/function.rb
CHANGED
@@ -1,60 +1,85 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class Function <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
class Function < Language
|
4
|
+
def name
|
5
|
+
::Code::Parser::Name
|
6
|
+
end
|
7
|
+
|
8
|
+
def code
|
9
|
+
::Code::Parser::Code
|
10
|
+
end
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
rule(:right_caret) { str(">") }
|
13
|
-
rule(:opening_curly_bracket) { str("{") }
|
14
|
-
rule(:closing_curly_bracket) { str("}") }
|
15
|
-
rule(:comma) { str(",") }
|
16
|
-
rule(:colon) { str(":") }
|
17
|
-
rule(:asterisk) { str("*") }
|
18
|
-
rule(:ampersand) { str("&") }
|
12
|
+
def code_present
|
13
|
+
::Code::Parser::Code.new.present
|
14
|
+
end
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
rule(:whitespace?) { whitespace.maybe }
|
16
|
+
def whitespace
|
17
|
+
::Code::Parser::Whitespace
|
18
|
+
end
|
24
19
|
|
25
|
-
|
26
|
-
|
20
|
+
def whitespace?
|
21
|
+
whitespace.maybe
|
27
22
|
end
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
(asterisk >> asterisk).as(:keyword_splat).maybe >>
|
32
|
-
asterisk.as(:splat).maybe >> name >>
|
33
|
-
(
|
34
|
-
whitespace? >> equal >> whitespace? >> code_present.as(:default)
|
35
|
-
).maybe
|
24
|
+
def opening_parenthesis
|
25
|
+
str("(")
|
36
26
|
end
|
37
27
|
|
38
|
-
|
39
|
-
|
28
|
+
def closing_parenthesis
|
29
|
+
str(")")
|
40
30
|
end
|
41
31
|
|
42
|
-
|
43
|
-
|
44
|
-
(whitespace? >> comma >> whitespace? >> argument).repeat
|
32
|
+
def colon
|
33
|
+
str(":")
|
45
34
|
end
|
46
35
|
|
47
|
-
|
48
|
-
(
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
36
|
+
def comma
|
37
|
+
str(",")
|
38
|
+
end
|
39
|
+
|
40
|
+
def equal
|
41
|
+
str("=")
|
42
|
+
end
|
43
|
+
|
44
|
+
def greater
|
45
|
+
str(">")
|
46
|
+
end
|
47
|
+
|
48
|
+
def opening_curly_bracket
|
49
|
+
str("{")
|
55
50
|
end
|
56
51
|
|
57
|
-
|
52
|
+
def closing_curly_bracket
|
53
|
+
str("}")
|
54
|
+
end
|
55
|
+
|
56
|
+
def keyword_parameter
|
57
|
+
name.aka(:name) << whitespace? << colon.aka(:keyword) <<
|
58
|
+
code_present.aka(:default).maybe
|
59
|
+
end
|
60
|
+
|
61
|
+
def regular_parameter
|
62
|
+
name.aka(:name) << whitespace? <<
|
63
|
+
(equal << whitespace? << code_present.aka(:default)).maybe
|
64
|
+
end
|
65
|
+
|
66
|
+
def parameter
|
67
|
+
keyword_parameter | regular_parameter
|
68
|
+
end
|
69
|
+
|
70
|
+
def parameters
|
71
|
+
opening_parenthesis.ignore << whitespace? << parameter.repeat(0, 1) <<
|
72
|
+
(whitespace? << comma << whitespace? << parameter).repeat <<
|
73
|
+
whitespace? << closing_parenthesis.ignore.maybe
|
74
|
+
end
|
75
|
+
|
76
|
+
def root
|
77
|
+
(
|
78
|
+
parameters.aka(:parameters) << whitespace? << equal << greater <<
|
79
|
+
whitespace? << opening_curly_bracket << code.aka(:body) <<
|
80
|
+
closing_curly_bracket.maybe
|
81
|
+
).aka(:function) | ::Code::Parser::ChainedCall
|
82
|
+
end
|
58
83
|
end
|
59
84
|
end
|
60
85
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Code
|
2
|
+
class Parser
|
3
|
+
class Greater < Operation
|
4
|
+
def statement
|
5
|
+
::Code::Parser::BitwiseOr
|
6
|
+
end
|
7
|
+
|
8
|
+
def greater
|
9
|
+
str(">")
|
10
|
+
end
|
11
|
+
|
12
|
+
def lesser
|
13
|
+
str("<")
|
14
|
+
end
|
15
|
+
|
16
|
+
def equal
|
17
|
+
str("=")
|
18
|
+
end
|
19
|
+
|
20
|
+
def operator
|
21
|
+
(greater << equal) | (lesser << equal) | greater | lesser
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/code/parser/group.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class Group <
|
4
|
-
|
5
|
-
|
3
|
+
class Group < Language
|
4
|
+
def code
|
5
|
+
::Code::Parser::Code
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
def opening_parenthesis
|
9
|
+
str("(")
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
(
|
12
|
+
def closing_parenthesis
|
13
|
+
str(")")
|
12
14
|
end
|
13
15
|
|
14
|
-
root
|
16
|
+
def root
|
17
|
+
(opening_parenthesis << code << closing_parenthesis.maybe).aka(:group) |
|
18
|
+
::Code::Parser::Call
|
19
|
+
end
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
data/lib/code/parser/if.rb
CHANGED
@@ -1,33 +1,63 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class If <
|
4
|
-
|
5
|
-
|
3
|
+
class If < Language
|
4
|
+
def statement
|
5
|
+
::Code::Parser::IfModifier
|
6
|
+
end
|
7
|
+
|
8
|
+
def if_class
|
9
|
+
::Code::Parser::If
|
10
|
+
end
|
11
|
+
|
12
|
+
def whitespace
|
13
|
+
::Code::Parser::Whitespace
|
14
|
+
end
|
15
|
+
|
16
|
+
def code
|
17
|
+
::Code::Parser::Code
|
18
|
+
end
|
19
|
+
|
20
|
+
def whitespace?
|
21
|
+
whitespace.maybe
|
22
|
+
end
|
6
23
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
rule(:end_keyword) { str("end") }
|
24
|
+
def if_keyword
|
25
|
+
str("if")
|
26
|
+
end
|
11
27
|
|
12
|
-
|
13
|
-
|
14
|
-
|
28
|
+
def unless_keyword
|
29
|
+
str("unless")
|
30
|
+
end
|
15
31
|
|
16
|
-
|
32
|
+
def elsif_keyword
|
33
|
+
str("elsif")
|
34
|
+
end
|
35
|
+
|
36
|
+
def else_keyword
|
37
|
+
str("else")
|
38
|
+
end
|
39
|
+
|
40
|
+
def end_keyword
|
41
|
+
str("end")
|
42
|
+
end
|
43
|
+
|
44
|
+
def root
|
17
45
|
(
|
18
|
-
(if_keyword | unless_keyword).
|
19
|
-
|
46
|
+
(if_keyword | unless_keyword).aka(:first_operator) << whitespace <<
|
47
|
+
statement.aka(:first_statement) << code.aka(:first_body) <<
|
20
48
|
(
|
21
|
-
|
49
|
+
(
|
50
|
+
elsif_keyword.aka(:operator) << whitespace <<
|
51
|
+
statement.aka(:statement) << code.aka(:body)
|
52
|
+
) |
|
22
53
|
(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
54
|
+
else_keyword << whitespace <<
|
55
|
+
(if_keyword | unless_keyword).aka(:operator) <<
|
56
|
+
whitespace << statement.aka(:statement) << code.aka(:body)
|
57
|
+
) | (else_keyword.aka(:operator) << code.aka(:body))
|
58
|
+
).repeat(1).aka(:elses).maybe << end_keyword.maybe
|
59
|
+
).aka(:if) | statement
|
28
60
|
end
|
29
|
-
|
30
|
-
root(:if_rule)
|
31
61
|
end
|
32
62
|
end
|
33
63
|
end
|
@@ -1,28 +1,55 @@
|
|
1
1
|
class Code
|
2
2
|
class Parser
|
3
|
-
class IfModifier <
|
4
|
-
|
3
|
+
class IfModifier < Language
|
4
|
+
def statement
|
5
|
+
::Code::Parser::OrKeyword
|
6
|
+
end
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
rule(:until_keyword) { str("until") }
|
8
|
+
def if_modifier
|
9
|
+
::Code::Parser::IfModifier
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
def whitespace
|
13
|
+
::Code::Parser::Whitespace.new.without_newline
|
14
|
+
end
|
15
|
+
|
16
|
+
def whitespace?
|
17
|
+
whitespace.maybe
|
13
18
|
end
|
14
19
|
|
15
|
-
|
16
|
-
|
20
|
+
def if_keyword
|
21
|
+
str("if")
|
22
|
+
end
|
17
23
|
|
18
|
-
|
19
|
-
(
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
def unless_keyword
|
25
|
+
str("unless")
|
26
|
+
end
|
27
|
+
|
28
|
+
def while_keyword
|
29
|
+
str("while")
|
30
|
+
end
|
31
|
+
|
32
|
+
def until_keyword
|
33
|
+
str("until")
|
34
|
+
end
|
35
|
+
|
36
|
+
def operator
|
37
|
+
if_keyword | unless_keyword | while_keyword | until_keyword
|
23
38
|
end
|
24
39
|
|
25
|
-
root
|
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
|
26
53
|
end
|
27
54
|
end
|
28
55
|
end
|