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,196 @@
|
|
1
|
+
var Jison = require("../setup").Jison,
|
2
|
+
Lexer = require("../setup").Lexer,
|
3
|
+
assert = require("assert");
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
exports["test commonjs module generator"] = function () {
|
8
|
+
var lexData = {
|
9
|
+
rules: [
|
10
|
+
["x", "return 'x';"],
|
11
|
+
["y", "return 'y';"]
|
12
|
+
]
|
13
|
+
};
|
14
|
+
var grammar = {
|
15
|
+
tokens: "x y",
|
16
|
+
startSymbol: "A",
|
17
|
+
bnf: {
|
18
|
+
"A" :[ 'A x',
|
19
|
+
'A y',
|
20
|
+
'' ]
|
21
|
+
}
|
22
|
+
};
|
23
|
+
|
24
|
+
var input = "xyxxxy";
|
25
|
+
var gen = new Jison.Generator(grammar);
|
26
|
+
gen.lexer = new Lexer(lexData);
|
27
|
+
|
28
|
+
var parserSource = gen.generateCommonJSModule();
|
29
|
+
var exports = {};
|
30
|
+
eval(parserSource);
|
31
|
+
|
32
|
+
assert.ok(exports.parse(input));
|
33
|
+
};
|
34
|
+
|
35
|
+
exports["test module generator"] = function () {
|
36
|
+
var lexData = {
|
37
|
+
rules: [
|
38
|
+
["x", "return 'x';"],
|
39
|
+
["y", "return 'y';"]
|
40
|
+
]
|
41
|
+
};
|
42
|
+
var grammar = {
|
43
|
+
tokens: "x y",
|
44
|
+
startSymbol: "A",
|
45
|
+
bnf: {
|
46
|
+
"A" :[ 'A x',
|
47
|
+
'A y',
|
48
|
+
'' ]
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
var input = "xyxxxy";
|
53
|
+
var gen = new Jison.Generator(grammar);
|
54
|
+
gen.lexer = new Lexer(lexData);
|
55
|
+
|
56
|
+
var parserSource = gen.generateModule();
|
57
|
+
eval(parserSource);
|
58
|
+
|
59
|
+
assert.ok(parser.parse(input));
|
60
|
+
};
|
61
|
+
|
62
|
+
exports["test module generator with module name"] = function () {
|
63
|
+
var lexData = {
|
64
|
+
rules: [
|
65
|
+
["x", "return 'x';"],
|
66
|
+
["y", "return 'y';"]
|
67
|
+
]
|
68
|
+
};
|
69
|
+
var grammar = {
|
70
|
+
tokens: "x y",
|
71
|
+
startSymbol: "A",
|
72
|
+
bnf: {
|
73
|
+
"A" :[ 'A x',
|
74
|
+
'A y',
|
75
|
+
'' ]
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
var input = "xyxxxy";
|
80
|
+
var gen = new Jison.Generator(grammar);
|
81
|
+
gen.lexer = new Lexer(lexData);
|
82
|
+
|
83
|
+
var parserSource = gen.generate({moduleType: "js", moduleName: "parsey"});
|
84
|
+
eval(parserSource);
|
85
|
+
|
86
|
+
assert.ok(parsey.parse(input));
|
87
|
+
};
|
88
|
+
|
89
|
+
exports["test module generator with namespaced module name"] = function () {
|
90
|
+
var lexData = {
|
91
|
+
rules: [
|
92
|
+
["x", "return 'x';"],
|
93
|
+
["y", "return 'y';"]
|
94
|
+
]
|
95
|
+
};
|
96
|
+
var grammar = {
|
97
|
+
tokens: "x y",
|
98
|
+
startSymbol: "A",
|
99
|
+
bnf: {
|
100
|
+
"A" :[ 'A x',
|
101
|
+
'A y',
|
102
|
+
'' ]
|
103
|
+
}
|
104
|
+
};
|
105
|
+
|
106
|
+
var compiler = {};
|
107
|
+
|
108
|
+
var input = "xyxxxy";
|
109
|
+
var gen = new Jison.Generator(grammar);
|
110
|
+
gen.lexer = new Lexer(lexData);
|
111
|
+
|
112
|
+
var parserSource = gen.generateModule({moduleName: "compiler.parser"});
|
113
|
+
eval(parserSource);
|
114
|
+
|
115
|
+
assert.ok(compiler.parser.parse(input));
|
116
|
+
};
|
117
|
+
|
118
|
+
exports["test module include"] = function () {
|
119
|
+
var grammar = {
|
120
|
+
"comment": "ECMA-262 5th Edition, 15.12.1 The JSON Grammar. (Incomplete implementation)",
|
121
|
+
"author": "Zach Carter",
|
122
|
+
|
123
|
+
"lex": {
|
124
|
+
"macros": {
|
125
|
+
"digit": "[0-9]",
|
126
|
+
"exp": "([eE][-+]?{digit}+)"
|
127
|
+
},
|
128
|
+
"rules": [
|
129
|
+
["\\s+", "/* skip whitespace */"],
|
130
|
+
["-?{digit}+(\\.{digit}+)?{exp}?", "return 'NUMBER';"],
|
131
|
+
["\"[^\"]*", function(){
|
132
|
+
if(yytext.charAt(yyleng-1) == '\\') {
|
133
|
+
// remove escape
|
134
|
+
yytext = yytext.substr(0,yyleng-2);
|
135
|
+
this.more();
|
136
|
+
} else {
|
137
|
+
yytext = yytext.substr(1); // swallow start quote
|
138
|
+
this.input(); // swallow end quote
|
139
|
+
return "STRING";
|
140
|
+
}
|
141
|
+
}],
|
142
|
+
["\\{", "return '{'"],
|
143
|
+
["\\}", "return '}'"],
|
144
|
+
["\\[", "return '['"],
|
145
|
+
["\\]", "return ']'"],
|
146
|
+
[",", "return ','"],
|
147
|
+
[":", "return ':'"],
|
148
|
+
["true\\b", "return 'TRUE'"],
|
149
|
+
["false\\b", "return 'FALSE'"],
|
150
|
+
["null\\b", "return 'NULL'"]
|
151
|
+
]
|
152
|
+
},
|
153
|
+
|
154
|
+
"tokens": "STRING NUMBER { } [ ] , : TRUE FALSE NULL",
|
155
|
+
"start": "JSONText",
|
156
|
+
|
157
|
+
"bnf": {
|
158
|
+
"JSONString": [ "STRING" ],
|
159
|
+
|
160
|
+
"JSONNumber": [ "NUMBER" ],
|
161
|
+
|
162
|
+
"JSONBooleanLiteral": [ "TRUE", "FALSE" ],
|
163
|
+
|
164
|
+
|
165
|
+
"JSONText": [ "JSONValue" ],
|
166
|
+
|
167
|
+
"JSONValue": [ "JSONNullLiteral",
|
168
|
+
"JSONBooleanLiteral",
|
169
|
+
"JSONString",
|
170
|
+
"JSONNumber",
|
171
|
+
"JSONObject",
|
172
|
+
"JSONArray" ],
|
173
|
+
|
174
|
+
"JSONObject": [ "{ }",
|
175
|
+
"{ JSONMemberList }" ],
|
176
|
+
|
177
|
+
"JSONMember": [ "JSONString : JSONValue" ],
|
178
|
+
|
179
|
+
"JSONMemberList": [ "JSONMember",
|
180
|
+
"JSONMemberList , JSONMember" ],
|
181
|
+
|
182
|
+
"JSONArray": [ "[ ]",
|
183
|
+
"[ JSONElementList ]" ],
|
184
|
+
|
185
|
+
"JSONElementList": [ "JSONValue",
|
186
|
+
"JSONElementList , JSONValue" ]
|
187
|
+
}
|
188
|
+
};
|
189
|
+
|
190
|
+
var gen = new Jison.Generator(grammar);
|
191
|
+
|
192
|
+
var parserSource = gen.generateModule();
|
193
|
+
eval(parserSource);
|
194
|
+
|
195
|
+
assert.ok(parser.parse(JSON.stringify(grammar.bnf)));
|
196
|
+
};
|
@@ -0,0 +1,183 @@
|
|
1
|
+
var Jison = require("../setup").Jison,
|
2
|
+
Lexer = require("../setup").Lexer,
|
3
|
+
assert = require("assert");
|
4
|
+
|
5
|
+
exports["test 0+0 grammar"] = function () {
|
6
|
+
var lexData2 = {
|
7
|
+
rules: [
|
8
|
+
["0", "return 'ZERO';"],
|
9
|
+
["\\+", "return 'PLUS';"]
|
10
|
+
]
|
11
|
+
};
|
12
|
+
var grammar = {
|
13
|
+
tokens: [ "ZERO", "PLUS"],
|
14
|
+
startSymbol: "E",
|
15
|
+
bnf: {
|
16
|
+
"E" :[ "E PLUS T",
|
17
|
+
"T" ],
|
18
|
+
"T" :[ "ZERO" ]
|
19
|
+
}
|
20
|
+
};
|
21
|
+
|
22
|
+
var parser = new Jison.Parser(grammar, {type: "lalr"});
|
23
|
+
parser.lexer = new Lexer(lexData2);
|
24
|
+
|
25
|
+
assert.ok(parser.parse("0+0+0"), "parse");
|
26
|
+
assert.ok(parser.parse("0"), "parse single 0");
|
27
|
+
|
28
|
+
assert["throws"](function () {parser.parse("+")}, "throws parse error on invalid");
|
29
|
+
};
|
30
|
+
|
31
|
+
exports["test xx nullable grammar"] = function () {
|
32
|
+
var lexData = {
|
33
|
+
rules: [
|
34
|
+
["x", "return 'x';"]
|
35
|
+
]
|
36
|
+
};
|
37
|
+
var grammar = {
|
38
|
+
tokens: [ 'x' ],
|
39
|
+
startSymbol: "A",
|
40
|
+
bnf: {
|
41
|
+
"A" :[ 'A x',
|
42
|
+
'' ]
|
43
|
+
}
|
44
|
+
};
|
45
|
+
|
46
|
+
var parser = new Jison.Parser(grammar, {type: "lalr"});
|
47
|
+
parser.lexer = new Lexer(lexData);
|
48
|
+
|
49
|
+
assert.ok(parser.parse("xxx"), "parse");
|
50
|
+
assert.ok(parser.parse("x"), "parse single x");
|
51
|
+
assert["throws"](function (){parser.parse("+");}, "throws parse error on invalid");
|
52
|
+
};
|
53
|
+
|
54
|
+
exports["test LALR algorithm from Bermudez, Logothetis"] = function () {
|
55
|
+
var lexData = {
|
56
|
+
rules: [
|
57
|
+
["a", "return 'a';"],
|
58
|
+
["b", "return 'b';"],
|
59
|
+
["c", "return 'c';"],
|
60
|
+
["d", "return 'd';"],
|
61
|
+
["g", "return 'g';"]
|
62
|
+
]
|
63
|
+
};
|
64
|
+
var grammar = {
|
65
|
+
"tokens": "a b c d g",
|
66
|
+
"startSymbol": "S",
|
67
|
+
"bnf": {
|
68
|
+
"S" :[ "a g d",
|
69
|
+
"a A c",
|
70
|
+
"b A d",
|
71
|
+
"b g c" ],
|
72
|
+
"A" :[ "B" ],
|
73
|
+
"B" :[ "g" ]
|
74
|
+
}
|
75
|
+
};
|
76
|
+
|
77
|
+
var parser = new Jison.Parser(grammar, {type: "lalr"});
|
78
|
+
parser.lexer = new Lexer(lexData);
|
79
|
+
assert.ok(parser.parse("agd"));
|
80
|
+
assert.ok(parser.parse("agc"));
|
81
|
+
assert.ok(parser.parse("bgd"));
|
82
|
+
assert.ok(parser.parse("bgc"));
|
83
|
+
};
|
84
|
+
|
85
|
+
exports["test basic JSON grammar"] = function () {
|
86
|
+
var grammar = {
|
87
|
+
"lex": {
|
88
|
+
"macros": {
|
89
|
+
"digit": "[0-9]",
|
90
|
+
"esc": "\\\\",
|
91
|
+
"int": "-?(?:[0-9]|[1-9][0-9]+)",
|
92
|
+
"exp": "(?:[eE][-+]?[0-9]+)",
|
93
|
+
"frac": "(?:\\.[0-9]+)"
|
94
|
+
},
|
95
|
+
"rules": [
|
96
|
+
["\\s+", "/* skip whitespace */"],
|
97
|
+
["{int}{frac}?{exp}?\\b", "return 'NUMBER';"],
|
98
|
+
["\"(?:{esc}[\"bfnrt/{esc}]|{esc}u[a-fA-F0-9]{4}|[^\"{esc}])*\"", "yytext = yytext.substr(1,yyleng-2); return 'STRING';"],
|
99
|
+
["\\{", "return '{'"],
|
100
|
+
["\\}", "return '}'"],
|
101
|
+
["\\[", "return '['"],
|
102
|
+
["\\]", "return ']'"],
|
103
|
+
[",", "return ','"],
|
104
|
+
[":", "return ':'"],
|
105
|
+
["true\\b", "return 'TRUE'"],
|
106
|
+
["false\\b", "return 'FALSE'"],
|
107
|
+
["null\\b", "return 'NULL'"]
|
108
|
+
]
|
109
|
+
},
|
110
|
+
|
111
|
+
"tokens": "STRING NUMBER { } [ ] , : TRUE FALSE NULL",
|
112
|
+
"bnf": {
|
113
|
+
"JsonThing": [ "JsonObject",
|
114
|
+
"JsonArray" ],
|
115
|
+
|
116
|
+
"JsonObject": [ "{ JsonPropertyList }" ],
|
117
|
+
|
118
|
+
"JsonPropertyList": [ "JsonProperty",
|
119
|
+
"JsonPropertyList , JsonProperty" ],
|
120
|
+
|
121
|
+
"JsonProperty": [ "StringLiteral : JsonValue" ],
|
122
|
+
|
123
|
+
"JsonArray": [ "[ JsonValueList ]" ],
|
124
|
+
|
125
|
+
"JsonValueList": [ "JsonValue",
|
126
|
+
"JsonValueList , JsonValue" ],
|
127
|
+
|
128
|
+
"JsonValue": [ "StringLiteral",
|
129
|
+
"NumericalLiteral",
|
130
|
+
"JsonObject",
|
131
|
+
"JsonArray",
|
132
|
+
"TRUE",
|
133
|
+
"FALSE",
|
134
|
+
"NULL" ],
|
135
|
+
|
136
|
+
"StringLiteral": [ "STRING" ],
|
137
|
+
|
138
|
+
"NumericalLiteral": [ "NUMBER" ]
|
139
|
+
},
|
140
|
+
};
|
141
|
+
|
142
|
+
var source = '{"foo": "Bar", "hi": 42, "array": [1,2,3.004, -4.04e-4], "false": false, "true":true, "null": null, "obj": {"ha":"ho"}, "string": "str\\ting\\"sgfg" }';
|
143
|
+
|
144
|
+
var gen = new Jison.Generator(grammar, {type: "lalr"});
|
145
|
+
var parser = gen.createParser();
|
146
|
+
var gen2 = new Jison.Generator(grammar, {type: "slr"});
|
147
|
+
var parser2 = gen2.createParser();
|
148
|
+
assert.deepEqual(gen.table, gen2.table, "SLR(1) and LALR(1) tables should be equal");
|
149
|
+
assert.ok(parser.parse(source));
|
150
|
+
};
|
151
|
+
|
152
|
+
exports["test LR(1) grammar"] = function () {
|
153
|
+
var grammar = {
|
154
|
+
"comment": "Produces a reduce-reduce conflict unless using LR(1).",
|
155
|
+
"tokens": "z d b c a",
|
156
|
+
"start": "S",
|
157
|
+
"bnf": {
|
158
|
+
"S" :[ "a A c",
|
159
|
+
"a B d",
|
160
|
+
"b A d",
|
161
|
+
"b B c"],
|
162
|
+
"A" :[ "z" ],
|
163
|
+
"B" :[ "z" ]
|
164
|
+
}
|
165
|
+
};
|
166
|
+
|
167
|
+
var gen = new Jison.Generator(grammar, {type: "lalr"});
|
168
|
+
assert.equal(gen.conflicts, 2);
|
169
|
+
};
|
170
|
+
|
171
|
+
exports["test BNF grammar bootstrap"] = function () {
|
172
|
+
var grammar = "%%\n\nspec\n : declaration_list '%%' grammar EOF\n {$$ = $1; $$.bnf = $3; return $$;}\n | declaration_list '%%' grammar '%%' EOF\n {$$ = $1; $$.bnf = $3; return $$;}\n ;\n\ndeclaration_list\n : declaration_list declaration\n {$$ = $1; yy.addDeclaration($$, $2);}\n | \n <$$ = {};>\n ;\n\ndeclaration\n : START id\n <$$ = {start: $2};>\n | operator\n <$$ = {operator: $1};>\n ;\n\noperator\n : associativity token_list\n {$$ = [$1]; $$.push.apply($$, $2);}\n ;\n\nassociativity\n : LEFT\n {$$ = 'left';}\n | RIGHT\n {$$ = 'right';}\n | NONASSOC\n {$$ = 'nonassoc';}\n ;\n\ntoken_list\n : token_list symbol\n {$$ = $1; $$.push($2);}\n | symbol\n {$$ = [$1];}\n ;\n\ngrammar\n : production_list\n {$$ = $1;}\n ;\n\nproduction_list\n : production_list production\n {$$ = $1; $$[$2[0]] = $2[1];}\n | production\n <$$ = {}; $$[$1[0]] = $1[1];>\n ;\n\nproduction\n : id ':' handle_list ';'\n {$$ = [$1, $3];}\n ;\n\nhandle_list\n : handle_list '|' handle_action\n {$$ = $1; $$.push($3);}\n | handle_action\n {$$ = [$1];}\n ;\n\nhandle_action\n : handle action prec\n {$$ = [($1.length ? $1.join(' ') : '')];\n if($2) $$.push($2);\n if($3) $$.push($3);\n if ($$.length === 1) $$ = $$[0];\n }\n ;\n\nhandle\n : handle symbol\n {$$ = $1; $$.push($2)}\n | \n {$$ = [];}\n ;\n\nprec\n : PREC symbol\n <$$ = {prec: $2};>\n | \n {$$ = null;}\n ;\n\nsymbol\n : id\n {$$ = $1;}\n | STRING\n {$$ = yytext;}\n ;\n\nid\n : ID\n {$$ = yytext;}\n ;\n\naction\n : ACTION\n {$$ = yytext;}\n | \n {$$ = '';}\n ;\n\n";
|
173
|
+
|
174
|
+
var lex = "\n%%\n\\s+ \t{/* skip whitespace */}\n\"/*\"[^*]*\"*\" \t{return yy.lexComment(this);}\n[a-zA-Z][a-zA-Z0-9_-]* \t{return 'ID';}\n'\"'[^\"]+'\"' \t{yytext = yytext.substr(1, yyleng-2); return 'STRING';}\n\"'\"[^']+\"'\" \t{yytext = yytext.substr(1, yyleng-2); return 'STRING';}\n\":\" \t{return ':';}\n\";\" \t{return ';';}\n\"|\" \t{return '|';}\n\"%%\" \t{return '%%';}\n\"%prec\" \t{return 'PREC';}\n\"%start\" \t{return 'START';}\n\"%left\" \t{return 'LEFT';}\n\"%right\" \t{return 'RIGHT';}\n\"%nonassoc\" \t{return 'NONASSOC';}\n\"%\"[a-zA-Z]+[^\\n]* \t{/* ignore unrecognized decl */}\n\"{{\"[^}]*\"}\" \t{return yy.lexAction(this);}\n\"{\"[^}]*\"}\" \t{yytext = yytext.substr(1, yyleng-2); return 'ACTION';}\n\"<\"[^>]*\">\" \t{yytext = yytext.substr(1, yyleng-2); return 'ACTION';}\n. \t{/* ignore bad characters */}\n<<EOF>> \t{return 'EOF';}\n\n%%\n\n";
|
175
|
+
|
176
|
+
|
177
|
+
var gen = new Jison.Generator(grammar, {type: "lalr"});
|
178
|
+
gen.lexer = new Lexer(lex);
|
179
|
+
|
180
|
+
var parser = gen.createParser();
|
181
|
+
|
182
|
+
assert.ok(parser.parse(grammar), "bootstrapped bnf parser should parse correctly.");
|
183
|
+
};
|
@@ -0,0 +1,72 @@
|
|
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 parser = new Jison.Parser(grammar, {type: "lr0"});
|
24
|
+
parser.lexer = new Lexer(lexData);
|
25
|
+
|
26
|
+
assert.ok(parser.parse('xxx'), "parse 3 x's");
|
27
|
+
assert.ok(parser.parse("x"), "parse single x");
|
28
|
+
assert["throws"](function () {parser.parse("y")}, "throws parse error on invalid token");
|
29
|
+
};
|
30
|
+
|
31
|
+
exports["test right-recursive nullable grammar"] = function () {
|
32
|
+
|
33
|
+
var grammar = {
|
34
|
+
tokens: [ 'x' ],
|
35
|
+
startSymbol: "A",
|
36
|
+
bnf: {
|
37
|
+
"A" :[ 'x A',
|
38
|
+
'' ]
|
39
|
+
}
|
40
|
+
};
|
41
|
+
|
42
|
+
var gen = new Jison.Generator(grammar, {type: "lr0"});
|
43
|
+
|
44
|
+
assert.ok(gen.table.length == 4, "table has 4 states");
|
45
|
+
assert.ok(gen.conflicts == 2, "encountered 2 conflicts");
|
46
|
+
};
|
47
|
+
|
48
|
+
exports["test 0+0 grammar"] = function () {
|
49
|
+
var lexData2 = {
|
50
|
+
rules: [
|
51
|
+
["0", "return 'ZERO';"],
|
52
|
+
["\\+", "return 'PLUS';"]
|
53
|
+
]
|
54
|
+
};
|
55
|
+
var grammar = {
|
56
|
+
tokens: [ "ZERO", "PLUS"],
|
57
|
+
startSymbol: "E",
|
58
|
+
bnf: {
|
59
|
+
"E" :[ "E PLUS T",
|
60
|
+
"T" ],
|
61
|
+
"T" :[ "ZERO" ]
|
62
|
+
}
|
63
|
+
};
|
64
|
+
|
65
|
+
var parser = new Jison.Parser(grammar, {type: "lr0"});
|
66
|
+
parser.lexer = new Lexer(lexData2);
|
67
|
+
|
68
|
+
assert.ok(parser.parse("0+0+0"), "parse");
|
69
|
+
assert.ok(parser.parse("0"), "parse single 0");
|
70
|
+
|
71
|
+
assert["throws"](function () {parser.parse("+")}, "throws parse error on invalid");
|
72
|
+
};
|
@@ -0,0 +1,119 @@
|
|
1
|
+
var Jison = require("../setup").Jison,
|
2
|
+
Lexer = require("../setup").Lexer,
|
3
|
+
assert = require("assert");
|
4
|
+
|
5
|
+
exports["test xx nullable grammar"] = function () {
|
6
|
+
var lexData = {
|
7
|
+
rules: [
|
8
|
+
["x", "return 'x';"],
|
9
|
+
["y", "return 'y';"]
|
10
|
+
]
|
11
|
+
};
|
12
|
+
var grammar = {
|
13
|
+
tokens: [ 'x' ],
|
14
|
+
startSymbol: "A",
|
15
|
+
bnf: {
|
16
|
+
"A" :[ 'A x',
|
17
|
+
'' ]
|
18
|
+
}
|
19
|
+
};
|
20
|
+
|
21
|
+
var parser = new Jison.Parser(grammar, {type: "lr"});
|
22
|
+
parser.lexer = new Lexer(lexData);
|
23
|
+
|
24
|
+
assert.ok(parser.parse("xxx"), "parse");
|
25
|
+
assert.ok(parser.parse("x"), "parse single x");
|
26
|
+
assert["throws"](function (){parser.parse("+");}, "throws parse error on invalid");
|
27
|
+
};
|
28
|
+
|
29
|
+
exports["test LR parse"] = function () {
|
30
|
+
var lexData2 = {
|
31
|
+
rules: [
|
32
|
+
["0", "return 'ZERO';"],
|
33
|
+
["\\+", "return 'PLUS';"]
|
34
|
+
]
|
35
|
+
};
|
36
|
+
var grammar = {
|
37
|
+
tokens: [ "ZERO", "PLUS"],
|
38
|
+
startSymbol: "E",
|
39
|
+
bnf: {
|
40
|
+
"E" :[ "E PLUS T",
|
41
|
+
"T" ],
|
42
|
+
"T" :[ "ZERO" ]
|
43
|
+
}
|
44
|
+
};
|
45
|
+
var parser = new Jison.Parser(grammar, {type: "lr"});
|
46
|
+
parser.lexer = new Lexer(lexData2);
|
47
|
+
|
48
|
+
assert.ok(parser.parse("0+0+0"), "parse");
|
49
|
+
};
|
50
|
+
|
51
|
+
exports["test basic JSON grammar"] = function () {
|
52
|
+
var grammar = {
|
53
|
+
"lex": {
|
54
|
+
"macros": {
|
55
|
+
"digit": "[0-9]"
|
56
|
+
},
|
57
|
+
"rules": [
|
58
|
+
["\\s+", "/* skip whitespace */"],
|
59
|
+
["{digit}+(\\.{digit}+)?", "return 'NUMBER';"],
|
60
|
+
["\"[^\"]*", function(){
|
61
|
+
if(yytext.charAt(yyleng-1) == '\\') {
|
62
|
+
// remove escape
|
63
|
+
yytext = yytext.substr(0,yyleng-2);
|
64
|
+
this.more();
|
65
|
+
} else {
|
66
|
+
yytext = yytext.substr(1); // swallow start quote
|
67
|
+
this.input(); // swallow end quote
|
68
|
+
return "STRING";
|
69
|
+
}
|
70
|
+
}],
|
71
|
+
["\\{", "return '{'"],
|
72
|
+
["\\}", "return '}'"],
|
73
|
+
["\\[", "return '['"],
|
74
|
+
["\\]", "return ']'"],
|
75
|
+
[",", "return ','"],
|
76
|
+
[":", "return ':'"],
|
77
|
+
["true\\b", "return 'TRUE'"],
|
78
|
+
["false\\b", "return 'FALSE'"],
|
79
|
+
["null\\b", "return 'NULL'"]
|
80
|
+
]
|
81
|
+
},
|
82
|
+
|
83
|
+
"tokens": "STRING NUMBER { } [ ] , : TRUE FALSE NULL",
|
84
|
+
"bnf": {
|
85
|
+
"JsonThing": [ "JsonObject",
|
86
|
+
"JsonArray" ],
|
87
|
+
|
88
|
+
"JsonObject": [ "{ JsonPropertyList }" ],
|
89
|
+
|
90
|
+
"JsonPropertyList": [ "JsonProperty",
|
91
|
+
"JsonPropertyList , JsonProperty" ],
|
92
|
+
|
93
|
+
"JsonProperty": [ "StringLiteral : JsonValue" ],
|
94
|
+
|
95
|
+
"JsonArray": [ "[ JsonValueList ]" ],
|
96
|
+
|
97
|
+
"JsonValueList": [ "JsonValue",
|
98
|
+
"JsonValueList , JsonValue" ],
|
99
|
+
|
100
|
+
"JsonValue": [ "StringLiteral",
|
101
|
+
"NumericalLiteral",
|
102
|
+
"JsonObject",
|
103
|
+
"JsonArray",
|
104
|
+
"TRUE",
|
105
|
+
"FALSE",
|
106
|
+
"NULL" ],
|
107
|
+
|
108
|
+
"StringLiteral": [ "STRING" ],
|
109
|
+
|
110
|
+
"NumericalLiteral": [ "NUMBER" ]
|
111
|
+
},
|
112
|
+
};
|
113
|
+
|
114
|
+
var source = '{"foo": "Bar", "hi": 42, "array": [1,2,3.004,4], "false": false, "true":true, "null": null, "obj": {"ha":"ho"}, "string": "string\\"sgfg" }';
|
115
|
+
|
116
|
+
var parser = new Jison.Parser(grammar, {type: "lr"});
|
117
|
+
assert.ok(parser.parse(source));
|
118
|
+
}
|
119
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env narwhal
|
2
|
+
|
3
|
+
exports.testAPI = require("./api");
|
4
|
+
exports.testLR0 = require("./lr0");
|
5
|
+
exports.testSLR = require("./slr");
|
6
|
+
exports.testLALR = require("./lalr");
|
7
|
+
exports.testLR1 = require("./lr1");
|
8
|
+
exports.testAST = require("./actions");
|
9
|
+
exports.testTables = require("./tables");
|
10
|
+
exports.testPrecedence = require("./precedence");
|
11
|
+
exports.testGenerator = require("./generator");
|
12
|
+
|
13
|
+
if (require.main === module)
|
14
|
+
require("os").exit(require("test").run(exports));
|