haml-more 0.4.0.a

Sign up to get free protection for your applications and to get access to all the features.
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,126 @@
1
+ {
2
+ "comment": "ClassyLang grammar with AST-building actions. Very classy.",
3
+ "author": "Zach Carter",
4
+ "lex": {
5
+ "macros": {
6
+ "digit": "[0-9]",
7
+ "id": "[a-zA-Z][a-zA-Z0-9]*"
8
+ },
9
+
10
+ "rules": [
11
+ ["//.*", "/* ignore comment */"],
12
+ ["main\\b", "return 'MAIN';"],
13
+ ["class\\b", "return 'CLASS';"],
14
+ ["extends\\b", "return 'EXTENDS';"],
15
+ ["nat\\b", "return 'NATTYPE';"],
16
+ ["if\\b", "return 'IF';"],
17
+ ["else\\b", "return 'ELSE';"],
18
+ ["for\\b", "return 'FOR';"],
19
+ ["printNat\\b", "return 'PRINTNAT';"],
20
+ ["readNat\\b", "return 'READNAT';"],
21
+ ["this\\b", "return 'THIS';"],
22
+ ["new\\b", "return 'NEW';"],
23
+ ["var\\b", "return 'VAR';"],
24
+ ["null\\b", "return 'NUL';"],
25
+ ["{digit}+", "return 'NATLITERAL';"],
26
+ ["{id}", "return 'ID';"],
27
+ ["==", "return 'EQUALITY';"],
28
+ ["=", "return 'ASSIGN';"],
29
+ ["\\+", "return 'PLUS';"],
30
+ ["-", "return 'MINUS';"],
31
+ ["\\*", "return 'TIMES';"],
32
+ [">", "return 'GREATER';"],
33
+ ["\\|\\|", "return 'OR';"],
34
+ ["!", "return 'NOT';"],
35
+ ["\\.", "return 'DOT';"],
36
+ ["\\{", "return 'LBRACE';"],
37
+ ["\\}", "return 'RBRACE';"],
38
+ ["\\(", "return 'LPAREN';"],
39
+ ["\\)", "return 'RPAREN';"],
40
+ [";", "return 'SEMICOLON';"],
41
+ ["\\s+", "/* skip whitespace */"],
42
+ [".", "throw 'Illegal character: '+yytext;"],
43
+ ["$", "return 'ENDOFFILE';"]
44
+ ]
45
+ },
46
+
47
+ "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",
48
+ "operators": [
49
+ ["right", "ASSIGN"],
50
+ ["left", "OR"],
51
+ ["nonassoc", "EQUALITY", "GREATER"],
52
+ ["left", "PLUS", "MINUS"],
53
+ ["left", "TIMES"],
54
+ ["right", "NOT"],
55
+ ["left", "DOT"]
56
+ ],
57
+
58
+ "bnf": {
59
+ "pgm": [["cdl MAIN LBRACE vdl el RBRACE ENDOFFILE",
60
+ "$$ = ['PROGRAM',{},$1,$4,$5]; return $$;"]],
61
+
62
+ "cdl": [["c cdl",
63
+ "$$ = prependChild($2, $1);"],
64
+ ["",
65
+ "$$ = ['CLASS_DECL_LIST',{}];"]],
66
+
67
+ "c": [["CLASS id EXTENDS id LBRACE vdl mdl RBRACE",
68
+ "$$ = ['CLASS_DECL',{},$2,$4,$6,$7];"]],
69
+
70
+ "vdl": [["VAR t id SEMICOLON vdl",
71
+ "$$ = prependChild($5, ['VAR_DECL',{},$2,$3]);"],
72
+ ["",
73
+ "$$ = ['VAR_DECL_LIST',{}];"]],
74
+
75
+ "mdl": [["t id LPAREN t id RPAREN LBRACE vdl el RBRACE mdl",
76
+ "$$ = prependChild($11, ['METHOD_DECL',{},$1,$2,$4,$5,$8,$9]);"],
77
+ ["",
78
+ "$$ = ['METHOD_DECL_LIST',{}];"]],
79
+
80
+ "t": [["NATTYPE",
81
+ "$$ = ['NAT_TYPE',{}];"],
82
+ ["id",
83
+ "$$ = $1"]],
84
+
85
+ "id": [["ID",
86
+ "$$ = ['AST_ID',{val:yytext}]"]],
87
+ "el": [["e SEMICOLON el",
88
+ "$$ = prependChild($3, $1);"],
89
+ ["e SEMICOLON",
90
+ "$$ = ['EXPR_LIST',{},$1];"]],
91
+
92
+ "e": [["NATLITERAL", "$$ = ['NAT_LITERAL_EXPR',{val:parseInt(yytext)}];"],
93
+ ["NUL", "$$ = ['NULL_EXPR',{}];"],
94
+ ["id", "$$ = ['ID_EXPR',{},$1];"],
95
+ ["NEW id", "$$ = ['NEW_EXPR',{},$2];"],
96
+ ["THIS", "$$ = ['THIS_EXPR',{}];"],
97
+ ["IF LPAREN e RPAREN LBRACE el RBRACE ELSE LBRACE el RBRACE",
98
+ "$$ = ['IF_THEN_ELSE_EXPR',{},$3,$6,$10];"],
99
+ ["FOR LPAREN e SEMICOLON e SEMICOLON e RPAREN LBRACE el RBRACE",
100
+ "$$ = ['FOR_EXPR',{},$3,$5,$7,$10];"],
101
+ ["READNAT LPAREN RPAREN",
102
+ "$$ = ['READ_EXPR',{}];"],
103
+ ["PRINTNAT LPAREN e RPAREN",
104
+ "$$ = ['PRINT_EXPR',{},$3];"],
105
+ ["e PLUS e", "$$ = ['PLUS_EXPR',{},$1,$3];"],
106
+ ["e MINUS e", "$$ = ['MINUS_EXPR',{},$1,$3];"],
107
+ ["e TIMES e", "$$ = ['TIMES_EXPR',{},$1,$3];"],
108
+ ["e EQUALITY e", "$$ = ['EQUALITY_EXPR',{},$1,$3];"],
109
+ ["e GREATER e", "$$ = ['GREATER_THAN_EXPR',{},$1,$3];"],
110
+ ["NOT e", "$$ = ['NOT_EXPR',{},$2];"],
111
+ ["e OR e", "$$ = ['OR_EXPR',{},$1,$3];"],
112
+ ["e DOT id", "$$ = ['DOT_ID_EXPR',{},$1,$3];"],
113
+ ["id ASSIGN e", "$$ = ['ASSIGN_EXPR',{},$1,$3];"],
114
+ ["e DOT id ASSIGN e",
115
+ "$$ = ['DOT_ASSIGN_EXPR',{},$1,$3,$5];"],
116
+ ["id LPAREN e RPAREN",
117
+ "$$ = ['METHOD_CALL_EXPR',{},$1,$3];"],
118
+ ["e DOT id LPAREN e RPAREN",
119
+ "$$ = ['DOT_METHOD_CALL_EXPR',{},$1,$3,$5];"],
120
+ ["LPAREN e RPAREN",
121
+ "$$ = $2;"]]
122
+ },
123
+
124
+ "actionInclude": "function prependChild(node, child){ node.splice(2,0,child); return node; }"
125
+ }
126
+
@@ -0,0 +1,25 @@
1
+ {
2
+ "author": "Jay Ligatti",
3
+
4
+ "tokens": "ADD SUB MUL MOV LOD STR JMP BEQ BLT RDN PTN HLT INT LABEL COLON",
5
+ "bnf": {
6
+ "pgm" :[ "instlist" ],
7
+ "instlist" :[ "label COLON inst instlist",
8
+ "inst instlist",
9
+ "" ],
10
+ "inst" :[ "ADD intt intt intt",
11
+ "SUB intt intt intt",
12
+ "MUL intt intt intt",
13
+ "MOV intt intt",
14
+ "LOD intt intt intt",
15
+ "STR intt intt intt",
16
+ "JMP intt intt intt",
17
+ "BEQ intt intt intt",
18
+ "BLT intt intt intt",
19
+ "RDN intt",
20
+ "PTN intt",
21
+ "HLT intt"],
22
+ "label" :[ "LABEL" ],
23
+ "intt" :[ "INT", "label" ]
24
+ }
25
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "author": "Jay Ligatti",
3
+
4
+ "tokens": "ADD SUB MUL MOV LOD STR JMP BEQ BLT RDN PTN HLT INT LABEL COLON",
5
+ "bnf": {
6
+ "instlist" :[ "instlist label COLON inst",
7
+ "instlist inst",
8
+ "inst" ],
9
+
10
+ "inst" :[ "ADD intt intt intt",
11
+ "SUB intt intt intt",
12
+ "MUL intt intt intt",
13
+ "MOV intt intt",
14
+ "LOD intt intt intt",
15
+ "STR intt intt intt",
16
+ "JMP intt intt intt",
17
+ "BEQ intt intt intt",
18
+ "BLT intt intt intt",
19
+ "RDN intt",
20
+ "PTN intt",
21
+ "HLT intt"],
22
+ "label" :[ "LABEL" ],
23
+ "intt" :[ "INT", "label" ]
24
+ }
25
+ }
26
+
@@ -0,0 +1,80 @@
1
+ var Generator = require("jison").Generator;
2
+ var system = require("system");
3
+ var fs = require("file");
4
+
5
+ exports.grammar = {
6
+ "comment": "ECMA-262 5th Edition, 15.12.1 The JSON Grammar.",
7
+ "author": "Zach Carter",
8
+
9
+ "lex": {
10
+ "macros": {
11
+ "digit": "[0-9]",
12
+ "esc": "\\\\",
13
+ "int": "-?(?:[0-9]|[1-9][0-9]+)",
14
+ "exp": "(?:[eE][-+]?[0-9]+)",
15
+ "frac": "(?:\\.[0-9]+)"
16
+ },
17
+ "rules": [
18
+ ["\\s+", "/* skip whitespace */"],
19
+ ["{int}{frac}?{exp}?\\b", "return 'NUMBER';"],
20
+ ["\"(?:{esc}[\"bfnrt/{esc}]|{esc}u[a-fA-F0-9]{4}|[^\"{esc}])*\"", "yytext = yytext.substr(1,yyleng-2); return 'STRING';"],
21
+ ["\\{", "return '{'"],
22
+ ["\\}", "return '}'"],
23
+ ["\\[", "return '['"],
24
+ ["\\]", "return ']'"],
25
+ [",", "return ','"],
26
+ [":", "return ':'"],
27
+ ["true\\b", "return 'TRUE'"],
28
+ ["false\\b", "return 'FALSE'"],
29
+ ["null\\b", "return 'NULL'"]
30
+ ]
31
+ },
32
+
33
+ "tokens": "STRING NUMBER { } [ ] , : TRUE FALSE NULL",
34
+ "start": "JSONText",
35
+
36
+ "bnf": {
37
+ "JSONString": [ "STRING" ],
38
+
39
+ "JSONNumber": [ "NUMBER" ],
40
+
41
+ "JSONBooleanLiteral": [ "TRUE", "FALSE" ],
42
+
43
+
44
+ "JSONText": [ "JSONValue" ],
45
+
46
+ "JSONValue": [ "JSONNullLiteral",
47
+ "JSONBooleanLiteral",
48
+ "JSONString",
49
+ "JSONNumber",
50
+ "JSONObject",
51
+ "JSONArray" ],
52
+
53
+ "JSONObject": [ "{ }",
54
+ "{ JSONMemberList }" ],
55
+
56
+ "JSONMember": [ "JSONString : JSONValue" ],
57
+
58
+ "JSONMemberList": [ "JSONMember",
59
+ "JSONMemberList , JSONMember" ],
60
+
61
+ "JSONArray": [ "[ ]",
62
+ "[ JSONElementList ]" ],
63
+
64
+ "JSONElementList": [ "JSONValue",
65
+ "JSONElementList , JSONValue" ]
66
+ }
67
+ };
68
+
69
+ var options = {type: "slr", moduleType: "commonjs", moduleName: "jsoncheck"};
70
+
71
+ exports.main = function main (args) {
72
+ var cwd = fs.path(fs.cwd()),
73
+ code = new Generator(exports.grammar, options).generate(),
74
+ stream = cwd.join(options.moduleName+".js").open("w");
75
+ stream.print(code).close();
76
+ };
77
+
78
+ if (require.main === module)
79
+ exports.main(system.args);
80
+
@@ -0,0 +1,83 @@
1
+ var Generator = require("jison").Generator;
2
+ var system = require("system");
3
+ var fs = require("file");
4
+
5
+ exports.grammar = {
6
+ "comment": "ECMA-262 5th Edition, 15.12.1 The JSON Grammar. Parses JSON strings into objects.",
7
+ "author": "Zach Carter",
8
+
9
+ "lex": {
10
+ "macros": {
11
+ "digit": "[0-9]",
12
+ "esc": "\\\\",
13
+ "int": "-?(?:[0-9]|[1-9][0-9]+)",
14
+ "exp": "(?:[eE][-+]?[0-9]+)",
15
+ "frac": "(?:\\.[0-9]+)"
16
+ },
17
+ "rules": [
18
+ ["\\s+", "/* skip whitespace */"],
19
+ ["{int}{frac}?{exp}?\\b", "return 'NUMBER';"],
20
+ ["\"(?:{esc}[\"bfnrt/{esc}]|{esc}u[a-fA-F0-9]{4}|[^\"{esc}])*\"", "yytext = yytext.substr(1,yyleng-2); return 'STRING';"],
21
+ ["\\{", "return '{'"],
22
+ ["\\}", "return '}'"],
23
+ ["\\[", "return '['"],
24
+ ["\\]", "return ']'"],
25
+ [",", "return ','"],
26
+ [":", "return ':'"],
27
+ ["true\\b", "return 'TRUE'"],
28
+ ["false\\b", "return 'FALSE'"],
29
+ ["null\\b", "return 'NULL'"]
30
+ ]
31
+ },
32
+
33
+ "tokens": "STRING NUMBER { } [ ] , : TRUE FALSE NULL",
34
+ "start": "JSONText",
35
+
36
+ "bnf": {
37
+ "JSONString": [[ "STRING", "$$ = yytext;" ]],
38
+
39
+ "JSONNumber": [[ "NUMBER", "$$ = Number(yytext);" ]],
40
+
41
+ "JSONNullLiteral": [[ "NULL", "$$ = null;" ]],
42
+
43
+ "JSONBooleanLiteral": [[ "TRUE", "$$ = true;" ],
44
+ [ "FALSE", "$$ = false;" ]],
45
+
46
+
47
+ "JSONText": [[ "JSONValue", "return $$ = $1;" ]],
48
+
49
+ "JSONValue": [[ "JSONNullLiteral", "$$ = $1;" ],
50
+ [ "JSONBooleanLiteral", "$$ = $1;" ],
51
+ [ "JSONString", "$$ = $1;" ],
52
+ [ "JSONNumber", "$$ = $1;" ],
53
+ [ "JSONObject", "$$ = $1;" ],
54
+ [ "JSONArray", "$$ = $1;" ]],
55
+
56
+ "JSONObject": [[ "{ }", "$$ = {};" ],
57
+ [ "{ JSONMemberList }", "$$ = $2;" ]],
58
+
59
+ "JSONMember": [[ "JSONString : JSONValue", "$$ = [$1, $3];" ]],
60
+
61
+ "JSONMemberList": [[ "JSONMember", "$$ = {}; $$[$1[0]] = $1[1];" ],
62
+ [ "JSONMemberList , JSONMember", "$$ = $1; $1[$3[0]] = $3[1];" ]],
63
+
64
+ "JSONArray": [[ "[ ]", "$$ = [];" ],
65
+ [ "[ JSONElementList ]", "$$ = $2;" ]],
66
+
67
+ "JSONElementList": [[ "JSONValue", "$$ = [$1];" ],
68
+ [ "JSONElementList , JSONValue", "$$ = $1; $1.push($3);" ]]
69
+ }
70
+ };
71
+
72
+ var options = {type: "slr", moduleType: "commonjs", moduleName: "jsonparse"};
73
+
74
+ exports.main = function main (args) {
75
+ var cwd = fs.path(fs.cwd()),
76
+ code = new Generator(exports.grammar, options).generate(),
77
+ stream = cwd.join(options.moduleName+".js").open("w");
78
+ stream.print(code).close();
79
+ };
80
+
81
+ if (require.main === module)
82
+ exports.main(system.args);
83
+
@@ -0,0 +1,26 @@
1
+ {
2
+ "comment": "Grammar showing precedence operators and semantic actions.",
3
+
4
+ "lex": {
5
+ "rules": [
6
+ ["\\s+", "/* skip whitespace */"],
7
+ ["[0-9]+", "return 'NAT';"],
8
+ ["\\+", "return '+';"],
9
+ ["\\*", "return '*';"],
10
+ ["$", "return 'EOF';"]
11
+ ]
12
+ },
13
+
14
+ "tokens": "NAT + * EOF",
15
+ "operators": [
16
+ ["left", "+"],
17
+ ["left", "*"]
18
+ ],
19
+ "bnf": {
20
+ "S" :[[ "e EOF", "return $1;" ]],
21
+ "e" :[[ "e + e", "$$ = [$1,'+', $3];" ],
22
+ [ "e * e", "$$ = [$1, '*', $3];" ],
23
+ [ "NAT", "$$ = parseInt(yytext);" ]]
24
+ }
25
+ }
26
+
@@ -0,0 +1,13 @@
1
+ {
2
+ "comment": "Produces a reduce-reduce conflict unless using LR(1).",
3
+ "tokens": "z d b c a",
4
+ "start": "S",
5
+ "bnf": {
6
+ "S" :[ "a A c",
7
+ "a B d",
8
+ "b A d",
9
+ "b B c"],
10
+ "A" :[ "z" ],
11
+ "B" :[ "z" ]
12
+ }
13
+ }
@@ -0,0 +1,43 @@
1
+ if (typeof require !== 'undefined') {
2
+ var bnf = require("./util/bnf-parser").parser;
3
+ exports.parse = function parse () { return bnf.parse.apply(bnf, arguments) };
4
+ }
5
+
6
+ // adds a declaration to the grammar
7
+ bnf.yy.addDeclaration = function (grammar, decl) {
8
+ if (decl.start) {
9
+ grammar.start = decl.start
10
+ }
11
+ if (decl.operator) {
12
+ if (!grammar.operators) {
13
+ grammar.operators = [];
14
+ }
15
+ grammar.operators.push(decl.operator);
16
+ }
17
+
18
+ };
19
+
20
+ // helps tokenize comments
21
+ bnf.yy.lexComment = function (lexer) {
22
+ var ch = lexer.input();
23
+ if (ch === '/') {
24
+ lexer.yytext = lexer.yytext.replace(/\*(.|\s)\/\*/, '*$1');
25
+ return;
26
+ } else {
27
+ lexer.unput('/*');
28
+ lexer.more();
29
+ }
30
+ }
31
+
32
+ // helps tokenize actions
33
+ bnf.yy.lexAction = function (lexer) {
34
+ var ch = lexer.input();
35
+ if (ch === '}') {
36
+ lexer.yytext = lexer.yytext.substr(2, lexer.yyleng-4).replace(/\}(.|\s)\{\{/, '}$1');
37
+ return 'ACTION';
38
+ } else {
39
+ lexer.unput('{{');
40
+ lexer.more();
41
+ }
42
+ }
43
+
@@ -0,0 +1,18 @@
1
+ if (typeof require !== 'undefined') {
2
+ var jisonlex = require("./util/lex-parser").parser;
3
+ exports.parse = function parse () {
4
+ jisonlex.yy.ruleSection = false;
5
+ return jisonlex.parse.apply(jisonlex, arguments);
6
+ };
7
+ }
8
+
9
+ function encodeRE (s) { return s.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); }
10
+
11
+ jisonlex.yy = {
12
+ prepareString: function (s) {
13
+ // unescape slashes
14
+ s = s.replace(/\\\\/g, "\\");
15
+ s = encodeRE(s);
16
+ return s;
17
+ }
18
+ };
@@ -0,0 +1,146 @@
1
+ // converts json grammar format to Jison grammar format
2
+
3
+ function json2jison (grammar) {
4
+ var s = "";
5
+
6
+ s += genDecls(grammar);
7
+ s += genBNF(grammar.bnf);
8
+
9
+ return s;
10
+ }
11
+
12
+ function genDecls (grammar) {
13
+ var s = "",
14
+ key;
15
+
16
+ for (key in grammar) if (grammar.hasOwnProperty(key)) {
17
+ if (key === 'start') {
18
+ s += "\n%start "+grammar.start+"\n\n";
19
+ }
20
+ if (key === 'author') {
21
+ s += "\n/* author: "+grammar.author+" */\n\n";
22
+ }
23
+ if (key === 'comment') {
24
+ s += "\n/* description: "+grammar.comment+" */\n\n";
25
+ }
26
+ if (key === 'operators') {
27
+ for (var i=0; i<grammar.operators.length; i++) {
28
+ s += "%"+grammar.operators[i][0]+' '+quoteSymbols(grammar.operators[i].slice(1).join(' '))+"\n";
29
+ }
30
+ s += "\n";
31
+ }
32
+ }
33
+
34
+ return s;
35
+ }
36
+
37
+ function genBNF (bnf) {
38
+ var s = "%%\n",
39
+ sym;
40
+
41
+ for (sym in bnf) if (bnf.hasOwnProperty(sym)) {
42
+ s += ["\n",sym,'\n : ', genHandles(bnf[sym]),"\n ;\n"].join("");
43
+ }
44
+
45
+ return s;
46
+ }
47
+
48
+ function genHandles (handle) {
49
+ if (typeof handle === 'string') {
50
+ return handle;
51
+ } else { //array
52
+ var s = "";
53
+ for (var i=0; i< handle.length;i++) {
54
+ if (typeof handle[i] === 'string' && handle[i]) {
55
+ s += quoteSymbols(handle[i]);
56
+ } else if (handle[i] instanceof Array) {
57
+ s += (handle[i][0] && quoteSymbols(handle[i][0]));
58
+ if (typeof handle[i][1] === 'string') {
59
+ s += handle[i][1].match(/\}/) ?
60
+ "\n {{"+handle[i][1]+(handle[i][1].match(/\}$/) ? ' ' : '')+"}}" :
61
+ "\n {"+handle[i][1]+"}";
62
+ if (handle[i][2] && handle[i][2].prec) {
63
+ s += " %prec "+handle[i][2].prec;
64
+ }
65
+ } else if (handle[i][1].prec) {
66
+ s += " %prec "+handle[i][1].prec;
67
+ }
68
+ }
69
+ if (typeof handle[i+1] !== 'undefined')
70
+ s += "\n | ";
71
+ }
72
+ return s;
73
+ }
74
+ }
75
+
76
+ function quoteSymbols (rhs) {
77
+ rhs = rhs.split(' ');
78
+
79
+ for (var i=0; i<rhs.length; i++) {
80
+ rhs[i] = quoteSymbol(rhs[i]);
81
+ }
82
+ return rhs.join(' ');
83
+ }
84
+
85
+ function quoteSymbol (sym) {
86
+ if (!/[a-zA-Z][a-zA-Z0-9_-]*/.test(sym)) {
87
+ var quote = /'/.test(sym) ? '"' : "'";
88
+ sym = quote+sym+quote;
89
+ }
90
+ return sym;
91
+ }
92
+
93
+
94
+ // Generate lex format from lex JSON
95
+
96
+ function genLex (lex) {
97
+ var s = [];
98
+
99
+ if (lex.macros) {
100
+ for (var macro;macro=lex.macros.shift();) {
101
+ s.push(macro[0], '\t\t', macros[1], '\n');
102
+ }
103
+ }
104
+ if (lex.actionInclude) {
105
+ s.push('\n%{\n', lex.actionInclude, '\n%}\n');
106
+ }
107
+ s.push('\n%%\n');
108
+ if (lex.rules) {
109
+ for (var rule;rule=lex.rules.shift();) {
110
+ s.push(rule[0], ' ', genLexRule(rule[1]), '\n');
111
+ }
112
+ }
113
+ s.push('\n%%\n');
114
+
115
+ return s.join('');
116
+ }
117
+
118
+ function genLexRule (rule) {
119
+ return rule.match(/\\}/) ? '%{'+rule+'}%' : '{'+rule+'}';
120
+ }
121
+
122
+ exports.json2jison = json2jison;
123
+ exports.convert = json2jison;
124
+
125
+ exports.main = function main (args) {
126
+ var fs = require("file");
127
+ gfile = fs.path(fs.cwd()).join(args[1]),
128
+ grammar = JSON.parse(gfile.read({charset: "utf-8"}));
129
+
130
+ if (grammar.bnf) {
131
+ var fname = fs.path(fs.cwd()).join(gfile.basename(".json") + ".jison"),
132
+ stream = fname.open("w");
133
+ stream.print(json2jison(grammar));
134
+ stream.close();
135
+ }
136
+
137
+ var lex = grammar.lex || grammar.rules && grammar;
138
+
139
+ if (lex) {
140
+ var fname = fs.path(fs.cwd()).join(gfile.basename(".json").replace(/[._]?lex$/,'') + ".jisonlex"),
141
+ stream = fname.open("w");
142
+ stream.print(genLex(lex));
143
+ stream.close();
144
+ }
145
+ };
146
+