haml-more 0.4.0.a
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +79 -0
- data/lib/haml/more/coffee_script.rb +137 -0
- data/lib/haml/more/content_for.rb +25 -0
- data/lib/haml/more.rb +45 -0
- data/lib/haml-more.rb +1 -0
- data/lib/sass/more.rb +16 -0
- data/lib/sass-more.rb +1 -0
- data/spec/sass/more_spec.rb +21 -0
- data/vendor/coffee-script/Cakefile +57 -0
- data/vendor/coffee-script/LICENSE +22 -0
- data/vendor/coffee-script/README +41 -0
- data/vendor/coffee-script/Rakefile +20 -0
- data/vendor/coffee-script/bin/cake +7 -0
- data/vendor/coffee-script/bin/coffee +7 -0
- data/vendor/coffee-script/documentation/coffee/aliases.coffee +9 -0
- data/vendor/coffee-script/documentation/coffee/arguments.coffee +4 -0
- data/vendor/coffee-script/documentation/coffee/array_comprehensions.coffee +7 -0
- data/vendor/coffee-script/documentation/coffee/assignment.coffee +2 -0
- data/vendor/coffee-script/documentation/coffee/cake_tasks.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/comparisons.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/conditionals.coffee +9 -0
- data/vendor/coffee-script/documentation/coffee/embedded.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/existence.coffee +8 -0
- data/vendor/coffee-script/documentation/coffee/expressions.coffee +9 -0
- data/vendor/coffee-script/documentation/coffee/expressions_assignment.coffee +1 -0
- data/vendor/coffee-script/documentation/coffee/expressions_comprehension.coffee +3 -0
- data/vendor/coffee-script/documentation/coffee/expressions_try.coffee +6 -0
- data/vendor/coffee-script/documentation/coffee/fat_arrow.coffee +6 -0
- data/vendor/coffee-script/documentation/coffee/functions.coffee +2 -0
- data/vendor/coffee-script/documentation/coffee/heredocs.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/multiple_return_values.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/object_comprehensions.coffee +4 -0
- data/vendor/coffee-script/documentation/coffee/object_extraction.coffee +13 -0
- data/vendor/coffee-script/documentation/coffee/objects_and_arrays.coffee +13 -0
- data/vendor/coffee-script/documentation/coffee/overview.coffee +29 -0
- data/vendor/coffee-script/documentation/coffee/parallel_assignment.coffee +4 -0
- data/vendor/coffee-script/documentation/coffee/range_comprehensions.coffee +6 -0
- data/vendor/coffee-script/documentation/coffee/scope.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/slices.coffee +6 -0
- data/vendor/coffee-script/documentation/coffee/soaks.coffee +1 -0
- data/vendor/coffee-script/documentation/coffee/splats.coffee +25 -0
- data/vendor/coffee-script/documentation/coffee/splices.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/strings.coffee +8 -0
- data/vendor/coffee-script/documentation/coffee/super.coffee +34 -0
- data/vendor/coffee-script/documentation/coffee/switch.coffee +10 -0
- data/vendor/coffee-script/documentation/coffee/try.coffee +7 -0
- data/vendor/coffee-script/documentation/coffee/while.coffee +10 -0
- data/vendor/coffee-script/documentation/css/docs.css +213 -0
- data/vendor/coffee-script/documentation/css/idle.css +63 -0
- data/vendor/coffee-script/documentation/css/logo.png +0 -0
- data/vendor/coffee-script/documentation/index.html.erb +967 -0
- data/vendor/coffee-script/documentation/js/aliases.js +14 -0
- data/vendor/coffee-script/documentation/js/arguments.js +8 -0
- data/vendor/coffee-script/documentation/js/array_comprehensions.js +26 -0
- data/vendor/coffee-script/documentation/js/assignment.js +5 -0
- data/vendor/coffee-script/documentation/js/cake_tasks.js +14 -0
- data/vendor/coffee-script/documentation/js/comparisons.js +5 -0
- data/vendor/coffee-script/documentation/js/conditionals.js +12 -0
- data/vendor/coffee-script/documentation/js/embedded.js +6 -0
- data/vendor/coffee-script/documentation/js/existence.js +7 -0
- data/vendor/coffee-script/documentation/js/expressions.js +13 -0
- data/vendor/coffee-script/documentation/js/expressions_assignment.js +4 -0
- data/vendor/coffee-script/documentation/js/expressions_comprehension.js +12 -0
- data/vendor/coffee-script/documentation/js/expressions_try.js +9 -0
- data/vendor/coffee-script/documentation/js/fat_arrow.js +15 -0
- data/vendor/coffee-script/documentation/js/functions.js +9 -0
- data/vendor/coffee-script/documentation/js/heredocs.js +4 -0
- data/vendor/coffee-script/documentation/js/intro.js +7 -0
- data/vendor/coffee-script/documentation/js/multiple_return_values.js +11 -0
- data/vendor/coffee-script/documentation/js/object_comprehensions.js +17 -0
- data/vendor/coffee-script/documentation/js/object_extraction.js +17 -0
- data/vendor/coffee-script/documentation/js/objects_and_arrays.js +10 -0
- data/vendor/coffee-script/documentation/js/overview.js +43 -0
- data/vendor/coffee-script/documentation/js/parallel_assignment.js +8 -0
- data/vendor/coffee-script/documentation/js/punctuation.js +8 -0
- data/vendor/coffee-script/documentation/js/range_comprehensions.js +21 -0
- data/vendor/coffee-script/documentation/js/scope.js +10 -0
- data/vendor/coffee-script/documentation/js/slices.js +6 -0
- data/vendor/coffee-script/documentation/js/soaks.js +4 -0
- data/vendor/coffee-script/documentation/js/splats.js +16 -0
- data/vendor/coffee-script/documentation/js/splices.js +5 -0
- data/vendor/coffee-script/documentation/js/strings.js +9 -0
- data/vendor/coffee-script/documentation/js/super.js +37 -0
- data/vendor/coffee-script/documentation/js/switch.js +18 -0
- data/vendor/coffee-script/documentation/js/try.js +10 -0
- data/vendor/coffee-script/documentation/js/while.js +22 -0
- data/vendor/coffee-script/documentation/underscore.html +627 -0
- data/vendor/coffee-script/examples/beautiful_code/binary_search.coffee +16 -0
- data/vendor/coffee-script/examples/beautiful_code/quicksort_runtime.coffee +13 -0
- data/vendor/coffee-script/examples/beautiful_code/regular_expression_matcher.coffee +34 -0
- data/vendor/coffee-script/examples/blocks.coffee +57 -0
- data/vendor/coffee-script/examples/code.coffee +173 -0
- data/vendor/coffee-script/examples/computer_science/README +4 -0
- data/vendor/coffee-script/examples/computer_science/binary_search.coffee +25 -0
- data/vendor/coffee-script/examples/computer_science/bubble_sort.coffee +11 -0
- data/vendor/coffee-script/examples/computer_science/linked_list.coffee +106 -0
- data/vendor/coffee-script/examples/computer_science/luhn_algorithm.coffee +36 -0
- data/vendor/coffee-script/examples/computer_science/merge_sort.coffee +19 -0
- data/vendor/coffee-script/examples/computer_science/selection_sort.coffee +23 -0
- data/vendor/coffee-script/examples/poignant.coffee +186 -0
- data/vendor/coffee-script/examples/potion.coffee +205 -0
- data/vendor/coffee-script/examples/underscore.coffee +603 -0
- data/vendor/coffee-script/examples/web_server.coffee +12 -0
- data/vendor/coffee-script/extras/CoffeeScript.tmbundle/Preferences/CoffeeScript.tmPreferences +24 -0
- data/vendor/coffee-script/extras/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +361 -0
- data/vendor/coffee-script/extras/CoffeeScript.tmbundle/info.plist +10 -0
- data/vendor/coffee-script/extras/EXTRAS +20 -0
- data/vendor/coffee-script/extras/coffee.vim +117 -0
- data/vendor/coffee-script/index.html +1847 -0
- data/vendor/coffee-script/lib/bin/cake +7 -0
- data/vendor/coffee-script/lib/bin/coffee +7 -0
- data/vendor/coffee-script/lib/cake.js +80 -0
- data/vendor/coffee-script/lib/coffee-script.js +61 -0
- data/vendor/coffee-script/lib/command_line.js +201 -0
- data/vendor/coffee-script/lib/grammar.js +564 -0
- data/vendor/coffee-script/lib/lexer.js +405 -0
- data/vendor/coffee-script/lib/narwhal.js +44 -0
- data/vendor/coffee-script/lib/nodes.js +1328 -0
- data/vendor/coffee-script/lib/optparse.js +117 -0
- data/vendor/coffee-script/lib/parser.js +536 -0
- data/vendor/coffee-script/lib/repl.js +32 -0
- data/vendor/coffee-script/lib/rewriter.js +383 -0
- data/vendor/coffee-script/lib/scope.js +114 -0
- data/vendor/coffee-script/package.json +7 -0
- data/vendor/coffee-script/src/cake.coffee +45 -0
- data/vendor/coffee-script/src/coffee-script.coffee +45 -0
- data/vendor/coffee-script/src/command_line.coffee +130 -0
- data/vendor/coffee-script/src/grammar.coffee +456 -0
- data/vendor/coffee-script/src/lexer.coffee +327 -0
- data/vendor/coffee-script/src/narwhal.coffee +42 -0
- data/vendor/coffee-script/src/nodes.coffee +1045 -0
- data/vendor/coffee-script/src/optparse.coffee +79 -0
- data/vendor/coffee-script/src/repl.coffee +23 -0
- data/vendor/coffee-script/src/rewriter.coffee +253 -0
- data/vendor/coffee-script/src/scope.coffee +75 -0
- data/vendor/coffee-script/test/test_arguments.coffee +34 -0
- data/vendor/coffee-script/test/test_array_comprehension.coffee +42 -0
- data/vendor/coffee-script/test/test_assignment.coffee +26 -0
- data/vendor/coffee-script/test/test_blocks.coffee +4 -0
- data/vendor/coffee-script/test/test_calling_super.coffee +42 -0
- data/vendor/coffee-script/test/test_chained_calls.coffee +25 -0
- data/vendor/coffee-script/test/test_destructuring_assignment.coffee +62 -0
- data/vendor/coffee-script/test/test_everything.coffee +29 -0
- data/vendor/coffee-script/test/test_exceptions.coffee +2 -0
- data/vendor/coffee-script/test/test_existence.coffee +81 -0
- data/vendor/coffee-script/test/test_expressions.coffee +30 -0
- data/vendor/coffee-script/test/test_fancy_if_statement.coffee +26 -0
- data/vendor/coffee-script/test/test_functions.coffee +80 -0
- data/vendor/coffee-script/test/test_funky_comments.coffee +25 -0
- data/vendor/coffee-script/test/test_heredocs.coffee +46 -0
- data/vendor/coffee-script/test/test_lexical_scope.coffee +10 -0
- data/vendor/coffee-script/test/test_literals.coffee +56 -0
- data/vendor/coffee-script/test/test_nested_comprehensions.coffee +11 -0
- data/vendor/coffee-script/test/test_newline_escaping.coffee +6 -0
- data/vendor/coffee-script/test/test_operations.coffee +18 -0
- data/vendor/coffee-script/test/test_range_comprehension.coffee +20 -0
- data/vendor/coffee-script/test/test_ranges_and_slices.coffee +16 -0
- data/vendor/coffee-script/test/test_splats.coffee +47 -0
- data/vendor/coffee-script/test/test_splices.coffee +5 -0
- data/vendor/coffee-script/test/test_switch.coffee +64 -0
- data/vendor/coffee-script/test/test_while.coffee +30 -0
- data/vendor/coffee-script/vendor/jison/Jakefile +31 -0
- data/vendor/coffee-script/vendor/jison/README.md +347 -0
- data/vendor/coffee-script/vendor/jison/bin/jison +3 -0
- data/vendor/coffee-script/vendor/jison/bin/json2jison +3 -0
- data/vendor/coffee-script/vendor/jison/examples/ansic.jison +415 -0
- data/vendor/coffee-script/vendor/jison/examples/basic.json +8 -0
- data/vendor/coffee-script/vendor/jison/examples/basic2.json +9 -0
- data/vendor/coffee-script/vendor/jison/examples/basic2_lex.json +16 -0
- data/vendor/coffee-script/vendor/jison/examples/basic_lex.json +15 -0
- data/vendor/coffee-script/vendor/jison/examples/calculator.jison +38 -0
- data/vendor/coffee-script/vendor/jison/examples/calculator.jisonlex +14 -0
- data/vendor/coffee-script/vendor/jison/examples/calculator.json +42 -0
- data/vendor/coffee-script/vendor/jison/examples/classy.json +105 -0
- data/vendor/coffee-script/vendor/jison/examples/classy_ast.json +126 -0
- data/vendor/coffee-script/vendor/jison/examples/dism.json +25 -0
- data/vendor/coffee-script/vendor/jison/examples/dism_lr0.json +26 -0
- data/vendor/coffee-script/vendor/jison/examples/json.js +80 -0
- data/vendor/coffee-script/vendor/jison/examples/json_ast.js +83 -0
- data/vendor/coffee-script/vendor/jison/examples/precedence.json +26 -0
- data/vendor/coffee-script/vendor/jison/examples/reduce_conflict.json +13 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/bnf.js +43 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/jisonlex.js +18 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/json2jison.js +146 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/lexer.js +224 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/util/bnf-parser.js +383 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/util/lex-parser.js +407 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/util/set.js +94 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/util/typal.js +90 -0
- data/vendor/coffee-script/vendor/jison/lib/jison.js +1414 -0
- data/vendor/coffee-script/vendor/jison/package.json +14 -0
- data/vendor/coffee-script/vendor/jison/src/bnf.jison +110 -0
- data/vendor/coffee-script/vendor/jison/src/bnf.jisonlex +25 -0
- data/vendor/coffee-script/vendor/jison/src/bnf.lex.json +24 -0
- data/vendor/coffee-script/vendor/jison/src/jisonlex.jison +129 -0
- data/vendor/coffee-script/vendor/jison/src/jisonlex.jisonlex +31 -0
- data/vendor/coffee-script/vendor/jison/src/jisonlex.lex.json +30 -0
- data/vendor/coffee-script/vendor/jison/tests/all-tests.js +8 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/bnf.js +91 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/bnf_parse.js +65 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/grammar-tests.js +10 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/json2jison.js +24 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/ansic.jisonlex +115 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/bnf.jisonlex +25 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/bnf.lex.json +24 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/lex_grammar.jisonlex +31 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/lex_grammar.lex.json +30 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex.jison +119 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex.js +58 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex_parse.js +117 -0
- data/vendor/coffee-script/vendor/jison/tests/lexer/lexer-tests.js +6 -0
- data/vendor/coffee-script/vendor/jison/tests/lexer/regexplexer.js +417 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/actions.js +311 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/api.js +236 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/generator.js +196 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/lalr.js +183 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/lr0.js +72 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/lr1.js +119 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/parser-tests.js +14 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/precedence.js +237 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/slr.js +52 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/tables.js +126 -0
- data/vendor/coffee-script/vendor/jison/tests/performance.js +110 -0
- data/vendor/coffee-script/vendor/jison/tests/setup.js +3 -0
- metadata +324 -0
@@ -0,0 +1,237 @@
|
|
1
|
+
var Jison = require("../setup").Jison,
|
2
|
+
RegExpLexer = require("../setup").RegExpLexer,
|
3
|
+
assert = require("assert");
|
4
|
+
|
5
|
+
var lexData = {
|
6
|
+
rules: [
|
7
|
+
["x", "return 'x';"],
|
8
|
+
["\\+", "return '+';"],
|
9
|
+
["$", "return 'EOF';"]
|
10
|
+
]
|
11
|
+
};
|
12
|
+
|
13
|
+
exports["test Left associative rule"] = function () {
|
14
|
+
var lexData = {
|
15
|
+
rules: [
|
16
|
+
["x", "return 'x';"],
|
17
|
+
["\\+", "return '+';"],
|
18
|
+
["$", "return 'EOF';"]
|
19
|
+
]
|
20
|
+
};
|
21
|
+
var grammar = {
|
22
|
+
tokens: [ "x", "+", "EOF" ],
|
23
|
+
startSymbol: "S",
|
24
|
+
operators: [
|
25
|
+
["left", "+"]
|
26
|
+
],
|
27
|
+
bnf: {
|
28
|
+
"S" :[ [ 'E EOF', "return $1;" ] ],
|
29
|
+
"E" :[ [ "E + E", "$$ = ['+', $1, $3];" ],
|
30
|
+
[ "x", "$$ = ['x'];"] ]
|
31
|
+
}
|
32
|
+
};
|
33
|
+
|
34
|
+
var parser = new Jison.Parser(grammar);
|
35
|
+
parser.lexer = new RegExpLexer(lexData);
|
36
|
+
|
37
|
+
var expectedAST = ["+", ["+", ["x"], ["x"]], ["x"]];
|
38
|
+
|
39
|
+
var r = parser.parse("x+x+x");
|
40
|
+
assert.deepEqual(r, expectedAST);
|
41
|
+
};
|
42
|
+
|
43
|
+
exports["test Right associative rule"] = function () {
|
44
|
+
var lexData = {
|
45
|
+
rules: [
|
46
|
+
["x", "return 'x';"],
|
47
|
+
["\\+", "return '+';"],
|
48
|
+
["$", "return 'EOF';"]
|
49
|
+
]
|
50
|
+
};
|
51
|
+
var grammar = {
|
52
|
+
tokens: [ "x", "+", "EOF" ],
|
53
|
+
startSymbol: "S",
|
54
|
+
operators: [
|
55
|
+
["right", "+"]
|
56
|
+
],
|
57
|
+
bnf: {
|
58
|
+
"S" :[ [ "E EOF", "return $1;" ] ],
|
59
|
+
"E" :[ [ "E + E", "$$ = ['+', $1, $3];" ],
|
60
|
+
[ "x", "$$ = ['x'];" ] ]
|
61
|
+
}
|
62
|
+
};
|
63
|
+
|
64
|
+
var parser = new Jison.Parser(grammar);
|
65
|
+
parser.lexer = new RegExpLexer(lexData);
|
66
|
+
|
67
|
+
var expectedAST = ["+", ["x"], ["+", ["x"], ["x"]]];
|
68
|
+
|
69
|
+
var r = parser.parse("x+x+x");
|
70
|
+
assert.deepEqual(r, expectedAST);
|
71
|
+
};
|
72
|
+
|
73
|
+
exports["test Multiple precedence operators"] = function () {
|
74
|
+
var lexData = {
|
75
|
+
rules: [
|
76
|
+
["x", "return 'x';"],
|
77
|
+
["\\+", "return '+';"],
|
78
|
+
["\\*", "return '*';"],
|
79
|
+
["$", "return 'EOF';"]
|
80
|
+
]
|
81
|
+
};
|
82
|
+
var grammar = {
|
83
|
+
tokens: [ "x", "+", "*", "EOF" ],
|
84
|
+
startSymbol: "S",
|
85
|
+
operators: [
|
86
|
+
["left", "+"],
|
87
|
+
["left", "*"]
|
88
|
+
],
|
89
|
+
bnf: {
|
90
|
+
"S" :[ [ "E EOF", "return $1;" ] ],
|
91
|
+
"E" :[ [ "E + E", "$$ = ['+', $1, $3];" ],
|
92
|
+
[ "E * E", "$$ = ['*', $1, $3];" ],
|
93
|
+
[ "x", "$$ = ['x'];" ] ]
|
94
|
+
}
|
95
|
+
};
|
96
|
+
|
97
|
+
var parser = new Jison.Parser(grammar);
|
98
|
+
parser.lexer = new RegExpLexer(lexData);
|
99
|
+
|
100
|
+
var expectedAST = ["+", ["*", ["x"], ["x"]], ["x"]];
|
101
|
+
|
102
|
+
var r = parser.parse("x*x+x");
|
103
|
+
assert.deepEqual(r, expectedAST);
|
104
|
+
};
|
105
|
+
|
106
|
+
exports["test Multiple precedence operators"] = function () {
|
107
|
+
var lexData = {
|
108
|
+
rules: [
|
109
|
+
["x", "return 'x';"],
|
110
|
+
["\\+", "return '+';"],
|
111
|
+
["\\*", "return '*';"],
|
112
|
+
["$", "return 'EOF';"]
|
113
|
+
]
|
114
|
+
};
|
115
|
+
var grammar = {
|
116
|
+
tokens: [ "x", "+", "*", "EOF" ],
|
117
|
+
startSymbol: "S",
|
118
|
+
operators: [
|
119
|
+
["left", "+"],
|
120
|
+
["left", "*"]
|
121
|
+
],
|
122
|
+
bnf: {
|
123
|
+
"S" :[ [ "E EOF", "return $1;" ] ],
|
124
|
+
"E" :[ [ "E + E", "$$ = [$1,'+', $3];" ],
|
125
|
+
[ "E * E", "$$ = [$1, '*', $3];" ],
|
126
|
+
[ "x", "$$ = ['x'];" ] ]
|
127
|
+
}
|
128
|
+
};
|
129
|
+
|
130
|
+
var parser = new Jison.Parser(grammar);
|
131
|
+
parser.lexer = new RegExpLexer(lexData);
|
132
|
+
|
133
|
+
var expectedAST = [["x"], "+", [["x"], "*", ["x"]]];
|
134
|
+
|
135
|
+
var r = parser.parse("x+x*x");
|
136
|
+
assert.deepEqual(r, expectedAST);
|
137
|
+
};
|
138
|
+
|
139
|
+
exports["test Non-associative operator"] = function () {
|
140
|
+
var lexData = {
|
141
|
+
rules: [
|
142
|
+
["x", "return 'x';"],
|
143
|
+
["=", "return '=';"],
|
144
|
+
["$", "return 'EOF';"]
|
145
|
+
]
|
146
|
+
};
|
147
|
+
var grammar = {
|
148
|
+
tokens: [ "x", "=", "EOF" ],
|
149
|
+
startSymbol: "S",
|
150
|
+
operators: [
|
151
|
+
["nonassoc", "="]
|
152
|
+
],
|
153
|
+
bnf: {
|
154
|
+
"S" :[ "E EOF" ],
|
155
|
+
"E" :[ "E = E",
|
156
|
+
"x" ]
|
157
|
+
}
|
158
|
+
};
|
159
|
+
|
160
|
+
var parser = new Jison.Parser(grammar, {type: "lalr"});
|
161
|
+
parser.lexer = new RegExpLexer(lexData);
|
162
|
+
|
163
|
+
assert["throws"](function () {parser.parse("x=x=x");}, "throws parse error when operator used twice.");
|
164
|
+
assert.ok(parser.parse("x=x"), "normal use is okay.");
|
165
|
+
};
|
166
|
+
|
167
|
+
exports["test Context-dependent precedence"] = function () {
|
168
|
+
var lexData = {
|
169
|
+
rules: [
|
170
|
+
["x", "return 'x';"],
|
171
|
+
["-", "return '-';"],
|
172
|
+
["\\+", "return '+';"],
|
173
|
+
["\\*", "return '*';"],
|
174
|
+
["$", "return 'EOF';"]
|
175
|
+
]
|
176
|
+
};
|
177
|
+
var grammar = {
|
178
|
+
tokens: [ "x", "-", "+", "*", "EOF" ],
|
179
|
+
startSymbol: "S",
|
180
|
+
operators: [
|
181
|
+
["left", "-", "+"],
|
182
|
+
["left", "*"],
|
183
|
+
["left", "UMINUS"]
|
184
|
+
],
|
185
|
+
bnf: {
|
186
|
+
"S" :[ [ "E EOF", "return $1;" ] ],
|
187
|
+
"E" :[ [ "E - E", "$$ = [$1,'-', $3];" ],
|
188
|
+
[ "E + E", "$$ = [$1,'+', $3];" ],
|
189
|
+
[ "E * E", "$$ = [$1,'*', $3];" ],
|
190
|
+
[ "- E", "$$ = ['#', $2];", {prec: "UMINUS"} ],
|
191
|
+
[ "x", "$$ = ['x'];" ] ]
|
192
|
+
}
|
193
|
+
};
|
194
|
+
|
195
|
+
var parser = new Jison.Parser(grammar, {type: "slr"});
|
196
|
+
parser.lexer = new RegExpLexer(lexData);
|
197
|
+
|
198
|
+
var expectedAST = [[[["#", ["x"]], "*", ["#", ["x"]]], "*", ["x"]], "-", ["x"]];
|
199
|
+
|
200
|
+
var r = parser.parse("-x*-x*x-x");
|
201
|
+
assert.deepEqual(r, expectedAST);
|
202
|
+
};
|
203
|
+
|
204
|
+
exports["test multi-operator rules"] = function () {
|
205
|
+
var lexData = {
|
206
|
+
rules: [
|
207
|
+
["x", "return 'ID';"],
|
208
|
+
["\\.", "return 'DOT';"],
|
209
|
+
["=", "return 'ASSIGN';"],
|
210
|
+
["\\(", "return 'LPAREN';"],
|
211
|
+
["\\)", "return 'RPAREN';"],
|
212
|
+
["$", "return 'EOF';"]
|
213
|
+
]
|
214
|
+
};
|
215
|
+
var grammar = {
|
216
|
+
tokens: "ID DOT ASSIGN LPAREN RPAREN EOF",
|
217
|
+
startSymbol: "S",
|
218
|
+
operators: [
|
219
|
+
["right", "ASSIGN"],
|
220
|
+
["left", "DOT"]
|
221
|
+
],
|
222
|
+
bnf: {
|
223
|
+
"S" :[ [ "e EOF", "return $1;" ] ],
|
224
|
+
"id":[ [ "ID", "$$ = ['ID'];"] ],
|
225
|
+
"e" :[ [ "e DOT id", "$$ = [$1,'-', $3];" ],
|
226
|
+
[ "e DOT id ASSIGN e", "$$ = [$1,'=', $3];" ],
|
227
|
+
[ "e DOT id LPAREN e RPAREN", "$$ = [$1,'+', $3];" ],
|
228
|
+
[ "id ASSIGN e", "$$ = [$1,'+', $3];" ],
|
229
|
+
[ "id LPAREN e RPAREN", "$$ = [$1,'+', $3];" ],
|
230
|
+
[ "id", "$$ = $1;" ] ]
|
231
|
+
}
|
232
|
+
};
|
233
|
+
|
234
|
+
var gen = new Jison.Generator(grammar, {type: 'slr'});
|
235
|
+
|
236
|
+
assert.equal(gen.conflicts, 0);
|
237
|
+
};
|
@@ -0,0 +1,52 @@
|
|
1
|
+
var Jison = require("../setup").Jison,
|
2
|
+
Lexer = require("../setup").Lexer,
|
3
|
+
assert = require("assert");
|
4
|
+
|
5
|
+
var lexData = {
|
6
|
+
rules: [
|
7
|
+
["x", "return 'x';"],
|
8
|
+
["y", "return 'y';"]
|
9
|
+
]
|
10
|
+
};
|
11
|
+
|
12
|
+
exports["test left-recursive nullable grammar"] = function () {
|
13
|
+
|
14
|
+
var grammar = {
|
15
|
+
tokens: [ 'x' ],
|
16
|
+
startSymbol: "A",
|
17
|
+
bnf: {
|
18
|
+
"A" :[ 'A x',
|
19
|
+
'' ]
|
20
|
+
}
|
21
|
+
};
|
22
|
+
|
23
|
+
var gen = new Jison.Generator(grammar, {type: "slr"});
|
24
|
+
var parser = gen.createParser();
|
25
|
+
parser.lexer = new Lexer(lexData);
|
26
|
+
|
27
|
+
assert.ok(parser.parse('xxx'), "parse 3 x's");
|
28
|
+
assert.ok(parser.parse("x"), "parse single x");
|
29
|
+
assert["throws"](function(){parser.parse("y")}, "throws parse error on invalid token");
|
30
|
+
assert.ok(gen.conflicts == 0, "no conflicts");
|
31
|
+
};
|
32
|
+
|
33
|
+
exports["test right-recursive nullable grammar"] = function () {
|
34
|
+
|
35
|
+
var grammar = {
|
36
|
+
tokens: [ 'x' ],
|
37
|
+
startSymbol: "A",
|
38
|
+
bnf: {
|
39
|
+
"A" :[ 'x A',
|
40
|
+
'' ]
|
41
|
+
}
|
42
|
+
};
|
43
|
+
|
44
|
+
var gen = new Jison.Generator(grammar, {type: "slr"});
|
45
|
+
var parser = gen.createParser();
|
46
|
+
parser.lexer = new Lexer(lexData);
|
47
|
+
|
48
|
+
assert.ok(parser.parse('xxx'), "parse 3 x's");
|
49
|
+
assert.ok(gen.table.length == 4, "table has 4 states");
|
50
|
+
assert.ok(gen.conflicts == 0, "no conflicts");
|
51
|
+
assert.equal(gen.nullable('A'), true, "A is nullable");
|
52
|
+
};
|
@@ -0,0 +1,126 @@
|
|
1
|
+
var Jison = require("../setup").Jison,
|
2
|
+
assert = require("assert");
|
3
|
+
|
4
|
+
exports["test right-recursive nullable grammar"] = function () {
|
5
|
+
|
6
|
+
var grammar = {
|
7
|
+
tokens: [ 'x' ],
|
8
|
+
startSymbol: "A",
|
9
|
+
bnf: {
|
10
|
+
"A" :[ 'x A',
|
11
|
+
'' ]
|
12
|
+
}
|
13
|
+
};
|
14
|
+
|
15
|
+
var gen = new Jison.Generator(grammar, {type: "slr"});
|
16
|
+
var gen2 = new Jison.Generator(grammar, {type: "lalr"});
|
17
|
+
|
18
|
+
assert.equal(gen.table.length, 4, "table has 4 states");
|
19
|
+
assert.equal(gen.nullable('A'), true, "A is nullable");
|
20
|
+
assert.equal(gen.conflicts, 0, "should have no conflict");
|
21
|
+
assert.deepEqual(gen.table, gen2.table, "should have identical tables");
|
22
|
+
};
|
23
|
+
|
24
|
+
exports["test slr lalr lr tables are equal"] = function () {
|
25
|
+
var grammar = {
|
26
|
+
tokens: [ "ZERO", "PLUS"],
|
27
|
+
startSymbol: "E",
|
28
|
+
bnf: {
|
29
|
+
"E" :[ "E PLUS T",
|
30
|
+
"T" ],
|
31
|
+
"T" :[ "ZERO" ]
|
32
|
+
}
|
33
|
+
};
|
34
|
+
|
35
|
+
var gen = new Jison.Generator(grammar, {type: "slr"});
|
36
|
+
var gen2 = new Jison.Generator(grammar, {type: "lalr"});
|
37
|
+
var gen3 = new Jison.Generator(grammar, {type: "lr"});
|
38
|
+
|
39
|
+
assert.deepEqual(gen.table, gen2.table, "slr lalr should have identical tables");
|
40
|
+
assert.deepEqual(gen2.table, gen3.table, "lalr lr should have identical tables");
|
41
|
+
};
|
42
|
+
|
43
|
+
exports["test LL parse table"] = function () {
|
44
|
+
|
45
|
+
var grammar = {
|
46
|
+
tokens: [ 'x' ],
|
47
|
+
startSymbol: "A",
|
48
|
+
bnf: {
|
49
|
+
"A" :[ 'x A',
|
50
|
+
'' ]
|
51
|
+
}
|
52
|
+
};
|
53
|
+
|
54
|
+
var gen = new Jison.Generator(grammar, {type: "ll"});
|
55
|
+
|
56
|
+
assert.deepEqual(gen.table, {$accept:{x:[0], $end:[0]}, A:{x:[1], $end:[2]}}, "ll table has 2 states");
|
57
|
+
};
|
58
|
+
|
59
|
+
exports["test LL parse table with conflict"] = function () {
|
60
|
+
|
61
|
+
var grammar = {
|
62
|
+
tokens: [ 'x' ],
|
63
|
+
startSymbol: "L",
|
64
|
+
bnf: {
|
65
|
+
"L" :[ 'T L T',
|
66
|
+
'' ],
|
67
|
+
"T" :[ "x" ]
|
68
|
+
}
|
69
|
+
};
|
70
|
+
|
71
|
+
var gen = new Jison.Generator(grammar, {type: "ll"});
|
72
|
+
assert.equal(gen.conflicts, 1, "should have 1 conflict");
|
73
|
+
};
|
74
|
+
|
75
|
+
exports["test Ambigous grammar"] = function () {
|
76
|
+
|
77
|
+
var grammar = {
|
78
|
+
tokens: [ 'x', 'y' ],
|
79
|
+
startSymbol: "A",
|
80
|
+
bnf: {
|
81
|
+
"A" :[ 'A B A',
|
82
|
+
'x' ],
|
83
|
+
"B" :[ '',
|
84
|
+
'y' ]
|
85
|
+
}
|
86
|
+
};
|
87
|
+
|
88
|
+
var gen = new Jison.Generator(grammar, {type: "lr"});
|
89
|
+
assert.equal(gen.conflicts, 2, "should have 2 conflict");
|
90
|
+
};
|
91
|
+
|
92
|
+
// for Minimal LR testing. Not there yet.
|
93
|
+
/*exports["test Spector grammar G1"] = function () {*/
|
94
|
+
|
95
|
+
//var grammar = {
|
96
|
+
//"tokens": "z d b c a",
|
97
|
+
//"startSymbol": "S",
|
98
|
+
//"bnf": {
|
99
|
+
//"S" :[ "a A c",
|
100
|
+
//"a B d",
|
101
|
+
//"b A d",
|
102
|
+
//"b B c"],
|
103
|
+
//"A" :[ "z" ],
|
104
|
+
//"B" :[ "z" ]
|
105
|
+
//}
|
106
|
+
//};
|
107
|
+
|
108
|
+
//var gen = new Jison.Generator(grammar, {type: "mlr", debug:true});
|
109
|
+
//assert.strictEqual(gen.conflicts, 0, "should have no conflict");
|
110
|
+
//};
|
111
|
+
|
112
|
+
//exports["test De Remer G4"] = function () {
|
113
|
+
|
114
|
+
//var grammar = {
|
115
|
+
//"tokens": "z d b c a",
|
116
|
+
//"startSymbol": "S",
|
117
|
+
//"bnf": {
|
118
|
+
//"S" : "a A d | b A c | b B d",
|
119
|
+
//"A" : "e A | e",
|
120
|
+
//"B" : "e B | e"
|
121
|
+
//}
|
122
|
+
//};
|
123
|
+
|
124
|
+
//var gen = new Jison.Generator(grammar, {type: "mlr", debug:true});
|
125
|
+
//assert.strictEqual(gen.conflicts, 0, "should have no conflict");
|
126
|
+
/*};*/
|
@@ -0,0 +1,110 @@
|
|
1
|
+
#!/usr/bin/env narwhal
|
2
|
+
|
3
|
+
// TODO: ...should probably have some real performance tests.
|
4
|
+
|
5
|
+
var Jison = require("./setup").Jison;
|
6
|
+
|
7
|
+
var grammar = {
|
8
|
+
"lex": {
|
9
|
+
"macros": {
|
10
|
+
"digit": "[0-9]",
|
11
|
+
"id": "[a-zA-Z][a-zA-Z0-9]*"
|
12
|
+
},
|
13
|
+
|
14
|
+
"rules": [
|
15
|
+
["//.*", "/* ignore comment */"],
|
16
|
+
["main\\b", "return 'MAIN';"],
|
17
|
+
["class\\b", "return 'CLASS';"],
|
18
|
+
["extends\\b", "return 'EXTENDS';"],
|
19
|
+
["nat\\b", "return 'NATTYPE';"],
|
20
|
+
["if\\b", "return 'IF';"],
|
21
|
+
["else\\b", "return 'ELSE';"],
|
22
|
+
["for\\b", "return 'FOR';"],
|
23
|
+
["printNat\\b", "return 'PRINTNAT';"],
|
24
|
+
["readNat\\b", "return 'READNAT';"],
|
25
|
+
["this\\b", "return 'THIS';"],
|
26
|
+
["new\\b", "return 'NEW';"],
|
27
|
+
["var\\b", "return 'VAR';"],
|
28
|
+
["null\\b", "return 'NUL';"],
|
29
|
+
["{digit}+", "return 'NATLITERAL';"],
|
30
|
+
["{id}", "return 'ID';"],
|
31
|
+
["==", "return 'EQUALITY';"],
|
32
|
+
["=", "return 'ASSIGN';"],
|
33
|
+
["\\+", "return 'PLUS';"],
|
34
|
+
["-", "return 'MINUS';"],
|
35
|
+
["\\*", "return 'TIMES';"],
|
36
|
+
[">", "return 'GREATER';"],
|
37
|
+
["\\|\\|", "return 'OR';"],
|
38
|
+
["!", "return 'NOT';"],
|
39
|
+
["\\.", "return 'DOT';"],
|
40
|
+
["\\{", "return 'LBRACE';"],
|
41
|
+
["\\}", "return 'RBRACE';"],
|
42
|
+
["\\(", "return 'LPAREN';"],
|
43
|
+
["\\)", "return 'RPAREN';"],
|
44
|
+
[";", "return 'SEMICOLON';"],
|
45
|
+
["\\s+", "/* skip whitespace */"],
|
46
|
+
[".", "print('Illegal character');throw 'Illegal character';"],
|
47
|
+
["$", "return 'ENDOFFILE';"]
|
48
|
+
]
|
49
|
+
},
|
50
|
+
|
51
|
+
"tokens": "MAIN CLASS EXTENDS NATTYPE IF ELSE FOR PRINTNAT READNAT THIS NEW VAR NUL NATLITERAL ID ASSIGN PLUS MINUS TIMES EQUALITY GREATER OR NOT DOT SEMICOLON LBRACE RBRACE LPAREN RPAREN ENDOFFILE",
|
52
|
+
"operators": [
|
53
|
+
["right", "ASSIGN"],
|
54
|
+
["left", "OR"],
|
55
|
+
["nonassoc", "EQUALITY", "GREATER"],
|
56
|
+
["left", "PLUS", "MINUS"],
|
57
|
+
["left", "TIMES"],
|
58
|
+
["right", "NOT"],
|
59
|
+
["left", "DOT"]
|
60
|
+
],
|
61
|
+
|
62
|
+
"bnf": {
|
63
|
+
"pgm": ["cdl MAIN LBRACE vdl el RBRACE ENDOFFILE"],
|
64
|
+
|
65
|
+
"cdl": ["c cdl",
|
66
|
+
""],
|
67
|
+
|
68
|
+
"c": ["CLASS id EXTENDS id LBRACE vdl mdl RBRACE"],
|
69
|
+
|
70
|
+
"vdl": ["VAR t id SEMICOLON vdl",
|
71
|
+
""],
|
72
|
+
|
73
|
+
"mdl": ["t id LPAREN t id RPAREN LBRACE vdl el RBRACE mdl",
|
74
|
+
""],
|
75
|
+
|
76
|
+
"t": ["NATTYPE",
|
77
|
+
"id"],
|
78
|
+
|
79
|
+
"id": ["ID"],
|
80
|
+
|
81
|
+
"el": ["e SEMICOLON el",
|
82
|
+
"e SEMICOLON"],
|
83
|
+
|
84
|
+
"e": ["NATLITERAL",
|
85
|
+
"NUL",
|
86
|
+
"id",
|
87
|
+
"NEW id",
|
88
|
+
"THIS",
|
89
|
+
"IF LPAREN e RPAREN LBRACE el RBRACE ELSE LBRACE el RBRACE ",
|
90
|
+
"FOR LPAREN e SEMICOLON e SEMICOLON e RPAREN LBRACE el RBRACE",
|
91
|
+
"READNAT LPAREN RPAREN",
|
92
|
+
"PRINTNAT LPAREN e RPAREN",
|
93
|
+
"e PLUS e",
|
94
|
+
"e MINUS e",
|
95
|
+
"e TIMES e",
|
96
|
+
"e EQUALITY e",
|
97
|
+
"e GREATER e",
|
98
|
+
"NOT e",
|
99
|
+
"e OR e",
|
100
|
+
"e DOT id",
|
101
|
+
"id ASSIGN e",
|
102
|
+
"e DOT id ASSIGN e",
|
103
|
+
"id LPAREN e RPAREN",
|
104
|
+
"e DOT id LPAREN e RPAREN",
|
105
|
+
"LPAREN e RPAREN"]
|
106
|
+
}
|
107
|
+
};
|
108
|
+
|
109
|
+
var parser = new Jison.Parser(grammar, {type: 'lalr'});
|
110
|
+
|