haml-more 0.4.0.a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. data/README.md +79 -0
  2. data/lib/haml/more/coffee_script.rb +137 -0
  3. data/lib/haml/more/content_for.rb +25 -0
  4. data/lib/haml/more.rb +45 -0
  5. data/lib/haml-more.rb +1 -0
  6. data/lib/sass/more.rb +16 -0
  7. data/lib/sass-more.rb +1 -0
  8. data/spec/sass/more_spec.rb +21 -0
  9. data/vendor/coffee-script/Cakefile +57 -0
  10. data/vendor/coffee-script/LICENSE +22 -0
  11. data/vendor/coffee-script/README +41 -0
  12. data/vendor/coffee-script/Rakefile +20 -0
  13. data/vendor/coffee-script/bin/cake +7 -0
  14. data/vendor/coffee-script/bin/coffee +7 -0
  15. data/vendor/coffee-script/documentation/coffee/aliases.coffee +9 -0
  16. data/vendor/coffee-script/documentation/coffee/arguments.coffee +4 -0
  17. data/vendor/coffee-script/documentation/coffee/array_comprehensions.coffee +7 -0
  18. data/vendor/coffee-script/documentation/coffee/assignment.coffee +2 -0
  19. data/vendor/coffee-script/documentation/coffee/cake_tasks.coffee +5 -0
  20. data/vendor/coffee-script/documentation/coffee/comparisons.coffee +5 -0
  21. data/vendor/coffee-script/documentation/coffee/conditionals.coffee +9 -0
  22. data/vendor/coffee-script/documentation/coffee/embedded.coffee +5 -0
  23. data/vendor/coffee-script/documentation/coffee/existence.coffee +8 -0
  24. data/vendor/coffee-script/documentation/coffee/expressions.coffee +9 -0
  25. data/vendor/coffee-script/documentation/coffee/expressions_assignment.coffee +1 -0
  26. data/vendor/coffee-script/documentation/coffee/expressions_comprehension.coffee +3 -0
  27. data/vendor/coffee-script/documentation/coffee/expressions_try.coffee +6 -0
  28. data/vendor/coffee-script/documentation/coffee/fat_arrow.coffee +6 -0
  29. data/vendor/coffee-script/documentation/coffee/functions.coffee +2 -0
  30. data/vendor/coffee-script/documentation/coffee/heredocs.coffee +5 -0
  31. data/vendor/coffee-script/documentation/coffee/multiple_return_values.coffee +5 -0
  32. data/vendor/coffee-script/documentation/coffee/object_comprehensions.coffee +4 -0
  33. data/vendor/coffee-script/documentation/coffee/object_extraction.coffee +13 -0
  34. data/vendor/coffee-script/documentation/coffee/objects_and_arrays.coffee +13 -0
  35. data/vendor/coffee-script/documentation/coffee/overview.coffee +29 -0
  36. data/vendor/coffee-script/documentation/coffee/parallel_assignment.coffee +4 -0
  37. data/vendor/coffee-script/documentation/coffee/range_comprehensions.coffee +6 -0
  38. data/vendor/coffee-script/documentation/coffee/scope.coffee +5 -0
  39. data/vendor/coffee-script/documentation/coffee/slices.coffee +6 -0
  40. data/vendor/coffee-script/documentation/coffee/soaks.coffee +1 -0
  41. data/vendor/coffee-script/documentation/coffee/splats.coffee +25 -0
  42. data/vendor/coffee-script/documentation/coffee/splices.coffee +5 -0
  43. data/vendor/coffee-script/documentation/coffee/strings.coffee +8 -0
  44. data/vendor/coffee-script/documentation/coffee/super.coffee +34 -0
  45. data/vendor/coffee-script/documentation/coffee/switch.coffee +10 -0
  46. data/vendor/coffee-script/documentation/coffee/try.coffee +7 -0
  47. data/vendor/coffee-script/documentation/coffee/while.coffee +10 -0
  48. data/vendor/coffee-script/documentation/css/docs.css +213 -0
  49. data/vendor/coffee-script/documentation/css/idle.css +63 -0
  50. data/vendor/coffee-script/documentation/css/logo.png +0 -0
  51. data/vendor/coffee-script/documentation/index.html.erb +967 -0
  52. data/vendor/coffee-script/documentation/js/aliases.js +14 -0
  53. data/vendor/coffee-script/documentation/js/arguments.js +8 -0
  54. data/vendor/coffee-script/documentation/js/array_comprehensions.js +26 -0
  55. data/vendor/coffee-script/documentation/js/assignment.js +5 -0
  56. data/vendor/coffee-script/documentation/js/cake_tasks.js +14 -0
  57. data/vendor/coffee-script/documentation/js/comparisons.js +5 -0
  58. data/vendor/coffee-script/documentation/js/conditionals.js +12 -0
  59. data/vendor/coffee-script/documentation/js/embedded.js +6 -0
  60. data/vendor/coffee-script/documentation/js/existence.js +7 -0
  61. data/vendor/coffee-script/documentation/js/expressions.js +13 -0
  62. data/vendor/coffee-script/documentation/js/expressions_assignment.js +4 -0
  63. data/vendor/coffee-script/documentation/js/expressions_comprehension.js +12 -0
  64. data/vendor/coffee-script/documentation/js/expressions_try.js +9 -0
  65. data/vendor/coffee-script/documentation/js/fat_arrow.js +15 -0
  66. data/vendor/coffee-script/documentation/js/functions.js +9 -0
  67. data/vendor/coffee-script/documentation/js/heredocs.js +4 -0
  68. data/vendor/coffee-script/documentation/js/intro.js +7 -0
  69. data/vendor/coffee-script/documentation/js/multiple_return_values.js +11 -0
  70. data/vendor/coffee-script/documentation/js/object_comprehensions.js +17 -0
  71. data/vendor/coffee-script/documentation/js/object_extraction.js +17 -0
  72. data/vendor/coffee-script/documentation/js/objects_and_arrays.js +10 -0
  73. data/vendor/coffee-script/documentation/js/overview.js +43 -0
  74. data/vendor/coffee-script/documentation/js/parallel_assignment.js +8 -0
  75. data/vendor/coffee-script/documentation/js/punctuation.js +8 -0
  76. data/vendor/coffee-script/documentation/js/range_comprehensions.js +21 -0
  77. data/vendor/coffee-script/documentation/js/scope.js +10 -0
  78. data/vendor/coffee-script/documentation/js/slices.js +6 -0
  79. data/vendor/coffee-script/documentation/js/soaks.js +4 -0
  80. data/vendor/coffee-script/documentation/js/splats.js +16 -0
  81. data/vendor/coffee-script/documentation/js/splices.js +5 -0
  82. data/vendor/coffee-script/documentation/js/strings.js +9 -0
  83. data/vendor/coffee-script/documentation/js/super.js +37 -0
  84. data/vendor/coffee-script/documentation/js/switch.js +18 -0
  85. data/vendor/coffee-script/documentation/js/try.js +10 -0
  86. data/vendor/coffee-script/documentation/js/while.js +22 -0
  87. data/vendor/coffee-script/documentation/underscore.html +627 -0
  88. data/vendor/coffee-script/examples/beautiful_code/binary_search.coffee +16 -0
  89. data/vendor/coffee-script/examples/beautiful_code/quicksort_runtime.coffee +13 -0
  90. data/vendor/coffee-script/examples/beautiful_code/regular_expression_matcher.coffee +34 -0
  91. data/vendor/coffee-script/examples/blocks.coffee +57 -0
  92. data/vendor/coffee-script/examples/code.coffee +173 -0
  93. data/vendor/coffee-script/examples/computer_science/README +4 -0
  94. data/vendor/coffee-script/examples/computer_science/binary_search.coffee +25 -0
  95. data/vendor/coffee-script/examples/computer_science/bubble_sort.coffee +11 -0
  96. data/vendor/coffee-script/examples/computer_science/linked_list.coffee +106 -0
  97. data/vendor/coffee-script/examples/computer_science/luhn_algorithm.coffee +36 -0
  98. data/vendor/coffee-script/examples/computer_science/merge_sort.coffee +19 -0
  99. data/vendor/coffee-script/examples/computer_science/selection_sort.coffee +23 -0
  100. data/vendor/coffee-script/examples/poignant.coffee +186 -0
  101. data/vendor/coffee-script/examples/potion.coffee +205 -0
  102. data/vendor/coffee-script/examples/underscore.coffee +603 -0
  103. data/vendor/coffee-script/examples/web_server.coffee +12 -0
  104. data/vendor/coffee-script/extras/CoffeeScript.tmbundle/Preferences/CoffeeScript.tmPreferences +24 -0
  105. data/vendor/coffee-script/extras/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +361 -0
  106. data/vendor/coffee-script/extras/CoffeeScript.tmbundle/info.plist +10 -0
  107. data/vendor/coffee-script/extras/EXTRAS +20 -0
  108. data/vendor/coffee-script/extras/coffee.vim +117 -0
  109. data/vendor/coffee-script/index.html +1847 -0
  110. data/vendor/coffee-script/lib/bin/cake +7 -0
  111. data/vendor/coffee-script/lib/bin/coffee +7 -0
  112. data/vendor/coffee-script/lib/cake.js +80 -0
  113. data/vendor/coffee-script/lib/coffee-script.js +61 -0
  114. data/vendor/coffee-script/lib/command_line.js +201 -0
  115. data/vendor/coffee-script/lib/grammar.js +564 -0
  116. data/vendor/coffee-script/lib/lexer.js +405 -0
  117. data/vendor/coffee-script/lib/narwhal.js +44 -0
  118. data/vendor/coffee-script/lib/nodes.js +1328 -0
  119. data/vendor/coffee-script/lib/optparse.js +117 -0
  120. data/vendor/coffee-script/lib/parser.js +536 -0
  121. data/vendor/coffee-script/lib/repl.js +32 -0
  122. data/vendor/coffee-script/lib/rewriter.js +383 -0
  123. data/vendor/coffee-script/lib/scope.js +114 -0
  124. data/vendor/coffee-script/package.json +7 -0
  125. data/vendor/coffee-script/src/cake.coffee +45 -0
  126. data/vendor/coffee-script/src/coffee-script.coffee +45 -0
  127. data/vendor/coffee-script/src/command_line.coffee +130 -0
  128. data/vendor/coffee-script/src/grammar.coffee +456 -0
  129. data/vendor/coffee-script/src/lexer.coffee +327 -0
  130. data/vendor/coffee-script/src/narwhal.coffee +42 -0
  131. data/vendor/coffee-script/src/nodes.coffee +1045 -0
  132. data/vendor/coffee-script/src/optparse.coffee +79 -0
  133. data/vendor/coffee-script/src/repl.coffee +23 -0
  134. data/vendor/coffee-script/src/rewriter.coffee +253 -0
  135. data/vendor/coffee-script/src/scope.coffee +75 -0
  136. data/vendor/coffee-script/test/test_arguments.coffee +34 -0
  137. data/vendor/coffee-script/test/test_array_comprehension.coffee +42 -0
  138. data/vendor/coffee-script/test/test_assignment.coffee +26 -0
  139. data/vendor/coffee-script/test/test_blocks.coffee +4 -0
  140. data/vendor/coffee-script/test/test_calling_super.coffee +42 -0
  141. data/vendor/coffee-script/test/test_chained_calls.coffee +25 -0
  142. data/vendor/coffee-script/test/test_destructuring_assignment.coffee +62 -0
  143. data/vendor/coffee-script/test/test_everything.coffee +29 -0
  144. data/vendor/coffee-script/test/test_exceptions.coffee +2 -0
  145. data/vendor/coffee-script/test/test_existence.coffee +81 -0
  146. data/vendor/coffee-script/test/test_expressions.coffee +30 -0
  147. data/vendor/coffee-script/test/test_fancy_if_statement.coffee +26 -0
  148. data/vendor/coffee-script/test/test_functions.coffee +80 -0
  149. data/vendor/coffee-script/test/test_funky_comments.coffee +25 -0
  150. data/vendor/coffee-script/test/test_heredocs.coffee +46 -0
  151. data/vendor/coffee-script/test/test_lexical_scope.coffee +10 -0
  152. data/vendor/coffee-script/test/test_literals.coffee +56 -0
  153. data/vendor/coffee-script/test/test_nested_comprehensions.coffee +11 -0
  154. data/vendor/coffee-script/test/test_newline_escaping.coffee +6 -0
  155. data/vendor/coffee-script/test/test_operations.coffee +18 -0
  156. data/vendor/coffee-script/test/test_range_comprehension.coffee +20 -0
  157. data/vendor/coffee-script/test/test_ranges_and_slices.coffee +16 -0
  158. data/vendor/coffee-script/test/test_splats.coffee +47 -0
  159. data/vendor/coffee-script/test/test_splices.coffee +5 -0
  160. data/vendor/coffee-script/test/test_switch.coffee +64 -0
  161. data/vendor/coffee-script/test/test_while.coffee +30 -0
  162. data/vendor/coffee-script/vendor/jison/Jakefile +31 -0
  163. data/vendor/coffee-script/vendor/jison/README.md +347 -0
  164. data/vendor/coffee-script/vendor/jison/bin/jison +3 -0
  165. data/vendor/coffee-script/vendor/jison/bin/json2jison +3 -0
  166. data/vendor/coffee-script/vendor/jison/examples/ansic.jison +415 -0
  167. data/vendor/coffee-script/vendor/jison/examples/basic.json +8 -0
  168. data/vendor/coffee-script/vendor/jison/examples/basic2.json +9 -0
  169. data/vendor/coffee-script/vendor/jison/examples/basic2_lex.json +16 -0
  170. data/vendor/coffee-script/vendor/jison/examples/basic_lex.json +15 -0
  171. data/vendor/coffee-script/vendor/jison/examples/calculator.jison +38 -0
  172. data/vendor/coffee-script/vendor/jison/examples/calculator.jisonlex +14 -0
  173. data/vendor/coffee-script/vendor/jison/examples/calculator.json +42 -0
  174. data/vendor/coffee-script/vendor/jison/examples/classy.json +105 -0
  175. data/vendor/coffee-script/vendor/jison/examples/classy_ast.json +126 -0
  176. data/vendor/coffee-script/vendor/jison/examples/dism.json +25 -0
  177. data/vendor/coffee-script/vendor/jison/examples/dism_lr0.json +26 -0
  178. data/vendor/coffee-script/vendor/jison/examples/json.js +80 -0
  179. data/vendor/coffee-script/vendor/jison/examples/json_ast.js +83 -0
  180. data/vendor/coffee-script/vendor/jison/examples/precedence.json +26 -0
  181. data/vendor/coffee-script/vendor/jison/examples/reduce_conflict.json +13 -0
  182. data/vendor/coffee-script/vendor/jison/lib/jison/bnf.js +43 -0
  183. data/vendor/coffee-script/vendor/jison/lib/jison/jisonlex.js +18 -0
  184. data/vendor/coffee-script/vendor/jison/lib/jison/json2jison.js +146 -0
  185. data/vendor/coffee-script/vendor/jison/lib/jison/lexer.js +224 -0
  186. data/vendor/coffee-script/vendor/jison/lib/jison/util/bnf-parser.js +383 -0
  187. data/vendor/coffee-script/vendor/jison/lib/jison/util/lex-parser.js +407 -0
  188. data/vendor/coffee-script/vendor/jison/lib/jison/util/set.js +94 -0
  189. data/vendor/coffee-script/vendor/jison/lib/jison/util/typal.js +90 -0
  190. data/vendor/coffee-script/vendor/jison/lib/jison.js +1414 -0
  191. data/vendor/coffee-script/vendor/jison/package.json +14 -0
  192. data/vendor/coffee-script/vendor/jison/src/bnf.jison +110 -0
  193. data/vendor/coffee-script/vendor/jison/src/bnf.jisonlex +25 -0
  194. data/vendor/coffee-script/vendor/jison/src/bnf.lex.json +24 -0
  195. data/vendor/coffee-script/vendor/jison/src/jisonlex.jison +129 -0
  196. data/vendor/coffee-script/vendor/jison/src/jisonlex.jisonlex +31 -0
  197. data/vendor/coffee-script/vendor/jison/src/jisonlex.lex.json +30 -0
  198. data/vendor/coffee-script/vendor/jison/tests/all-tests.js +8 -0
  199. data/vendor/coffee-script/vendor/jison/tests/grammar/bnf.js +91 -0
  200. data/vendor/coffee-script/vendor/jison/tests/grammar/bnf_parse.js +65 -0
  201. data/vendor/coffee-script/vendor/jison/tests/grammar/grammar-tests.js +10 -0
  202. data/vendor/coffee-script/vendor/jison/tests/grammar/json2jison.js +24 -0
  203. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/ansic.jisonlex +115 -0
  204. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/bnf.jisonlex +25 -0
  205. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/bnf.lex.json +24 -0
  206. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/lex_grammar.jisonlex +31 -0
  207. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/lex_grammar.lex.json +30 -0
  208. data/vendor/coffee-script/vendor/jison/tests/grammar/lex.jison +119 -0
  209. data/vendor/coffee-script/vendor/jison/tests/grammar/lex.js +58 -0
  210. data/vendor/coffee-script/vendor/jison/tests/grammar/lex_parse.js +117 -0
  211. data/vendor/coffee-script/vendor/jison/tests/lexer/lexer-tests.js +6 -0
  212. data/vendor/coffee-script/vendor/jison/tests/lexer/regexplexer.js +417 -0
  213. data/vendor/coffee-script/vendor/jison/tests/parser/actions.js +311 -0
  214. data/vendor/coffee-script/vendor/jison/tests/parser/api.js +236 -0
  215. data/vendor/coffee-script/vendor/jison/tests/parser/generator.js +196 -0
  216. data/vendor/coffee-script/vendor/jison/tests/parser/lalr.js +183 -0
  217. data/vendor/coffee-script/vendor/jison/tests/parser/lr0.js +72 -0
  218. data/vendor/coffee-script/vendor/jison/tests/parser/lr1.js +119 -0
  219. data/vendor/coffee-script/vendor/jison/tests/parser/parser-tests.js +14 -0
  220. data/vendor/coffee-script/vendor/jison/tests/parser/precedence.js +237 -0
  221. data/vendor/coffee-script/vendor/jison/tests/parser/slr.js +52 -0
  222. data/vendor/coffee-script/vendor/jison/tests/parser/tables.js +126 -0
  223. data/vendor/coffee-script/vendor/jison/tests/performance.js +110 -0
  224. data/vendor/coffee-script/vendor/jison/tests/setup.js +3 -0
  225. metadata +324 -0
