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,417 @@
|
|
1
|
+
var RegExpLexer = require("../setup").RegExpLexer,
|
2
|
+
assert = require("assert"),
|
3
|
+
jsDump = require("test/jsdump").jsDump;
|
4
|
+
|
5
|
+
exports["test basic matchers"] = function() {
|
6
|
+
var dict = {
|
7
|
+
rules: [
|
8
|
+
["x", "return 'X';" ],
|
9
|
+
["y", "return 'Y';" ],
|
10
|
+
["$", "return 'EOF';" ]
|
11
|
+
]
|
12
|
+
};
|
13
|
+
|
14
|
+
var input = "xxyx";
|
15
|
+
|
16
|
+
var lexer = new RegExpLexer(dict, input);
|
17
|
+
assert.equal(lexer.lex(), "X");
|
18
|
+
assert.equal(lexer.lex(), "X");
|
19
|
+
assert.equal(lexer.lex(), "Y");
|
20
|
+
assert.equal(lexer.lex(), "X");
|
21
|
+
assert.equal(lexer.lex(), "EOF");
|
22
|
+
};
|
23
|
+
|
24
|
+
exports["test set input after"] = function() {
|
25
|
+
var dict = {
|
26
|
+
rules: [
|
27
|
+
["x", "return 'X';" ],
|
28
|
+
["y", "return 'Y';" ],
|
29
|
+
["$", "return 'EOF';" ]
|
30
|
+
]
|
31
|
+
};
|
32
|
+
|
33
|
+
var input = "xxyx";
|
34
|
+
|
35
|
+
var lexer = new RegExpLexer(dict);
|
36
|
+
lexer.setInput(input);
|
37
|
+
|
38
|
+
assert.equal(lexer.lex(), "X");
|
39
|
+
assert.equal(lexer.lex(), "X");
|
40
|
+
assert.equal(lexer.lex(), "Y");
|
41
|
+
assert.equal(lexer.lex(), "X");
|
42
|
+
assert.equal(lexer.lex(), "EOF");
|
43
|
+
};
|
44
|
+
|
45
|
+
exports["test unrecognized char"] = function() {
|
46
|
+
var dict = {
|
47
|
+
rules: [
|
48
|
+
["x", "return 'X';" ],
|
49
|
+
["y", "return 'Y';" ],
|
50
|
+
["$", "return 'EOF';" ]
|
51
|
+
]
|
52
|
+
};
|
53
|
+
|
54
|
+
var input = "xa";
|
55
|
+
|
56
|
+
var lexer = new RegExpLexer(dict, input);
|
57
|
+
assert.equal(lexer.lex(), "X");
|
58
|
+
assert["throws"](function(){lexer.lex()}, "bad char");
|
59
|
+
};
|
60
|
+
|
61
|
+
exports["test macro"] = function() {
|
62
|
+
var dict = {
|
63
|
+
macros: {
|
64
|
+
"digit": "[0-9]"
|
65
|
+
},
|
66
|
+
rules: [
|
67
|
+
["x", "return 'X';" ],
|
68
|
+
["y", "return 'Y';" ],
|
69
|
+
["{digit}+", "return 'NAT';" ],
|
70
|
+
["$", "return 'EOF';" ]
|
71
|
+
]
|
72
|
+
};
|
73
|
+
|
74
|
+
var input = "x12234y42";
|
75
|
+
|
76
|
+
var lexer = new RegExpLexer(dict, input);
|
77
|
+
assert.equal(lexer.lex(), "X");
|
78
|
+
assert.equal(lexer.lex(), "NAT");
|
79
|
+
assert.equal(lexer.lex(), "Y");
|
80
|
+
assert.equal(lexer.lex(), "NAT");
|
81
|
+
assert.equal(lexer.lex(), "EOF");
|
82
|
+
};
|
83
|
+
|
84
|
+
exports["test action include"] = function() {
|
85
|
+
var dict = {
|
86
|
+
rules: [
|
87
|
+
["x", "return included ? 'Y' : 'N';" ],
|
88
|
+
["$", "return 'EOF';" ]
|
89
|
+
],
|
90
|
+
actionInclude: "var included = true;"
|
91
|
+
};
|
92
|
+
|
93
|
+
var input = "x";
|
94
|
+
|
95
|
+
var lexer = new RegExpLexer(dict, input);
|
96
|
+
assert.equal(lexer.lex(), "Y");
|
97
|
+
assert.equal(lexer.lex(), "EOF");
|
98
|
+
};
|
99
|
+
|
100
|
+
exports["test ignored"] = function() {
|
101
|
+
var dict = {
|
102
|
+
rules: [
|
103
|
+
["x", "return 'X';" ],
|
104
|
+
["y", "return 'Y';" ],
|
105
|
+
["\\s+", "/* skip whitespace */" ],
|
106
|
+
["$", "return 'EOF';" ]
|
107
|
+
]
|
108
|
+
};
|
109
|
+
|
110
|
+
var input = "x x y x";
|
111
|
+
|
112
|
+
var lexer = new RegExpLexer(dict, input);
|
113
|
+
assert.equal(lexer.lex(), "X");
|
114
|
+
assert.equal(lexer.lex(), "X");
|
115
|
+
assert.equal(lexer.lex(), "Y");
|
116
|
+
assert.equal(lexer.lex(), "X");
|
117
|
+
assert.equal(lexer.lex(), "EOF");
|
118
|
+
};
|
119
|
+
|
120
|
+
exports["test dissambiguate"] = function() {
|
121
|
+
var dict = {
|
122
|
+
rules: [
|
123
|
+
["for\\b", "return 'FOR';" ],
|
124
|
+
["if\\b", "return 'IF';" ],
|
125
|
+
["[a-z]+", "return 'IDENTIFIER';" ],
|
126
|
+
["\\s+", "/* skip whitespace */" ],
|
127
|
+
["$", "return 'EOF';" ]
|
128
|
+
]
|
129
|
+
};
|
130
|
+
|
131
|
+
var input = "if forever for for";
|
132
|
+
|
133
|
+
var lexer = new RegExpLexer(dict, input);
|
134
|
+
assert.equal(lexer.lex(), "IF");
|
135
|
+
assert.equal(lexer.lex(), "IDENTIFIER");
|
136
|
+
assert.equal(lexer.lex(), "FOR");
|
137
|
+
assert.equal(lexer.lex(), "FOR");
|
138
|
+
assert.equal(lexer.lex(), "EOF");
|
139
|
+
};
|
140
|
+
|
141
|
+
exports["test yytext overwrite"] = function() {
|
142
|
+
var dict = {
|
143
|
+
rules: [
|
144
|
+
["x", "yytext = 'hi der'; return 'X';" ]
|
145
|
+
]
|
146
|
+
};
|
147
|
+
|
148
|
+
var input = "x";
|
149
|
+
|
150
|
+
var lexer = new RegExpLexer(dict, input);
|
151
|
+
lexer.lex();
|
152
|
+
assert.equal(lexer.yytext, "hi der");
|
153
|
+
};
|
154
|
+
|
155
|
+
exports["test yylineno"] = function() {
|
156
|
+
var dict = {
|
157
|
+
rules: [
|
158
|
+
["\\s+", "/* skip whitespace */" ],
|
159
|
+
["x", "return 'x';" ],
|
160
|
+
["y", "return 'y';" ]
|
161
|
+
]
|
162
|
+
};
|
163
|
+
|
164
|
+
var input = "x\nxy\n\n\nx";
|
165
|
+
|
166
|
+
var lexer = new RegExpLexer(dict, input);
|
167
|
+
assert.equal(lexer.yylineno, 0);
|
168
|
+
assert.equal(lexer.lex(), "x");
|
169
|
+
assert.equal(lexer.lex(), "x");
|
170
|
+
assert.equal(lexer.yylineno, 1);
|
171
|
+
assert.equal(lexer.lex(), "y");
|
172
|
+
assert.equal(lexer.yylineno, 1);
|
173
|
+
assert.equal(lexer.lex(), "x");
|
174
|
+
assert.equal(lexer.yylineno, 4);
|
175
|
+
};
|
176
|
+
|
177
|
+
exports["test more()"] = function() {
|
178
|
+
var dict = {
|
179
|
+
rules: [
|
180
|
+
["x", "return 'X';" ],
|
181
|
+
['"[^"]*', function(){
|
182
|
+
if(yytext.charAt(yyleng-1) == '\\') {
|
183
|
+
this.more();
|
184
|
+
} else {
|
185
|
+
yytext += this.input(); // swallow end quote
|
186
|
+
return "STRING";
|
187
|
+
}
|
188
|
+
} ],
|
189
|
+
["$", "return 'EOF';" ]
|
190
|
+
]
|
191
|
+
};
|
192
|
+
|
193
|
+
var input = 'x"fgjdrtj\\"sdfsdf"x';
|
194
|
+
|
195
|
+
var lexer = new RegExpLexer(dict, input);
|
196
|
+
assert.equal(lexer.lex(), "X");
|
197
|
+
assert.equal(lexer.lex(), "STRING");
|
198
|
+
assert.equal(lexer.lex(), "X");
|
199
|
+
assert.equal(lexer.lex(), "EOF");
|
200
|
+
};
|
201
|
+
|
202
|
+
exports["test defined token returns"] = function() {
|
203
|
+
var tokens = {"2":"X", "3":"Y", "4":"EOF"};
|
204
|
+
var dict = {
|
205
|
+
rules: [
|
206
|
+
["x", "return 'X';" ],
|
207
|
+
["y", "return 'Y';" ],
|
208
|
+
["$", "return 'EOF';" ]
|
209
|
+
]
|
210
|
+
};
|
211
|
+
|
212
|
+
var input = "xxyx";
|
213
|
+
|
214
|
+
var lexer = new RegExpLexer(dict, input, tokens);
|
215
|
+
|
216
|
+
assert.equal(lexer.lex(), 2);
|
217
|
+
assert.equal(lexer.lex(), 2);
|
218
|
+
assert.equal(lexer.lex(), 3);
|
219
|
+
assert.equal(lexer.lex(), 2);
|
220
|
+
assert.equal(lexer.lex(), 4);
|
221
|
+
};
|
222
|
+
|
223
|
+
exports["test module generator"] = function() {
|
224
|
+
var dict = {
|
225
|
+
rules: [
|
226
|
+
["x", "return 'X';" ],
|
227
|
+
["y", "return 'Y';" ],
|
228
|
+
["$", "return 'EOF';" ]
|
229
|
+
]
|
230
|
+
};
|
231
|
+
|
232
|
+
var input = "xxyx";
|
233
|
+
|
234
|
+
var lexer_ = new RegExpLexer(dict);
|
235
|
+
var lexerSource = lexer_.generateModule();
|
236
|
+
eval(lexerSource);
|
237
|
+
lexer.setInput(input);
|
238
|
+
|
239
|
+
assert.equal(lexer.lex(), "X");
|
240
|
+
assert.equal(lexer.lex(), "X");
|
241
|
+
assert.equal(lexer.lex(), "Y");
|
242
|
+
assert.equal(lexer.lex(), "X");
|
243
|
+
assert.equal(lexer.lex(), "EOF");
|
244
|
+
};
|
245
|
+
|
246
|
+
exports["test generator with more complex lexer"] = function() {
|
247
|
+
var dict = {
|
248
|
+
rules: [
|
249
|
+
["x", "return 'X';" ],
|
250
|
+
['"[^"]*', function(){
|
251
|
+
if(yytext.charAt(yyleng-1) == '\\') {
|
252
|
+
this.more();
|
253
|
+
} else {
|
254
|
+
yytext += this.input(); // swallow end quote
|
255
|
+
return "STRING";
|
256
|
+
}
|
257
|
+
} ],
|
258
|
+
["$", "return 'EOF';" ]
|
259
|
+
]
|
260
|
+
};
|
261
|
+
|
262
|
+
var input = 'x"fgjdrtj\\"sdfsdf"x';
|
263
|
+
|
264
|
+
var lexer_ = new RegExpLexer(dict);
|
265
|
+
var lexerSource = lexer_.generateModule();
|
266
|
+
eval(lexerSource);
|
267
|
+
lexer.setInput(input);
|
268
|
+
|
269
|
+
assert.equal(lexer.lex(), "X");
|
270
|
+
assert.equal(lexer.lex(), "STRING");
|
271
|
+
assert.equal(lexer.lex(), "X");
|
272
|
+
assert.equal(lexer.lex(), "EOF");
|
273
|
+
};
|
274
|
+
|
275
|
+
exports["test commonjs module generator"] = function() {
|
276
|
+
var dict = {
|
277
|
+
rules: [
|
278
|
+
["x", "return 'X';" ],
|
279
|
+
["y", "return 'Y';" ],
|
280
|
+
["$", "return 'EOF';" ]
|
281
|
+
]
|
282
|
+
};
|
283
|
+
|
284
|
+
var input = "xxyx";
|
285
|
+
|
286
|
+
var lexer_ = new RegExpLexer(dict);
|
287
|
+
var lexerSource = lexer_.generateCommonJSModule();
|
288
|
+
var exports = {};
|
289
|
+
eval(lexerSource);
|
290
|
+
exports.lexer.setInput(input);
|
291
|
+
|
292
|
+
assert.equal(exports.lex(), "X");
|
293
|
+
assert.equal(exports.lex(), "X");
|
294
|
+
assert.equal(exports.lex(), "Y");
|
295
|
+
assert.equal(exports.lex(), "X");
|
296
|
+
assert.equal(exports.lex(), "EOF");
|
297
|
+
};
|
298
|
+
|
299
|
+
exports["test DJ lexer"] = function() {
|
300
|
+
var dict = {
|
301
|
+
"lex": {
|
302
|
+
"macros": {
|
303
|
+
"digit": "[0-9]",
|
304
|
+
"id": "[a-zA-Z][a-zA-Z0-9]*"
|
305
|
+
},
|
306
|
+
|
307
|
+
"rules": [
|
308
|
+
["//.*", "/* ignore comment */"],
|
309
|
+
["main\\b", "return 'MAIN';"],
|
310
|
+
["class\\b", "return 'CLASS';"],
|
311
|
+
["extends\\b", "return 'EXTENDS';"],
|
312
|
+
["nat\\b", "return 'NATTYPE';"],
|
313
|
+
["if\\b", "return 'IF';"],
|
314
|
+
["else\\b", "return 'ELSE';"],
|
315
|
+
["for\\b", "return 'FOR';"],
|
316
|
+
["printNat\\b", "return 'PRINTNAT';"],
|
317
|
+
["readNat\\b", "return 'READNAT';"],
|
318
|
+
["this\\b", "return 'THIS';"],
|
319
|
+
["new\\b", "return 'NEW';"],
|
320
|
+
["var\\b", "return 'VAR';"],
|
321
|
+
["null\\b", "return 'NUL';"],
|
322
|
+
["{digit}+", "return 'NATLITERAL';"],
|
323
|
+
["{id}", "return 'ID';"],
|
324
|
+
["==", "return 'EQUALITY';"],
|
325
|
+
["=", "return 'ASSIGN';"],
|
326
|
+
["\\+", "return 'PLUS';"],
|
327
|
+
["-", "return 'MINUS';"],
|
328
|
+
["\\*", "return 'TIMES';"],
|
329
|
+
[">", "return 'GREATER';"],
|
330
|
+
["\\|\\|", "return 'OR';"],
|
331
|
+
["!", "return 'NOT';"],
|
332
|
+
["\\.", "return 'DOT';"],
|
333
|
+
["\\{", "return 'LBRACE';"],
|
334
|
+
["\\}", "return 'RBRACE';"],
|
335
|
+
["\\(", "return 'LPAREN';"],
|
336
|
+
["\\)", "return 'RPAREN';"],
|
337
|
+
[";", "return 'SEMICOLON';"],
|
338
|
+
["\\s+", "/* skip whitespace */"],
|
339
|
+
[".", "print('Illegal character');throw 'Illegal character';"],
|
340
|
+
["$", "return 'ENDOFFILE';"]
|
341
|
+
]
|
342
|
+
}
|
343
|
+
};
|
344
|
+
|
345
|
+
var input = "class Node extends Object { \
|
346
|
+
var nat value var nat value;\
|
347
|
+
var Node next;\
|
348
|
+
var nat index;\
|
349
|
+
}\
|
350
|
+
\
|
351
|
+
class List extends Object {\
|
352
|
+
var Node start;\
|
353
|
+
\
|
354
|
+
Node prepend(Node startNode) {\
|
355
|
+
startNode.next = start;\
|
356
|
+
start = startNode;\
|
357
|
+
}\
|
358
|
+
\
|
359
|
+
nat find(nat index) {\
|
360
|
+
var nat value;\
|
361
|
+
var Node node;\
|
362
|
+
\
|
363
|
+
for(node = start;!(node == null);node = node.next){\
|
364
|
+
if(node.index == index){\
|
365
|
+
value = node.value;\
|
366
|
+
} else { 0; };\
|
367
|
+
};\
|
368
|
+
\
|
369
|
+
value;\
|
370
|
+
}\
|
371
|
+
}\
|
372
|
+
\
|
373
|
+
main {\
|
374
|
+
var nat index;\
|
375
|
+
var nat value;\
|
376
|
+
var List list;\
|
377
|
+
var Node startNode;\
|
378
|
+
\
|
379
|
+
index = readNat();\
|
380
|
+
list = new List;\
|
381
|
+
\
|
382
|
+
for(0;!(index==0);0){\
|
383
|
+
value = readNat();\
|
384
|
+
startNode = new Node;\
|
385
|
+
startNode.index = index;\
|
386
|
+
startNode.value = value;\
|
387
|
+
list.prepend(startNode);\
|
388
|
+
index = readNat();\
|
389
|
+
};\
|
390
|
+
\
|
391
|
+
index = readNat();\
|
392
|
+
\
|
393
|
+
for(0;!(index==0);0){\
|
394
|
+
printNat(list.find(index));\
|
395
|
+
index = readNat();\
|
396
|
+
};\
|
397
|
+
}";
|
398
|
+
|
399
|
+
var lexer = new RegExpLexer(dict.lex);
|
400
|
+
lexer.setInput(input);
|
401
|
+
var tok;
|
402
|
+
while (tok = lexer.lex()) {
|
403
|
+
assert.equal(typeof tok, "string");
|
404
|
+
}
|
405
|
+
};
|
406
|
+
|
407
|
+
exports["test instantiation from string"] = function() {
|
408
|
+
var dict = "%%\n'x' {return 'X';}\n'y' {return 'Y';}\n<<EOF>> {return 'EOF';}";
|
409
|
+
|
410
|
+
var input = "x";
|
411
|
+
|
412
|
+
var lexer = new RegExpLexer(dict);
|
413
|
+
lexer.setInput(input);
|
414
|
+
|
415
|
+
assert.equal(lexer.lex(), "X");
|
416
|
+
assert.equal(lexer.lex(), "EOF");
|
417
|
+
};
|