shift-lang 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/shift-lang/builder.rb +22 -0
- data/lib/shift-lang/generator/javascript_generator.rb +10 -2
- data/lib/shift-lang/generator/ruby_generator.rb +1 -1
- data/lib/shift-lang/parser/keyword_parser.rb +9 -0
- data/lib/shift-lang/parser/routing_expression_parser.rb +2 -2
- data/lib/shift-lang/parser/token_parser.rb +3 -3
- data/lib/shift-lang/version.rb +1 -1
- metadata +1 -1
data/lib/shift-lang/builder.rb
CHANGED
@@ -42,9 +42,17 @@ module Shift
|
|
42
42
|
case this_statement
|
43
43
|
|
44
44
|
when :model_definition_statement
|
45
|
+
if num_tabs != 0
|
46
|
+
@clean = false
|
47
|
+
puts "Error at line #{line_number} character 1 : #{line}"
|
48
|
+
end
|
45
49
|
model = Builder::DBModel.new(statement[:model_definition_statement][:model_name])
|
46
50
|
|
47
51
|
when :model_attribute_definition_statement
|
52
|
+
if num_tabs != 1
|
53
|
+
@clean = false
|
54
|
+
puts "Error at line #{line_number} character 1 : #{line}"
|
55
|
+
end
|
48
56
|
model_attribute = statement[:model_attribute_definition_statement]
|
49
57
|
model.add_attribute(model_attribute[:attribute_name], model_attribute[:attribute_type])
|
50
58
|
|
@@ -53,14 +61,28 @@ module Shift
|
|
53
61
|
add_model model
|
54
62
|
end
|
55
63
|
|
64
|
+
if num_tabs != 0
|
65
|
+
@clean = false
|
66
|
+
puts "Error at line #{line_number} character 1 : #{line}"
|
67
|
+
end
|
68
|
+
|
56
69
|
url = statement[:url]
|
57
70
|
when :url_method
|
58
71
|
if url_handler
|
59
72
|
add_handler url_handler
|
60
73
|
end
|
61
74
|
|
75
|
+
if num_tabs != 1
|
76
|
+
@clean = false
|
77
|
+
puts "Error at line #{line_number} character 1 : #{line}"
|
78
|
+
end
|
79
|
+
|
62
80
|
url_handler = Builder::UrlHandler.new(url, statement[:url_method].to_s)
|
63
81
|
else
|
82
|
+
if num_tabs < 2
|
83
|
+
@clean = false
|
84
|
+
puts "Error at line #{line_number} character 1 : #{line}"
|
85
|
+
end
|
64
86
|
stmt = {
|
65
87
|
:statement => statement,
|
66
88
|
:num_tabs => num_tabs
|
@@ -213,8 +213,16 @@ module Shift
|
|
213
213
|
case statement[:condition][:operator].to_s.gsub!(" ", "")
|
214
214
|
when "<="
|
215
215
|
condition_expression = "{lte : " + condition_attribute + "}"
|
216
|
+
when ">="
|
217
|
+
condition_expression = "{gte : " + condition_attribute + "}"
|
218
|
+
when "<"
|
219
|
+
condition_expression = "{lt : " + condition_attribute + "}"
|
220
|
+
when ">"
|
221
|
+
condition_expression = "{gt : " + condition_attribute + "}"
|
222
|
+
when "!="
|
223
|
+
condition_expression = "{not : " + condition_attribute + "}"
|
216
224
|
else
|
217
|
-
|
225
|
+
condition_expression = condition_attribute
|
218
226
|
end
|
219
227
|
|
220
228
|
result += "{ " + condition[:attribute] + " : " + condition_expression + " }"
|
@@ -377,7 +385,7 @@ module Shift
|
|
377
385
|
url_handler_template = ERB.new(Shift::Generator::JavaScriptTemplates::URL_HANDLER_DEFINITION)
|
378
386
|
result += "\n" + url_handler_template.result(binding) + "\n"
|
379
387
|
|
380
|
-
defined_hashes = []
|
388
|
+
@defined_hashes = []
|
381
389
|
|
382
390
|
handlers.handler.each do | statement |
|
383
391
|
result += apply_transforms(statement[:statement], statement[:num_tabs] + functions.length)
|
@@ -310,7 +310,7 @@ module Shift
|
|
310
310
|
result = get_import_statements + get_model_data + get_utility_functions
|
311
311
|
|
312
312
|
@builder.handlers.each do | handlers |
|
313
|
-
defined_hashes = []
|
313
|
+
@defined_hashes = []
|
314
314
|
|
315
315
|
result += handlers.method + " '" + url_transform(handlers.url) + "' do\n"
|
316
316
|
|
@@ -48,5 +48,14 @@ module Shift
|
|
48
48
|
|
49
49
|
rule(:integer_cast_keyword) { str('int') }
|
50
50
|
|
51
|
+
rule(:keyword) {
|
52
|
+
read_keyword | write_keyword | write_file_keyword | redirect_keyword |
|
53
|
+
all_keyword | new_keyword | find_keyword | where_keyword | find_by_id_keyword | update_keyword | delete_keyword |
|
54
|
+
if_keyword | else_keyword | for_keyword | in_keyword | while_keyword |
|
55
|
+
get_keyword | post_keyword |
|
56
|
+
model_keyword | string_keyword | integer_keyword |
|
57
|
+
integer_cast_keyword
|
58
|
+
}
|
59
|
+
|
51
60
|
end
|
52
61
|
end
|
@@ -6,9 +6,9 @@ module Shift
|
|
6
6
|
|
7
7
|
rule(:url_method) { get_keyword.as(:url_method) | post_keyword.as(:url_method) }
|
8
8
|
|
9
|
-
rule(:url_variable) { colon >> identifier.as(:url_variable) }
|
9
|
+
rule(:url_variable) { colon >> (identifier.as(:url_variable) | keyword.as(:url_variable)) }
|
10
10
|
|
11
|
-
rule(:url_token) { (url_variable | identifier.as(:url_token)) >> fwd_slash.maybe }
|
11
|
+
rule(:url_token) { (url_variable | (identifier.as(:url_token) | keyword.as(:url_variable))) >> fwd_slash.maybe }
|
12
12
|
|
13
13
|
rule(:url) { fwd_slash >> url_token.repeat(0) }
|
14
14
|
|
@@ -47,12 +47,12 @@ module Shift
|
|
47
47
|
end
|
48
48
|
rule(:string_value) { single_quoted_string | double_quoted_string }
|
49
49
|
|
50
|
-
rule(:identifier) { match('[A-Za-z]') >> match['[A-Za-z0-9_]'].repeat(0) }
|
50
|
+
rule(:identifier) { keyword.absent? >> match('[A-Za-z]') >> match['[A-Za-z0-9_]'].repeat(0) }
|
51
51
|
|
52
52
|
rule(:hash_attribute) { string_value | identifier }
|
53
|
-
rule(:hash_value) { identifier >> left_square_bracket >> hash_attribute >> right_square_bracket }
|
53
|
+
rule(:hash_value) { keyword.absent? >> identifier >> left_square_bracket >> hash_attribute >> right_square_bracket }
|
54
54
|
|
55
|
-
rule(:object_value) { identifier >> dot >> identifier }
|
55
|
+
rule(:object_value) { keyword.absent? >> identifier >> dot >> keyword.absent? >> identifier }
|
56
56
|
|
57
57
|
rule(:variables) { space? >> (object_value.as(:object_value) | hash_value.as(:hash_value) | identifier.as(:identifier)) >> space? }
|
58
58
|
|
data/lib/shift-lang/version.rb
CHANGED