@@ -0,0 +1,311 @@
1
+ var Jison = require("../setup").Jison,
2
+ RegExpLexer = require("../setup").RegExpLexer,
3
+ assert = require("assert");
4
+
5
+ exports["test Semantic action basic return"] = function() {
6
+ var lexData = {
7
+ rules: [
8
+ ["x", "return 'x';"],
9
+ ["y", "return 'y';"]
10
+ ]
11
+ };
12
+ var grammar = {
13
+ bnf: {
14
+ "E" :[ ["E x", "return 0"],
15
+ ["E y", "return 1"],
16
+ "" ]
17
+ }
18
+ };
19
+
20
+ var parser = new Jison.Parser(grammar);
21
+ parser.lexer = new RegExpLexer(lexData);
22
+
23
+ assert.equal(parser.parse('x'), 0, "semantic action");
24
+ assert.equal(parser.parse('y'), 1, "semantic action");
25
+ };
26
+
27
+ exports["test return null"] = function() {
28
+ var lexData = {
29
+ rules: [
30
+ ["x", "return 'x';"]
31
+ ]
32
+ };
33
+ var grammar = {
34
+ bnf: {
35
+ "E" :[ ["E x", "return null;"],
36
+ "" ]
37
+ }
38
+ };
39
+
40
+ var parser = new Jison.Parser(grammar);
41
+ parser.lexer = new RegExpLexer(lexData);
42
+
43
+ assert.equal(parser.parse('x'), null, "semantic action");
44
+ };
45
+
46
+ exports["test terminal semantic values are null"] = function() {
47
+ var lexData = {
48
+ rules: [
49
+ ["x", "return 'x';"],
50
+ ["y", "return 'y';"]
51
+ ]
52
+ };
53
+ var grammar = {
54
+ bnf: {
55
+ "E" :[ ["E x", "return [$2 === null]"],
56
+ ["E y", "return [$2]"],
57
+ "" ]
58
+ }
59
+ };
60
+
61
+ var parser = new Jison.Parser(grammar);
62
+ parser.lexer = new RegExpLexer(lexData);
63
+
64
+ assert.deepEqual(parser.parse('x'), [true], "semantic action");
65
+ assert.deepEqual(parser.parse('y'), [null], "semantic action");
66
+ };
67
+
68
+ exports["test Semantic action stack lookup"] = function() {
69
+ var lexData = {
70
+ rules: [
71
+ ["x", "return 'x';"],
72
+ ["y", "return 'y';"]
73
+ ]
74
+ };
75
+ var grammar = {
76
+ bnf: {
77
+ "pgm" :[ ["E", "return $1"] ],
78
+ "E" :[ ["B E", "return $1+$2"],
79
+ ["x", "$$ = 'EX'"] ],
80
+ "B" :[ ["y", "$$ = 'BY'"] ]
81
+ }
82
+ };
83
+
84
+ var parser = new Jison.Parser(grammar);
85
+ parser.lexer = new RegExpLexer(lexData);
86
+
87
+ assert.equal(parser.parse('x'), "EX", "return first token");
88
+ assert.equal(parser.parse('yx'), "BYEX", "return first after reduction");
89
+ };
90
+
91
+ exports["test Semantic actions on nullable grammar"] = function() {
92
+ var lexData = {
93
+ rules: [
94
+ ["x", "return 'x';"]
95
+ ]
96
+ };
97
+ var grammar = {
98
+ bnf: {
99
+ "S" :[ ["A", "return $1"] ],
100
+ "A" :[ ['x A', "$$ = $2+'x'" ],
101
+ ['', "$$ = '->'" ] ]
102
+ }
103
+ };
104
+
105
+ var parser = new Jison.Parser(grammar);
106
+ parser.lexer = new RegExpLexer(lexData);
107
+
108
+ assert.equal(parser.parse('xx'), "->xx", "return first after reduction");
109
+ };
110
+
111
+ exports["test named semantic value"] = function() {
112
+ var lexData = {
113
+ rules: [
114
+ ["x", "return 'x';"]
115
+ ]
116
+ };
117
+ var grammar = {
118
+ bnf: {
119
+ "S" :[ ["A", "return $A"] ],
120
+ "A" :[ ['x A', "$$ = $A+'x'" ],
121
+ ['', "$$ = '->'" ] ]
122
+ }
123
+ };
124
+
125
+ var parser = new Jison.Parser(grammar);
126
+ parser.lexer = new RegExpLexer(lexData);
127
+
128
+ assert.equal(parser.parse('xx'), "->xx", "return first after reduction");
129
+ };
130
+
131
+ exports["test ambiguous named semantic value"] = function() {
132
+ var lexData = {
133
+ rules: [
134
+ ["x", "return 'x';"],
135
+ ["y", "return 'y';"]
136
+ ]
137
+ };
138
+ var grammar = {
139
+ operators: [["left", "y"]],
140
+ bnf: {
141
+ "S" :[ ["A", "return $A"] ],
142
+ "A" :[ ['A y A', "$$ = $A2+'y'+$A1" ],
143
+ ['x', "$$ = 'x'" ] ]
144
+ }
145
+ };
146
+
147
+ var parser = new Jison.Parser(grammar);
148
+ parser.lexer = new RegExpLexer(lexData);
149
+
150
+ assert.equal(parser.parse('xyx'), "xyx", "return first after reduction");
151
+ };
152
+
153
+ exports["test Build AST"] = function() {
154
+ var lexData = {
155
+ rules: [
156
+ ["x", "return 'x';"]
157
+ ]
158
+ };
159
+ var grammar = {
160
+ bnf: {
161
+ "S" :[ ['A', "return $1;" ] ],
162
+ "A" :[ ['x A', "$2.push(['ID',{value:'x'}]); $$ = $2;"],
163
+ ['', "$$ = ['A',{}];"] ]
164
+ }
165
+ };
166
+
167
+ var parser = new Jison.Parser(grammar);
168
+ parser.lexer = new RegExpLexer(lexData);
169
+
170
+ var expectedAST = ['A',{},
171
+ ['ID',{value:'x'}],
172
+ ['ID',{value:'x'}],
173
+ ['ID',{value:'x'}]];
174
+
175
+ var r = parser.parse("xxx");
176
+ assert.deepEqual(r, expectedAST);
177
+ };
178
+
179
+ exports["test 0+0 grammar"] = function() {
180
+ var lexData2 = {
181
+ rules: [
182
+ ["0", "return 'ZERO';"],
183
+ ["\\+", "return 'PLUS';"],
184
+ ["$", "return 'EOF';"]
185
+ ]
186
+ };
187
+ var grammar = {
188
+ bnf: {
189
+ "S" :[ [ "E EOF", "return $1" ]],
190
+ "E" :[ [ "E PLUS T", "$$ = ['+',$1,$3]" ],
191
+ [ "T", "$$ = $1" ] ],
192
+ "T" :[ [ "ZERO", "$$ = [0]" ] ]
193
+ }
194
+ };
195
+
196
+ var parser = new Jison.Parser(grammar);
197
+ parser.lexer = new RegExpLexer(lexData2);
198
+
199
+ var expectedAST = ["+", ["+", [0], [0]], [0]];
200
+
201
+ assert.deepEqual(parser.parse("0+0+0"), expectedAST);
202
+ };
203
+
204
+ exports["test implicit $$ = $1 action"] = function() {
205
+ var lexData2 = {
206
+ rules: [
207
+ ["0", "return 'ZERO';"],
208
+ ["\\+", "return 'PLUS';"],
209
+ ["$", "return 'EOF';"]
210
+ ]
211
+ };
212
+ var grammar = {
213
+ bnf: {
214
+ "S" :[ [ "E EOF", "return $1" ]],
215
+ "E" :[ [ "E PLUS T", "$$ = ['+',$1,$3]" ],
216
+ "T" ],
217
+ "T" :[ [ "ZERO", "$$ = [0]" ] ]
218
+ }
219
+ };
220
+
221
+ var parser = new Jison.Parser(grammar);
222
+ parser.lexer = new RegExpLexer(lexData2);
223
+
224
+ var expectedAST = ["+", ["+", [0], [0]], [0]];
225
+
226
+ assert.deepEqual(parser.parse("0+0+0"), expectedAST);
227
+ };
228
+
229
+ exports["test yytext"] = function() {
230
+ var lexData = {
231
+ rules: [
232
+ ["x", "return 'x';"]
233
+ ]
234
+ };
235
+ var grammar = {
236
+ bnf: {
237
+ "pgm" :[ ["Xexpr", "return $1;"] ],
238
+ "Xexpr" :[ ["x", "$$ = yytext;"] ]
239
+ }
240
+ };
241
+
242
+ var parser = new Jison.Parser(grammar);
243
+ parser.lexer = new RegExpLexer(lexData);
244
+
245
+ assert.equal(parser.parse('x'), "x", "return first token");
246
+ };
247
+
248
+ exports["test yyleng"] = function() {
249
+ var lexData = {
250
+ rules: [
251
+ ["x", "return 'x';"]
252
+ ]
253
+ };
254
+ var grammar = {
255
+ bnf: {
256
+ "pgm" :[ ["Xexpr", "return $1;"] ],
257
+ "Xexpr" :[ ["x", "$$ = yyleng;"] ]
258
+ }
259
+ };
260
+
261
+ var parser = new Jison.Parser(grammar);
262
+ parser.lexer = new RegExpLexer(lexData);
263
+
264
+ assert.equal(parser.parse('x'), 1, "return first token");
265
+ };
266
+
267
+ exports["test yytext more"] = function() {
268
+ var lexData = {
269
+ rules: [
270
+ ["x", "return 'x';"],
271
+ ["y", "return 'y';"]
272
+ ]
273
+ };
274
+ var grammar = {
275
+ bnf: {
276
+ "pgm" :[ ["expr expr", "return $1+$2;"] ],
277
+ "expr" :[ ["x", "$$ = yytext;"],
278
+ ["y", "$$ = yytext;"] ]
279
+ }
280
+ };
281
+
282
+ var parser = new Jison.Parser(grammar);
283
+ parser.lexer = new RegExpLexer(lexData);
284
+
285
+ assert.equal(parser.parse('xy'), "xy", "return first token");
286
+ };
287
+
288
+ exports["test action include"] = function() {
289
+ var lexData = {
290
+ rules: [
291
+ ["y", "return 'y';"]
292
+ ]
293
+ };
294
+ var grammar = {
295
+ bnf: {
296
+ "E" :[ ["E y", "return test();"],
297
+ "" ]
298
+ },
299
+ actionInclude: function () {
300
+ function test(val) {
301
+ return 1;
302
+ }
303
+ }
304
+ };
305
+
306
+ var parser = new Jison.Parser(grammar);
307
+ parser.lexer = new RegExpLexer(lexData);
308
+
309
+ assert.equal(parser.parse('y'), 1, "semantic action");
310
+ };
311
+
@@ -0,0 +1,236 @@
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 tokens as a string"] = function () {
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 parser = new Jison.Parser(grammar);
25
+ parser.lexer = new Lexer(lexData);
26
+ assert.ok(parser.parse('xyx'), "parse xyx");
27
+ };
28
+
29
+ exports["test generator"] = function () {
30
+
31
+ var grammar = {
32
+ bnf: {
33
+ "A" :[ 'A x',
34
+ 'A y',
35
+ '' ]
36
+ }
37
+ };
38
+
39
+ var parser = new Jison.Parser(grammar);
40
+ parser.lexer = new Lexer(lexData);
41
+ assert.ok(parser.parse('xyx'), "parse xyx");
42
+ };
43
+
44
+ exports["test extra spaces in productions"] = function () {
45
+
46
+ var grammar = {
47
+ tokens: "x y",
48
+ startSymbol: "A",
49
+ bnf: {
50
+ "A" :[ 'A x ',
51
+ 'A y',
52
+ '' ]
53
+ }
54
+ };
55
+
56
+ var parser = new Jison.Parser(grammar);
57
+ parser.lexer = new Lexer(lexData);
58
+ assert.ok(parser.parse('xyx'), "parse xyx");
59
+ };
60
+
61
+ exports["test | seperated rules"] = function () {
62
+
63
+ var grammar = {
64
+ tokens: "x y",
65
+ startSymbol: "A",
66
+ bnf: {
67
+ "A" :"A x | A y | "
68
+ }
69
+ };
70
+
71
+ var parser = new Jison.Parser(grammar);
72
+ parser.lexer = new Lexer(lexData);
73
+ assert.ok(parser.parse('xyx'), "parse xyx");
74
+ };
75
+
76
+ exports["test start symbol optional"] = function () {
77
+
78
+ var grammar = {
79
+ tokens: "x y",
80
+ bnf: {
81
+ "A" :"A x | A y | "
82
+ }
83
+ };
84
+
85
+ var parser = new Jison.Parser(grammar);
86
+ var ok = true;
87
+ assert.ok(ok, "no error");
88
+ };
89
+
90
+ exports["test start symbol should be nonterminal"] = function () {
91
+
92
+ var grammar = {
93
+ tokens: "x y",
94
+ startSymbol: "x",
95
+ bnf: {
96
+ "A" :"A x | A y | "
97
+ }
98
+ };
99
+
100
+ assert["throws"](function(){new Jison.Generator(grammar);}, "throws error");
101
+ };
102
+
103
+ exports["test token list as string"] = function () {
104
+
105
+ var grammar = {
106
+ tokens: "x y",
107
+ startSymbol: "A",
108
+ bnf: {
109
+ "A" :"A x | A y | "
110
+ }
111
+ };
112
+
113
+ var gen = new Jison.Generator(grammar);
114
+ assert.deepEqual(gen.terminals, ["$end", "x", "y"]);
115
+ };
116
+
117
+ exports["test grammar options"] = function () {
118
+
119
+ var grammar = {
120
+ options: {type: "slr"},
121
+ tokens: "x y",
122
+ startSymbol: "A",
123
+ bnf: {
124
+ "A" :[ 'A x',
125
+ 'A y',
126
+ '' ]
127
+ }
128
+ };
129
+
130
+ var gen = new Jison.Generator(grammar);
131
+ assert.ok(gen);
132
+ };
133
+
134
+ exports["test overwrite grammar options"] = function () {
135
+
136
+ var grammar = {
137
+ options: {type: "slr"},
138
+ tokens: "x y",
139
+ startSymbol: "A",
140
+ bnf: {
141
+ "A" :[ 'A x',
142
+ 'A y',
143
+ '' ]
144
+ }
145
+ };
146
+
147
+ var gen = new Jison.Generator(grammar, {type: "lr0"});
148
+ assert.equal(gen.constructor, Jison.LR0Generator);
149
+ };
150
+
151
+ exports["test yy shared scope"] = function () {
152
+ var lexData = {
153
+ rules: [
154
+ ["x", "return 'x';"],
155
+ ["y", "return yy.xed ? 'yfoo' : 'ybar';"]
156
+ ]
157
+ };
158
+ var grammar = {
159
+ tokens: "x yfoo ybar",
160
+ startSymbol: "A",
161
+ bnf: {
162
+ "A" :[[ 'A x', "yy.xed = true;" ],
163
+ [ 'A yfoo', " return 'foo';" ],
164
+ [ 'A ybar', " return 'bar';" ],
165
+ '' ]
166
+ }
167
+ };
168
+
169
+ var parser = new Jison.Parser(grammar, {type: "lr0"});
170
+ parser.lexer = new Lexer(lexData);
171
+ assert.equal(parser.parse('y'), "bar", "should return bar");
172
+ assert.equal(parser.parse('xxy'), "foo", "should return foo");
173
+ };
174
+
175
+
176
+ exports["test optional token declaration"] = function () {
177
+
178
+ var grammar = {
179
+ options: {type: "slr"},
180
+ bnf: {
181
+ "A" :[ 'A x',
182
+ 'A y',
183
+ '' ]
184
+ }
185
+ };
186
+
187
+ var gen = new Jison.Generator(grammar, {type: "lr0"});
188
+ assert.equal(gen.constructor, Jison.LR0Generator);
189
+ };
190
+
191
+
192
+ exports["test custom parse error method"] = function () {
193
+ var lexData = {
194
+ rules: [
195
+ ["a", "return 'a';"],
196
+ ["b", "return 'b';"],
197
+ ["c", "return 'c';"],
198
+ ["d", "return 'd';"],
199
+ ["g", "return 'g';"]
200
+ ]
201
+ };
202
+ var grammar = {
203
+ "tokens": "a b c d g",
204
+ "startSymbol": "S",
205
+ "bnf": {
206
+ "S" :[ "a g d",
207
+ "a A c",
208
+ "b A d",
209
+ "b g c" ],
210
+ "A" :[ "B" ],
211
+ "B" :[ "g" ]
212
+ }
213
+ };
214
+
215
+ var parser = new Jison.Parser(grammar, {type: "lalr"});
216
+ parser.lexer = new Lexer(lexData);
217
+ var result={};
218
+ parser.yy.parseError = function (str, hash) {
219
+ result = hash;
220
+ throw str;
221
+ };
222
+
223
+ assert["throws"](function () {parser.parse("aga")});
224
+ assert.strictEqual(result.text, "a", "parse error text should equal b");
225
+ assert.strictEqual(typeof result.token, 'string', "parse error token should be a string");
226
+ assert.strictEqual(result.line, 0, "hash should include line number");
227
+ };
228
+
229
+ exports["test jison grammar as string"] = function () {
230
+
231
+ var grammar = "%% A : A x | A y | ;"
232
+
233
+ var parser = new Jison.Generator(grammar).createParser();
234
+ parser.lexer = new Lexer(lexData);
235
+ assert.ok(parser.parse('xyx'), "parse xyx");
236
+ };