guard-mthaml 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (341) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +34 -0
  3. data/lib/guard/mthaml.rb +140 -0
  4. data/lib/guard/mthaml/compiler/MtHaml.php +255 -0
  5. data/lib/guard/mthaml/templates/Guardfile +12 -0
  6. data/lib/guard/mthaml/version.rb +5 -0
  7. data/vendor/autoload.php +7 -0
  8. data/vendor/coffeescript/coffeescript/LICENSE +22 -0
  9. data/vendor/coffeescript/coffeescript/README.md +96 -0
  10. data/vendor/coffeescript/coffeescript/composer.json +23 -0
  11. data/vendor/coffeescript/coffeescript/grammar.y +309 -0
  12. data/vendor/coffeescript/coffeescript/make.php +115 -0
  13. data/vendor/coffeescript/coffeescript/src/CoffeeScript/Compiler.php +76 -0
  14. data/vendor/coffeescript/coffeescript/src/CoffeeScript/Error.php +15 -0
  15. data/vendor/coffeescript/coffeescript/src/CoffeeScript/Helpers.php +116 -0
  16. data/vendor/coffeescript/coffeescript/src/CoffeeScript/Init.php +96 -0
  17. data/vendor/coffeescript/coffeescript/src/CoffeeScript/Lexer.php +1356 -0
  18. data/vendor/coffeescript/coffeescript/src/CoffeeScript/Nodes.php +105 -0
  19. data/vendor/coffeescript/coffeescript/src/CoffeeScript/Parser.php +3326 -0
  20. data/vendor/coffeescript/coffeescript/src/CoffeeScript/Rewriter.php +552 -0
  21. data/vendor/coffeescript/coffeescript/src/CoffeeScript/Scope.php +196 -0
  22. data/vendor/coffeescript/coffeescript/src/CoffeeScript/SyntaxError.php +9 -0
  23. data/vendor/coffeescript/coffeescript/src/CoffeeScript/Value.php +20 -0
  24. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Access.php +31 -0
  25. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Arr.php +69 -0
  26. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Assign.php +353 -0
  27. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Base.php +288 -0
  28. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Block.php +294 -0
  29. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Call.php +283 -0
  30. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Class.php +282 -0
  31. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Closure.php +49 -0
  32. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Code.php +203 -0
  33. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Comment.php +39 -0
  34. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Existence.php +42 -0
  35. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Extends.php +26 -0
  36. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/For.php +250 -0
  37. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/If.php +161 -0
  38. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/In.php +99 -0
  39. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Index.php +27 -0
  40. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Literal.php +96 -0
  41. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Obj.php +126 -0
  42. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Op.php +292 -0
  43. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Param.php +119 -0
  44. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Parens.php +45 -0
  45. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Range.php +225 -0
  46. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Return.php +56 -0
  47. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Slice.php +47 -0
  48. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Splat.php +100 -0
  49. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Switch.php +121 -0
  50. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Throw.php +37 -0
  51. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Try.php +79 -0
  52. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Value.php +210 -0
  53. data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/While.php +112 -0
  54. data/vendor/coffeescript/coffeescript/tests/cases/arrays.coffee +77 -0
  55. data/vendor/coffeescript/coffeescript/tests/cases/assignment.coffee +352 -0
  56. data/vendor/coffeescript/coffeescript/tests/cases/booleans.coffee +21 -0
  57. data/vendor/coffeescript/coffeescript/tests/cases/classes.coffee +681 -0
  58. data/vendor/coffeescript/coffeescript/tests/cases/comments.coffee +207 -0
  59. data/vendor/coffeescript/coffeescript/tests/cases/compilation.coffee +72 -0
  60. data/vendor/coffeescript/coffeescript/tests/cases/comprehensions.coffee +501 -0
  61. data/vendor/coffeescript/coffeescript/tests/cases/control_flow.coffee +430 -0
  62. data/vendor/coffeescript/coffeescript/tests/cases/eval.coffee +29 -0
  63. data/vendor/coffeescript/coffeescript/tests/cases/exception_handling.coffee +102 -0
  64. data/vendor/coffeescript/coffeescript/tests/cases/formatting.coffee +146 -0
  65. data/vendor/coffeescript/coffeescript/tests/cases/function_invocation.coffee +552 -0
  66. data/vendor/coffeescript/coffeescript/tests/cases/functions.coffee +188 -0
  67. data/vendor/coffeescript/coffeescript/tests/cases/helpers.coffee +96 -0
  68. data/vendor/coffeescript/coffeescript/tests/cases/importing.coffee +18 -0
  69. data/vendor/coffeescript/coffeescript/tests/cases/interpolation.coffee +138 -0
  70. data/vendor/coffeescript/coffeescript/tests/cases/javascript_literals.coffee +10 -0
  71. data/vendor/coffeescript/coffeescript/tests/cases/numbers.coffee +76 -0
  72. data/vendor/coffeescript/coffeescript/tests/cases/objects.coffee +271 -0
  73. data/vendor/coffeescript/coffeescript/tests/cases/operators.coffee +277 -0
  74. data/vendor/coffeescript/coffeescript/tests/cases/option_parser.coffee +43 -0
  75. data/vendor/coffeescript/coffeescript/tests/cases/ranges.coffee +88 -0
  76. data/vendor/coffeescript/coffeescript/tests/cases/regexps.coffee +63 -0
  77. data/vendor/coffeescript/coffeescript/tests/cases/scope.coffee +43 -0
  78. data/vendor/coffeescript/coffeescript/tests/cases/slicing_and_splicing.coffee +143 -0
  79. data/vendor/coffeescript/coffeescript/tests/cases/soaks.coffee +134 -0
  80. data/vendor/coffeescript/coffeescript/tests/cases/strict.coffee +155 -0
  81. data/vendor/coffeescript/coffeescript/tests/cases/strings.coffee +107 -0
  82. data/vendor/coffeescript/coffeescript/tests/css/style.css +43 -0
  83. data/vendor/coffeescript/coffeescript/tests/index.php +119 -0
  84. data/vendor/coffeescript/coffeescript/tests/js/lib/coffeescript_1.1.1.js +8 -0
  85. data/vendor/coffeescript/coffeescript/tests/js/lib/coffeescript_1.2.0.js +8 -0
  86. data/vendor/coffeescript/coffeescript/tests/js/lib/coffeescript_1.3.0.js +8 -0
  87. data/vendor/coffeescript/coffeescript/tests/js/lib/coffeescript_1.3.1.js +8 -0
  88. data/vendor/coffeescript/coffeescript/tests/js/lib/diff.js +276 -0
  89. data/vendor/coffeescript/coffeescript/tests/js/main.js +123 -0
  90. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/LICENSE.txt +10 -0
  91. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/Lempar.php +948 -0
  92. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/Action.php +257 -0
  93. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/ActionTable.php +299 -0
  94. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/Config.php +574 -0
  95. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/Data.php +1857 -0
  96. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/Parser.php +851 -0
  97. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/PropagationLink.php +126 -0
  98. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/Rule.php +144 -0
  99. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/State.php +283 -0
  100. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/Symbol.php +288 -0
  101. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/cli.php +5 -0
  102. data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/ParserGenerator.php +811 -0
  103. data/vendor/composer/ClassLoader.php +383 -0
  104. data/vendor/composer/autoload_classmap.php +9 -0
  105. data/vendor/composer/autoload_namespaces.php +12 -0
  106. data/vendor/composer/autoload_psr4.php +10 -0
  107. data/vendor/composer/autoload_real.php +50 -0
  108. data/vendor/composer/installed.json +166 -0
  109. data/vendor/michelf/php-markdown/License.md +36 -0
  110. data/vendor/michelf/php-markdown/Michelf/Markdown.inc.php +10 -0
  111. data/vendor/michelf/php-markdown/Michelf/Markdown.php +3117 -0
  112. data/vendor/michelf/php-markdown/Michelf/MarkdownExtra.inc.php +11 -0
  113. data/vendor/michelf/php-markdown/Michelf/MarkdownExtra.php +38 -0
  114. data/vendor/michelf/php-markdown/Michelf/MarkdownInterface.inc.php +9 -0
  115. data/vendor/michelf/php-markdown/Michelf/MarkdownInterface.php +37 -0
  116. data/vendor/michelf/php-markdown/Readme.md +305 -0
  117. data/vendor/michelf/php-markdown/Readme.php +31 -0
  118. data/vendor/michelf/php-markdown/composer.json +31 -0
  119. data/vendor/mthaml/mthaml/CHANGELOG +48 -0
  120. data/vendor/mthaml/mthaml/LICENSE +44 -0
  121. data/vendor/mthaml/mthaml/README.markdown +262 -0
  122. data/vendor/mthaml/mthaml/composer.json +45 -0
  123. data/vendor/mthaml/mthaml/docs/Makefile +153 -0
  124. data/vendor/mthaml/mthaml/docs/_static/mthaml.css +30 -0
  125. data/vendor/mthaml/mthaml/docs/_theme/mthaml/theme.conf +4 -0
  126. data/vendor/mthaml/mthaml/docs/conf.py +242 -0
  127. data/vendor/mthaml/mthaml/docs/index.rst +18 -0
  128. data/vendor/mthaml/mthaml/docs/twig-syntax.rst +274 -0
  129. data/vendor/mthaml/mthaml/examples/README.md +5 -0
  130. data/vendor/mthaml/mthaml/examples/autoload.php +8 -0
  131. data/vendor/mthaml/mthaml/examples/example-php.haml +5 -0
  132. data/vendor/mthaml/mthaml/examples/example-php.php +37 -0
  133. data/vendor/mthaml/mthaml/examples/example-twig-noext.twig +11 -0
  134. data/vendor/mthaml/mthaml/examples/example-twig.haml +9 -0
  135. data/vendor/mthaml/mthaml/examples/example-twig.php +60 -0
  136. data/vendor/mthaml/mthaml/examples/example.twig.haml +8 -0
  137. data/vendor/mthaml/mthaml/lib/MtHaml/Autoloader.php +22 -0
  138. data/vendor/mthaml/mthaml/lib/MtHaml/Environment.php +178 -0
  139. data/vendor/mthaml/mthaml/lib/MtHaml/Escaping.php +33 -0
  140. data/vendor/mthaml/mthaml/lib/MtHaml/Exception.php +9 -0
  141. data/vendor/mthaml/mthaml/lib/MtHaml/Exception/SyntaxErrorException.php +9 -0
  142. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/AbstractFilter.php +43 -0
  143. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Cdata.php +16 -0
  144. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/CoffeeScript.php +33 -0
  145. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Css.php +26 -0
  146. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Escaped.php +22 -0
  147. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/FilterInterface.php +15 -0
  148. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Javascript.php +26 -0
  149. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Less.php +27 -0
  150. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Less/LeafoLess.php +20 -0
  151. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Less/OyejorgeLess.php +23 -0
  152. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Markdown.php +58 -0
  153. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Markdown/CebeMarkdown.php +22 -0
  154. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Markdown/Ciconia.php +21 -0
  155. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Markdown/MichelfMarkdown.php +21 -0
  156. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Markdown/Parsedown.php +21 -0
  157. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Php.php +37 -0
  158. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Plain.php +24 -0
  159. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Preserve.php +19 -0
  160. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Scss.php +37 -0
  161. data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Twig.php +47 -0
  162. data/vendor/mthaml/mthaml/lib/MtHaml/Indentation/Indentation.php +96 -0
  163. data/vendor/mthaml/mthaml/lib/MtHaml/Indentation/IndentationException.php +9 -0
  164. data/vendor/mthaml/mthaml/lib/MtHaml/Indentation/IndentationInterface.php +50 -0
  165. data/vendor/mthaml/mthaml/lib/MtHaml/Indentation/Undefined.php +41 -0
  166. data/vendor/mthaml/mthaml/lib/MtHaml/Node/Comment.php +71 -0
  167. data/vendor/mthaml/mthaml/lib/MtHaml/Node/Doctype.php +96 -0
  168. data/vendor/mthaml/mthaml/lib/MtHaml/Node/EscapableAbstract.php +19 -0
  169. data/vendor/mthaml/mthaml/lib/MtHaml/Node/Filter.php +51 -0
  170. data/vendor/mthaml/mthaml/lib/MtHaml/Node/Insert.php +42 -0
  171. data/vendor/mthaml/mthaml/lib/MtHaml/Node/InterpolatedString.php +73 -0
  172. data/vendor/mthaml/mthaml/lib/MtHaml/Node/NestAbstract.php +117 -0
  173. data/vendor/mthaml/mthaml/lib/MtHaml/Node/NestInterface.php +10 -0
  174. data/vendor/mthaml/mthaml/lib/MtHaml/Node/NodeAbstract.php +77 -0
  175. data/vendor/mthaml/mthaml/lib/MtHaml/Node/ObjectRefClass.php +42 -0
  176. data/vendor/mthaml/mthaml/lib/MtHaml/Node/ObjectRefId.php +42 -0
  177. data/vendor/mthaml/mthaml/lib/MtHaml/Node/Root.php +35 -0
  178. data/vendor/mthaml/mthaml/lib/MtHaml/Node/Run.php +71 -0
  179. data/vendor/mthaml/mthaml/lib/MtHaml/Node/Statement.php +45 -0
  180. data/vendor/mthaml/mthaml/lib/MtHaml/Node/Tag.php +90 -0
  181. data/vendor/mthaml/mthaml/lib/MtHaml/Node/TagAttribute.php +62 -0
  182. data/vendor/mthaml/mthaml/lib/MtHaml/Node/TagAttributeInterpolation.php +24 -0
  183. data/vendor/mthaml/mthaml/lib/MtHaml/Node/TagAttributeList.php +24 -0
  184. data/vendor/mthaml/mthaml/lib/MtHaml/Node/Text.php +37 -0
  185. data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Autoclose.php +25 -0
  186. data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Escaping.php +105 -0
  187. data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/MergeAttrs.php +110 -0
  188. data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Midblock.php +37 -0
  189. data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/NodeVisitorAbstract.php +226 -0
  190. data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/NodeVisitorInterface.php +97 -0
  191. data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/PhpRenderer.php +288 -0
  192. data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Printer.php +265 -0
  193. data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/RendererAbstract.php +581 -0
  194. data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/TwigRenderer.php +252 -0
  195. data/vendor/mthaml/mthaml/lib/MtHaml/Parser.php +862 -0
  196. data/vendor/mthaml/mthaml/lib/MtHaml/Parser/Buffer.php +147 -0
  197. data/vendor/mthaml/mthaml/lib/MtHaml/Runtime.php +218 -0
  198. data/vendor/mthaml/mthaml/lib/MtHaml/Runtime/AttributeInterpolation.php +16 -0
  199. data/vendor/mthaml/mthaml/lib/MtHaml/Runtime/AttributeList.php +16 -0
  200. data/vendor/mthaml/mthaml/lib/MtHaml/Support/Php/Executor.php +157 -0
  201. data/vendor/mthaml/mthaml/lib/MtHaml/Support/Twig/Extension.php +47 -0
  202. data/vendor/mthaml/mthaml/lib/MtHaml/Support/Twig/Lexer.php +48 -0
  203. data/vendor/mthaml/mthaml/lib/MtHaml/Support/Twig/Loader.php +81 -0
  204. data/vendor/mthaml/mthaml/lib/MtHaml/Target/Php.php +23 -0
  205. data/vendor/mthaml/mthaml/lib/MtHaml/Target/TargetAbstract.php +87 -0
  206. data/vendor/mthaml/mthaml/lib/MtHaml/Target/TargetInterface.php +12 -0
  207. data/vendor/mthaml/mthaml/lib/MtHaml/Target/Twig.php +23 -0
  208. data/vendor/mthaml/mthaml/lib/MtHaml/TreeBuilder.php +100 -0
  209. data/vendor/mthaml/mthaml/lib/MtHaml/TreeBuilderException.php +9 -0
  210. data/vendor/mthaml/mthaml/phpunit.xml +25 -0
  211. data/vendor/mthaml/mthaml/test/MtHaml/Tests/EnvironmentTest.php +59 -0
  212. data/vendor/mthaml/mthaml/test/MtHaml/Tests/HamlSpecTest.php +83 -0
  213. data/vendor/mthaml/mthaml/test/MtHaml/Tests/IndentationTest.php +140 -0
  214. data/vendor/mthaml/mthaml/test/MtHaml/Tests/Node/DoctypeTest.php +51 -0
  215. data/vendor/mthaml/mthaml/test/MtHaml/Tests/Node/NodeTest.php +110 -0
  216. data/vendor/mthaml/mthaml/test/MtHaml/Tests/NodeVisitor/PhpRendererTest.php +113 -0
  217. data/vendor/mthaml/mthaml/test/MtHaml/Tests/NodeVisitor/TwigRendererTest.php +68 -0
  218. data/vendor/mthaml/mthaml/test/MtHaml/Tests/NodeVisitorsTest.php +44 -0
  219. data/vendor/mthaml/mthaml/test/MtHaml/Tests/Parser/BufferTest.php +77 -0
  220. data/vendor/mthaml/mthaml/test/MtHaml/Tests/ParserTest.php +47 -0
  221. data/vendor/mthaml/mthaml/test/MtHaml/Tests/RuntimeTest.php +356 -0
  222. data/vendor/mthaml/mthaml/test/MtHaml/Tests/Support/Php/ExecutorTest.php +83 -0
  223. data/vendor/mthaml/mthaml/test/MtHaml/Tests/Support/Twig/LoaderTest.php +65 -0
  224. data/vendor/mthaml/mthaml/test/MtHaml/Tests/TestCase.php +49 -0
  225. data/vendor/mthaml/mthaml/test/MtHaml/Tests/TestCaseTest.php +50 -0
  226. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/Support/Php/Executor.001.haml +1 -0
  227. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/attr_list_php.test +20 -0
  228. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/attr_list_twig.test +12 -0
  229. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/boolean_attr_php.test +16 -0
  230. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/boolean_attr_twig.test +16 -0
  231. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/bug28_php.test +15 -0
  232. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/bug28_twig.test +15 -0
  233. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/bug42.test +13 -0
  234. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/bug8_twig.test +10 -0
  235. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/coffeescript_filter.test +31 -0
  236. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/comments.test +26 -0
  237. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/cond_cmt.test +25 -0
  238. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/doctype.test +18 -0
  239. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/doctype_html4.test +20 -0
  240. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/doctype_invalid.test +12 -0
  241. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/doctype_invalid_xhtml.test +12 -0
  242. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/doctype_php.test +18 -0
  243. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/doctype_xhtml.test +30 -0
  244. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/filters.test +51 -0
  245. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/insert_non_echo_php.test +11 -0
  246. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/insert_non_echo_twig.test +11 -0
  247. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/interpolation_in_html_attrs_php.test +31 -0
  248. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/interpolation_in_html_attrs_twig.test +31 -0
  249. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/less_filter_leafo.test +33 -0
  250. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/less_filter_oyejorge.test +49 -0
  251. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/markdown_filter_cebemarkdown.test +35 -0
  252. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/markdown_filter_ciconia.test +36 -0
  253. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/markdown_filter_michelf.test +34 -0
  254. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/markdown_filter_parsedown.test +31 -0
  255. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/markdown_optimization_filter_michelf.test +23 -0
  256. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/mergeattrs.test +18 -0
  257. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/nuke_inner_whitespace.test +77 -0
  258. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/nuke_outer_whitespace.test +122 -0
  259. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/object_ref_php.test +14 -0
  260. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/object_ref_twig.test +14 -0
  261. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/php.test +109 -0
  262. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/php_autoescaping.test +22 -0
  263. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/php_autoescaping_once.test +25 -0
  264. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/php_blocks.test +29 -0
  265. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/php_filters.test +42 -0
  266. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/scss_filter.test +32 -0
  267. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/strip_inline_comments_php.test +22 -0
  268. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/test.test +24 -0
  269. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/trailing_semicolon_php.test +14 -0
  270. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/try_catch_php.test +17 -0
  271. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/twig.test +112 -0
  272. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/twig_blocks.test +29 -0
  273. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/twig_filters.test +37 -0
  274. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/twig_whitespace.test +32 -0
  275. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/whitespace.test +63 -0
  276. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/autoclose.test +30 -0
  277. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/escaping.test +52 -0
  278. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/escaping_attr_once.test +52 -0
  279. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/escaping_html_false.test +52 -0
  280. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/mergeattrs.test +26 -0
  281. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/midblock.test +54 -0
  282. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/midblock_002.test +32 -0
  283. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/attr_list.test +14 -0
  284. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/attrs.test +42 -0
  285. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/attrs_002.test +35 -0
  286. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/attrs_003.test +30 -0
  287. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/attrs_html_linebreak.test +17 -0
  288. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/blocks.test +27 -0
  289. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/blocks_002.test +15 -0
  290. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/boolean_attr.test +19 -0
  291. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/bug28.test +15 -0
  292. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/bug8.test +11 -0
  293. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/cond_cmt.test +23 -0
  294. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/doctype.test +11 -0
  295. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/double_equal.test +7 -0
  296. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/empty_line_after_multiline.test +10 -0
  297. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_001.test +8 -0
  298. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_002.test +8 -0
  299. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_003.test +8 -0
  300. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_004.test +6 -0
  301. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_005.test +5 -0
  302. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_006.test +7 -0
  303. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_007.test +7 -0
  304. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_008.test +7 -0
  305. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_009.test +5 -0
  306. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_010.test +5 -0
  307. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_013.test +5 -0
  308. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_016.test +7 -0
  309. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_017.test +8 -0
  310. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_018.test +6 -0
  311. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_019.test +6 -0
  312. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_020.test +5 -0
  313. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/filters.test +20 -0
  314. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/filters_002.test +19 -0
  315. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/filters_003.test +13 -0
  316. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/filters_004.test +21 -0
  317. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/filters_005.test +22 -0
  318. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/filters_006.test +23 -0
  319. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/insertflags.test +17 -0
  320. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/interpolation.test +36 -0
  321. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/interpolation_in_html_attrs.test +17 -0
  322. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/multiline.test +18 -0
  323. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/multiline_code.test +59 -0
  324. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/multiple_attr_kinds.test +47 -0
  325. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/non_rendered_comment.test +31 -0
  326. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/ns.test +11 -0
  327. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/object_ref.test +22 -0
  328. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/object_ref_error1.test +5 -0
  329. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/object_ref_error2.test +5 -0
  330. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/quotes_in_haml.test +10 -0
  331. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/ruby19_attrs.test +11 -0
  332. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/ruby_attrs_comma.test +23 -0
  333. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/ruby_attrs_comma_errors_001.test +5 -0
  334. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/ruby_attrs_comma_errors_002.test +5 -0
  335. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/ruby_attrs_comma_errors_003.test +5 -0
  336. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/standard.test +114 -0
  337. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/tagflags.test +39 -0
  338. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/runtime/php_filters.test +28 -0
  339. data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/runtime/twig_filters.test +31 -0
  340. data/vendor/mthaml/mthaml/test/bootstrap.php +3 -0
  341. metadata +398 -0
@@ -0,0 +1,288 @@
1
+ <?php
2
+ /**
3
+ * PHP_ParserGenerator, a php 5 parser generator.
4
+ *
5
+ * This is a direct port of the Lemon parser generator, found at
6
+ * {@link http://www.hwaci.com/sw/lemon/}
7
+ *
8
+ * PHP version 5
9
+ *
10
+ * LICENSE:
11
+ *
12
+ * Copyright (c) 2006, Gregory Beaver <cellog@php.net>
13
+ * All rights reserved.
14
+ *
15
+ * Redistribution and use in source and binary forms, with or without
16
+ * modification, are permitted provided that the following conditions
17
+ * are met:
18
+ *
19
+ * * Redistributions of source code must retain the above copyright
20
+ * notice, this list of conditions and the following disclaimer.
21
+ * * Redistributions in binary form must reproduce the above copyright
22
+ * notice, this list of conditions and the following disclaimer in
23
+ * the documentation and/or other materials provided with the distribution.
24
+ * * Neither the name of the PHP_ParserGenerator nor the names of its
25
+ * contributors may be used to endorse or promote products derived
26
+ * from this software without specific prior written permission.
27
+ *
28
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
29
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
32
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
35
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
36
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
37
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
+ *
40
+ * @category PHP
41
+ * @package PHP_ParserGenerator
42
+ * @author Gregory Beaver <cellog@php.net>
43
+ * @copyright 2006 Gregory Beaver
44
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
45
+ * @version CVS: $Id: Symbol.php 302382 2010-08-17 06:08:09Z jespino $
46
+ * @link http://pear.php.net/package/PHP_ParserGenerator
47
+ * @since File available since Release 0.1.0
48
+ */
49
+ /**
50
+ * Symbols (terminals and nonterminals) of the grammar are stored in this class
51
+ *
52
+ * @category PHP
53
+ * @package PHP_ParserGenerator
54
+ * @author Gregory Beaver <cellog@php.net>
55
+ * @copyright 2006 Gregory Beaver
56
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
57
+ * @version Release: @package_version@
58
+ * @link http://pear.php.net/package/PHP_ParserGenerator
59
+ * @since Class available since Release 0.1.0
60
+ */
61
+ class PHP_ParserGenerator_Symbol
62
+ {
63
+ /**
64
+ * Symbols that start with a capital letter like FOO.
65
+ *
66
+ * These are tokens directly from the lexer
67
+ */
68
+ const TERMINAL = 1;
69
+ /**
70
+ * Symbols that start with a lower-case letter like foo.
71
+ *
72
+ * These are grammar rules like "foo ::= BLAH."
73
+ */
74
+ const NONTERMINAL = 2;
75
+ /**
76
+ * Multiple terminal symbols.
77
+ *
78
+ * These are a grammar rule that consists of several terminals like
79
+ * FOO|BAR|BAZ. Note that non-terminals cannot be in a multi-terminal,
80
+ * and a multi-terminal acts like a single terminal.
81
+ *
82
+ * "FOO|BAR FOO|BAZ" is actually two multi-terminals, FOO|BAR and FOO|BAZ.
83
+ */
84
+ const MULTITERMINAL = 3;
85
+
86
+ const LEFT = 1;
87
+ const RIGHT = 2;
88
+ const NONE = 3;
89
+ const UNK = 4;
90
+ /**
91
+ * Name of the symbol
92
+ *
93
+ * @var string
94
+ */
95
+ public $name;
96
+ /**
97
+ * Index of this symbol.
98
+ *
99
+ * This will ultimately end up representing the symbol in the generated
100
+ * parser
101
+ * @var int
102
+ */
103
+ public $index;
104
+ /**
105
+ * Symbol type
106
+ *
107
+ * One of PHP_ParserGenerator_Symbol::TERMINAL,
108
+ * PHP_ParserGenerator_Symbol::NONTERMINAL or
109
+ * PHP_ParserGenerator_Symbol::MULTITERMINAL
110
+ * @var int
111
+ */
112
+ public $type;
113
+ /**
114
+ * Linked list of rules that use this symbol, if it is a non-terminal.
115
+ * @var PHP_ParserGenerator_Rule
116
+ */
117
+ public $rule;
118
+ /**
119
+ * Fallback token in case this token doesn't parse
120
+ * @var PHP_ParserGenerator_Symbol
121
+ */
122
+ public $fallback;
123
+ /**
124
+ * Precendence, if defined.
125
+ *
126
+ * -1 if no unusual precedence
127
+ * @var int
128
+ */
129
+ public $prec = -1;
130
+ /**
131
+ * Associativity if precedence is defined.
132
+ *
133
+ * One of PHP_ParserGenerator_Symbol::LEFT,
134
+ * PHP_ParserGenerator_Symbol::RIGHT, PHP_ParserGenerator_Symbol::NONE
135
+ * or PHP_ParserGenerator_Symbol::UNK
136
+ * @var unknown_type
137
+ */
138
+ public $assoc;
139
+ /**
140
+ * First-set for all rules of this symbol
141
+ *
142
+ * @var array
143
+ */
144
+ public $firstset;
145
+ /**
146
+ * True if this symbol is a non-terminal and can generate an empty
147
+ * result.
148
+ *
149
+ * For instance "foo ::= ."
150
+ * @var boolean
151
+ */
152
+ public $lambda;
153
+ /**
154
+ * Code that executes whenever this symbol is popped from the stack during
155
+ * error processing.
156
+ *
157
+ * @var string|0
158
+ */
159
+ public $destructor = 0;
160
+ /**
161
+ * Line number of destructor code
162
+ * @var int
163
+ */
164
+ public $destructorln;
165
+ /**
166
+ * Unused relic of the C version of Lemon.
167
+ *
168
+ * The data type of information held by this object. Only used
169
+ * if this is a non-terminal
170
+ * @var string
171
+ */
172
+ public $datatype;
173
+ /**
174
+ * Unused relic of the C version of Lemon.
175
+ *
176
+ * The data type number. In the parser, the value
177
+ * stack is a union. The .yy%d element of this
178
+ * union is the correct data type for this object
179
+ * @var string
180
+ */
181
+ public $dtnum;
182
+ /**#@+
183
+ * The following fields are used by MULTITERMINALs only
184
+ */
185
+ /**
186
+ * Number of terminal symbols in the MULTITERMINAL
187
+ *
188
+ * This is of course the same as count($this->subsym)
189
+ * @var int
190
+ */
191
+ public $nsubsym;
192
+ /**
193
+ * Array of terminal symbols in the MULTITERMINAL
194
+ * @var array an array of {@link PHP_ParserGenerator_Symbol} objects
195
+ */
196
+ public $subsym = array();
197
+ /**#@-*/
198
+ /**
199
+ * Singleton storage of symbols
200
+ *
201
+ * @var array an array of PHP_ParserGenerator_Symbol objects
202
+ */
203
+ private static $_symbol_table = array();
204
+ /**
205
+ * Return a pointer to the (terminal or nonterminal) symbol "x".
206
+ * Create a new symbol if this is the first time "x" has been seen.
207
+ * (this is a singleton)
208
+ * @param string
209
+ * @return PHP_ParserGenerator_Symbol
210
+ */
211
+ public static function Symbol_new($x)
212
+ {
213
+ if (isset(self::$_symbol_table[$x])) {
214
+ return self::$_symbol_table[$x];
215
+ }
216
+ $sp = new PHP_ParserGenerator_Symbol;
217
+ $sp->name = $x;
218
+ $sp->type = preg_match('/[A-Z]/', $x[0]) ? self::TERMINAL : self::NONTERMINAL;
219
+ $sp->rule = 0;
220
+ $sp->fallback = 0;
221
+ $sp->prec = -1;
222
+ $sp->assoc = self::UNK;
223
+ $sp->firstset = array();
224
+ $sp->lambda = false;
225
+ $sp->destructor = 0;
226
+ $sp->datatype = 0;
227
+ self::$_symbol_table[$sp->name] = $sp;
228
+ return $sp;
229
+ }
230
+
231
+ /**
232
+ * Return the number of unique symbols
233
+ *
234
+ * @return int
235
+ */
236
+ public static function Symbol_count()
237
+ {
238
+ return count(self::$_symbol_table);
239
+ }
240
+
241
+ public static function Symbol_arrayof()
242
+ {
243
+ return array_values(self::$_symbol_table);
244
+ }
245
+
246
+ public static function Symbol_find($x)
247
+ {
248
+ if (isset(self::$_symbol_table[$x])) {
249
+ return self::$_symbol_table[$x];
250
+ }
251
+ return 0;
252
+ }
253
+
254
+ /**
255
+ * Sort function helper for symbols
256
+ *
257
+ * Symbols that begin with upper case letters (terminals or tokens)
258
+ * must sort before symbols that begin with lower case letters
259
+ * (non-terminals). Other than that, the order does not matter.
260
+ *
261
+ * We find experimentally that leaving the symbols in their original
262
+ * order (the order they appeared in the grammar file) gives the
263
+ * smallest parser tables in SQLite.
264
+ * @param PHP_ParserGenerator_Symbol
265
+ * @param PHP_ParserGenerator_Symbol
266
+ */
267
+ public static function sortSymbols($a, $b)
268
+ {
269
+ $i1 = $a->index + 10000000*(ord($a->name[0]) > ord('Z'));
270
+ $i2 = $b->index + 10000000*(ord($b->name[0]) > ord('Z'));
271
+ return $i1 - $i2;
272
+ }
273
+
274
+ /**
275
+ * Return true if two symbols are the same.
276
+ */
277
+ public static function same_symbol(PHP_ParserGenerator_Symbol $a, PHP_ParserGenerator_Symbol $b)
278
+ {
279
+ if ($a === $b) return 1;
280
+ if ($a->type != self::MULTITERMINAL) return 0;
281
+ if ($b->type != self::MULTITERMINAL) return 0;
282
+ if ($a->nsubsym != $b->nsubsym) return 0;
283
+ for ($i = 0; $i < $a->nsubsym; $i++) {
284
+ if ($a->subsym[$i] != $b->subsym[$i]) return 0;
285
+ }
286
+ return 1;
287
+ }
288
+ }
@@ -0,0 +1,5 @@
1
+ <?php
2
+ require_once 'PHP/ParserGenerator.php';
3
+ $me = new PHP_ParserGenerator;
4
+ $me->main();
5
+ ?>
@@ -0,0 +1,811 @@
1
+ <?php
2
+ /**
3
+ * PHP_ParserGenerator, a php 5 parser generator.
4
+ *
5
+ * This is a direct port of the Lemon parser generator, found at
6
+ * {@link http://www.hwaci.com/sw/lemon/}
7
+ *
8
+ * There are a few PHP-specific changes to the lemon parser generator.
9
+ *
10
+ * - %extra_argument is removed, as class constructor can be used to
11
+ * pass in extra information
12
+ * - %token_type and company are irrelevant in PHP, and so are removed
13
+ * - %declare_class is added to define the parser class name and any
14
+ * implements/extends information
15
+ * - %include_class is added to allow insertion of extra class information
16
+ * such as constants, a class constructor, etc.
17
+ *
18
+ * Other changes make the parser more robust, and also make reporting
19
+ * syntax errors simpler. Detection of expected tokens eliminates some
20
+ * problematic edge cases where an unexpected token could cause the parser
21
+ * to simply accept input.
22
+ *
23
+ * Otherwise, the file format is identical to the Lemon parser generator
24
+ *
25
+ * PHP version 5
26
+ *
27
+ * LICENSE:
28
+ *
29
+ * Copyright (c) 2006, Gregory Beaver <cellog@php.net>
30
+ * All rights reserved.
31
+ *
32
+ * Redistribution and use in source and binary forms, with or without
33
+ * modification, are permitted provided that the following conditions
34
+ * are met:
35
+ *
36
+ * * Redistributions of source code must retain the above copyright
37
+ * notice, this list of conditions and the following disclaimer.
38
+ * * Redistributions in binary form must reproduce the above copyright
39
+ * notice, this list of conditions and the following disclaimer in
40
+ * the documentation and/or other materials provided with the distribution.
41
+ * * Neither the name of the PHP_ParserGenerator nor the names of its
42
+ * contributors may be used to endorse or promote products derived
43
+ * from this software without specific prior written permission.
44
+ *
45
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
46
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
47
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
49
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
50
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
51
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
52
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
53
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
54
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
55
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
+ *
57
+ * @category PHP
58
+ * @package PHP_ParserGenerator
59
+ * @author Gregory Beaver <cellog@php.net>
60
+ * @copyright 2006 Gregory Beaver
61
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
62
+ * @version CVS: $Id: ParserGenerator.php 302382 2010-08-17 06:08:09Z jespino $
63
+ * @link http://pear.php.net/package/PHP_ParserGenerator
64
+ * @since File available since Release 0.1.0
65
+ */
66
+ /**#@+
67
+ * Basic components of the parser generator
68
+ */
69
+ require_once 'PHP/ParserGenerator/Action.php';
70
+ require_once 'PHP/ParserGenerator/ActionTable.php';
71
+ require_once 'PHP/ParserGenerator/Config.php';
72
+ require_once 'PHP/ParserGenerator/Data.php';
73
+ require_once 'PHP/ParserGenerator/Symbol.php';
74
+ require_once 'PHP/ParserGenerator/Rule.php';
75
+ require_once 'PHP/ParserGenerator/Parser.php';
76
+ require_once 'PHP/ParserGenerator/PropagationLink.php';
77
+ require_once 'PHP/ParserGenerator/State.php';
78
+ /**#@-*/
79
+ /**
80
+ * The basic home class for the parser generator
81
+ *
82
+ * @category PHP
83
+ * @package PHP_ParserGenerator
84
+ * @author Gregory Beaver <cellog@php.net>
85
+ * @copyright 2006 Gregory Beaver
86
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
87
+ * @version Release: @package_version@
88
+ * @link http://pear.php.net/package/PHP_ParserGenerator
89
+ * @since Class available since Release 0.1.0
90
+ * @example Lempar.php
91
+ * @example examples/Parser.y Sample parser file format (PHP_LexerGenerator's parser)
92
+ * @example examples/Parser.php Sample parser file format PHP code (PHP_LexerGenerator's parser)
93
+ */
94
+ class PHP_ParserGenerator
95
+ {
96
+ /**
97
+ * Set this to 1 to turn on debugging of Lemon's parsing of
98
+ * grammar files.
99
+ */
100
+ const DEBUG = 0;
101
+ const MAXRHS = 1000;
102
+ const OPT_FLAG = 1, OPT_INT = 2, OPT_DBL = 3, OPT_STR = 4,
103
+ OPT_FFLAG = 5, OPT_FINT = 6, OPT_FDBL = 7, OPT_FSTR = 8;
104
+ public $azDefine = array();
105
+ private static $_options = array(
106
+ 'b' => array(
107
+ 'type' => self::OPT_FLAG,
108
+ 'arg' => 'basisflag',
109
+ 'message' => 'Print only the basis in report.'
110
+ ),
111
+ 'c' => array(
112
+ 'type' => self::OPT_FLAG,
113
+ 'arg' => 'compress',
114
+ 'message' => 'Don\'t compress the action table.'
115
+ ),
116
+ 'D' => array(
117
+ 'type' => self::OPT_FSTR,
118
+ 'arg' => 'handleDOption',
119
+ 'message' => 'Define an %ifdef macro.'
120
+ ),
121
+ 'g' => array(
122
+ 'type' => self::OPT_FLAG,
123
+ 'arg' => 'rpflag',
124
+ 'message' => 'Print grammar without actions.'
125
+ ),
126
+ 'm' => array(
127
+ 'type' => self::OPT_FLAG,
128
+ 'arg' => 'mhflag',
129
+ 'message' => 'Output a makeheaders compatible file'
130
+ ),
131
+ 'q' => array(
132
+ 'type' => self::OPT_FLAG,
133
+ 'arg' => 'quiet',
134
+ 'message' => '(Quiet) Don\'t print the report file.'
135
+ ),
136
+ 's' => array(
137
+ 'type' => self::OPT_FLAG,
138
+ 'arg' => 'statistics',
139
+ 'message' => 'Print parser stats to standard output.'
140
+ ),
141
+ 'x' => array(
142
+ 'type' => self::OPT_FLAG,
143
+ 'arg' => 'version',
144
+ 'message' => 'Print the version number.'
145
+ ),
146
+ 'T' => array(
147
+ 'type' => self::OPT_STR,
148
+ 'arg' => 'parser_template',
149
+ 'message' => 'Use different parser template file.'
150
+ )
151
+ );
152
+
153
+ private $_basisflag = 0;
154
+ private $_compress = 0;
155
+ private $_rpflag = 0;
156
+ private $_mhflag = 0;
157
+ private $_quiet = 0;
158
+ private $_statistics = 0;
159
+ private $_version = 0;
160
+ private $_size;
161
+ private $_parser_template = "";
162
+
163
+ /**
164
+ * Process a flag command line argument.
165
+ *
166
+ * @param int $i
167
+ * @param array $argv
168
+ *
169
+ * @return int
170
+ */
171
+ function handleflags($i, $argv)
172
+ {
173
+ if (!isset($argv[1]) || !isset(self::$_options[$argv[$i][1]])) {
174
+ throw new Exception('Command line syntax error: undefined option "' . $argv[$i] . '"');
175
+ }
176
+ $v = self::$_options[$argv[$i][1]] == '-';
177
+ if (self::$_options[$argv[$i][1]]['type'] == self::OPT_FLAG) {
178
+ $this->{self::$_options[$argv[$i][1]]['arg']} = 1;
179
+ } elseif (self::$_options[$argv[$i][1]]['type'] == self::OPT_FFLAG) {
180
+ $this->{self::$_options[$argv[$i][1]]['arg']}($v);
181
+ } elseif (self::$_options[$argv[$i][1]]['type'] == self::OPT_FSTR) {
182
+ $this->{self::$_options[$argv[$i][1]]['arg']}(substr($v, 2));
183
+ } else {
184
+ throw new Exception('Command line syntax error: missing argument on switch: "' . $argv[$i] . '"');
185
+ }
186
+ return 0;
187
+ }
188
+
189
+ /**
190
+ * Process a command line switch which has an argument.
191
+ *
192
+ * @param int $i
193
+ * @param array $argv
194
+ *
195
+ * @return int
196
+ */
197
+ function handleswitch($i, $argv)
198
+ {
199
+ $lv = 0;
200
+ $dv = 0.0;
201
+ $sv = $end = $cp = '';
202
+ $j; // int
203
+ $errcnt = 0;
204
+ $cp = strstr($argv[$i], '=');
205
+ if (!$cp) {
206
+ throw new Exception('INTERNAL ERROR: handleswitch passed bad argument, no "=" in arg');
207
+ }
208
+ $argv[$i] = substr($argv[$i], 0, strlen($argv[$i]) - strlen($cp));
209
+ if (!isset(self::$_options[$argv[$i]])) {
210
+ throw new Exception('Command line syntax error: undefined option "' . $argv[$i] .
211
+ $cp . '"');
212
+ }
213
+ $cp = substr($cp, 1);
214
+ switch (self::$_options[$argv[$i]]['type']) {
215
+ case self::OPT_FLAG:
216
+ case self::OPT_FFLAG:
217
+ throw new Exception('Command line syntax error: option requires an argument "' .
218
+ $argv[$i] . '=' . $cp . '"');
219
+ case self::OPT_DBL:
220
+ case self::OPT_FDBL:
221
+ $dv = (double) $cp;
222
+ break;
223
+ case self::OPT_INT:
224
+ case self::OPT_FINT:
225
+ $lv = (int) $cp;
226
+ break;
227
+ case self::OPT_STR:
228
+ case self::OPT_FSTR:
229
+ $sv = $cp;
230
+ break;
231
+ }
232
+ switch(self::$_options[$argv[$i]]['type']) {
233
+ case self::OPT_FLAG:
234
+ case self::OPT_FFLAG:
235
+ break;
236
+ case self::OPT_DBL:
237
+ $this->{self::$_options[$argv[$i]]['arg']} = $dv;
238
+ break;
239
+ case self::OPT_FDBL:
240
+ $this->{self::$_options[$argv[$i]]['arg']}($dv);
241
+ break;
242
+ case self::OPT_INT:
243
+ $this->{self::$_options[$argv[$i]]['arg']} = $lv;
244
+ break;
245
+ case self::OPT_FINT:
246
+ $this->{self::$_options[$argv[$i]]['arg']}($lv);
247
+ break;
248
+ case self::OPT_STR:
249
+ $this->{self::$_options[$argv[$i]]['arg']} = $sv;
250
+ break;
251
+ case self::OPT_FSTR:
252
+ $this->{self::$_options[$argv[$i]]['arg']}($sv);
253
+ break;
254
+ }
255
+ return 0;
256
+ }
257
+
258
+ /**
259
+ * OptInit
260
+ *
261
+ * @param array $a Arguments
262
+ *
263
+ * @return int
264
+ */
265
+ function OptInit($a)
266
+ {
267
+ $errcnt = 0;
268
+ $argv = $a;
269
+ try {
270
+ if (is_array($argv) && count($argv) && self::$_options) {
271
+ for ($i = 1; $i < count($argv); $i++) {
272
+ if ($argv[$i][0] == '+' || $argv[$i][0] == '-') {
273
+ $errcnt += $this->handleflags($i, $argv);
274
+ } elseif (strstr($argv[$i], '=')) {
275
+ $errcnt += $this->handleswitch($i, $argv);
276
+ }
277
+ }
278
+ }
279
+ } catch (Exception $e) {
280
+ $this->OptPrint();
281
+ echo $e->getMessage()."\n";
282
+ //exit(1);
283
+ }
284
+ return 0;
285
+ }
286
+
287
+ /**
288
+ * Return the index of the N-th non-switch argument. Return -1
289
+ * if N is out of range.
290
+ *
291
+ * @param int $n
292
+ * @param int $a
293
+ *
294
+ * @return int
295
+ */
296
+ private function _argindex($n, $a)
297
+ {
298
+ $dashdash = 0;
299
+ if (!is_array($a) || !count($a)) {
300
+ return -1;
301
+ }
302
+ for ($i=1; $i < count($a); $i++) {
303
+ if ($dashdash || !($a[$i][0] == '-' || $a[$i][0] == '+' || strchr($a[$i], '='))) {
304
+ if ($n == 0) {
305
+ return $i;
306
+ }
307
+ $n--;
308
+ }
309
+ if ($_SERVER['argv'][$i] == '--') {
310
+ $dashdash = 1;
311
+ }
312
+ }
313
+ return -1;
314
+ }
315
+
316
+ /**
317
+ * Return the value of the non-option argument as indexed by $i
318
+ *
319
+ * @param int $i
320
+ * @param array $a the value of $argv
321
+ *
322
+ * @return 0|string
323
+ */
324
+ private function _optArg($i, $a)
325
+ {
326
+ if (-1 == ($ind = $this->_argindex($i, $a))) {
327
+ return 0;
328
+ }
329
+ return $a[$ind];
330
+ }
331
+
332
+ /**
333
+ * @param array $a
334
+ *
335
+ * @return int number of arguments
336
+ */
337
+ function OptNArgs($a)
338
+ {
339
+ $cnt = $dashdash = 0;
340
+ if (is_array($a) && count($a)) {
341
+ for ($i = 1; $i < count($a); $i++) {
342
+ if ($dashdash
343
+ || !($a[$i][0] == '-' || $a[$i][0] == '+' || strchr($a[$i], '='))
344
+ ) {
345
+ $cnt++;
346
+ }
347
+ if ($a[$i] == "--") {
348
+ $dashdash = 1;
349
+ }
350
+ }
351
+ }
352
+ return $cnt;
353
+ }
354
+
355
+ /**
356
+ * Print out command-line options
357
+ *
358
+ * @return void
359
+ */
360
+ function OptPrint()
361
+ {
362
+ $max = 0;
363
+ foreach (self::$_options as $label => $info) {
364
+ $len = strlen($label) + 1;
365
+ switch ($info['type']) {
366
+ case self::OPT_FLAG:
367
+ case self::OPT_FFLAG:
368
+ break;
369
+ case self::OPT_INT:
370
+ case self::OPT_FINT:
371
+ $len += 9; /* length of "<integer>" */
372
+ break;
373
+ case self::OPT_DBL:
374
+ case self::OPT_FDBL:
375
+ $len += 6; /* length of "<real>" */
376
+ break;
377
+ case self::OPT_STR:
378
+ case self::OPT_FSTR:
379
+ $len += 8; /* length of "<string>" */
380
+ break;
381
+ }
382
+ if ($len > $max) {
383
+ $max = $len;
384
+ }
385
+ }
386
+ foreach (self::$_options as $label => $info) {
387
+ switch ($info['type']) {
388
+ case self::OPT_FLAG:
389
+ case self::OPT_FFLAG:
390
+ echo " -$label";
391
+ echo str_repeat(' ', $max - strlen($label));
392
+ echo " $info[message]\n";
393
+ break;
394
+ case self::OPT_INT:
395
+ case self::OPT_FINT:
396
+ echo " $label=<integer>" . str_repeat(' ', $max - strlen($label) - 9);
397
+ echo " $info[message]\n";
398
+ break;
399
+ case self::OPT_DBL:
400
+ case self::OPT_FDBL:
401
+ echo " $label=<real>" . str_repeat(' ', $max - strlen($label) - 6);
402
+ echo " $info[message]\n";
403
+ break;
404
+ case self::OPT_STR:
405
+ case self::OPT_FSTR:
406
+ echo " $label=<string>" . str_repeat(' ', $max - strlen($label) - 8);
407
+ echo " $info[message]\n";
408
+ break;
409
+ }
410
+ }
411
+ }
412
+
413
+ /**
414
+ * This routine is called with the argument to each -D command-line option.
415
+ * Add the macro defined to the azDefine array.
416
+ *
417
+ * @param string $z
418
+ *
419
+ * @return void
420
+ */
421
+ private function _handleDOption($z)
422
+ {
423
+ if ($a = strstr($z, '=')) {
424
+ $z = substr($a, 1); // strip first =
425
+ }
426
+ $this->azDefine[] = $z;
427
+ }
428
+
429
+ /**************** From the file "main.c" ************************************/
430
+ /*
431
+ ** Main program file for the LEMON parser generator.
432
+ */
433
+
434
+
435
+ /**
436
+ * The main program. Parse the command line and do it...
437
+ *
438
+ * @return int Number of error and conflicts
439
+ */
440
+ function main()
441
+ {
442
+ $lem = new PHP_ParserGenerator_Data;
443
+
444
+ $this->OptInit($_SERVER['argv']);
445
+ if ($this->_version) {
446
+ echo "Lemon version 1.0/PHP_ParserGenerator port version @package_version@\n";
447
+ //exit(0);
448
+ return;
449
+ }
450
+ if ($this->OptNArgs($_SERVER['argv']) != 1) {
451
+ echo "Exactly one filename argument is required.\n";
452
+ //exit(1);
453
+ return;
454
+ }
455
+ $lem->errorcnt = 0;
456
+ $lem->parser_template = $this->_parser_template;
457
+
458
+ /* Initialize the machine */
459
+ $lem->argv0 = $_SERVER['argv'][0];
460
+ $lem->filename = $this->_optArg(0, $_SERVER['argv']);
461
+ $a = pathinfo($lem->filename);
462
+ if (isset($a['extension'])) {
463
+ $ext = '.' . $a['extension'];
464
+ $lem->filenosuffix = substr($lem->filename, 0, strlen($lem->filename) - strlen($ext));
465
+ } else {
466
+ $lem->filenosuffix = $lem->filename;
467
+ }
468
+ $lem->basisflag = $this->_basisflag;
469
+ $lem->has_fallback = 0;
470
+ $lem->nconflict = 0;
471
+ $lem->name = $lem->include_code = $lem->include_classcode = $lem->arg = $lem->tokentype = $lem->start = 0;
472
+ $lem->vartype = 0;
473
+ $lem->stacksize = 0;
474
+ $lem->error = $lem->overflow = $lem->failure = $lem->accept = $lem->tokendest = $lem->tokenprefix = $lem->outname = $lem->extracode = 0;
475
+ $lem->vardest = 0;
476
+ $lem->tablesize = 0;
477
+ PHP_ParserGenerator_Symbol::Symbol_new("$");
478
+ $lem->errsym = PHP_ParserGenerator_Symbol::Symbol_new("error");
479
+
480
+ /* Parse the input file */
481
+ $parser = new PHP_ParserGenerator_Parser($this);
482
+ $parser->Parse($lem);
483
+ if ($lem->errorcnt) {
484
+ return;
485
+ // exit($lem->errorcnt);
486
+ }
487
+ if ($lem->rule === 0) {
488
+ printf("Empty grammar.\n");
489
+ return;
490
+ //exit(1);
491
+ }
492
+
493
+ /* Count and index the symbols of the grammar */
494
+ $lem->nsymbol = PHP_ParserGenerator_Symbol::Symbol_count();
495
+ PHP_ParserGenerator_Symbol::Symbol_new("{default}");
496
+ $lem->symbols = PHP_ParserGenerator_Symbol::Symbol_arrayof();
497
+ for ($i = 0; $i <= $lem->nsymbol; $i++) {
498
+ $lem->symbols[$i]->index = $i;
499
+ }
500
+ usort($lem->symbols, array('PHP_ParserGenerator_Symbol', 'sortSymbols'));
501
+ for ($i = 0; $i <= $lem->nsymbol; $i++) {
502
+ $lem->symbols[$i]->index = $i;
503
+ }
504
+ // find the first lower-case symbol
505
+ for ($i = 1; ord($lem->symbols[$i]->name[0]) <= ord('Z'); $i++);
506
+ $lem->nterminal = $i;
507
+
508
+ /* Generate a reprint of the grammar, if requested on the command line */
509
+ if ($this->_rpflag) {
510
+ $this->Reprint();
511
+ } else {
512
+ /* Initialize the size for all follow and first sets */
513
+ $this->SetSize($lem->nterminal);
514
+
515
+ /* Find the precedence for every production rule (that has one) */
516
+ $lem->FindRulePrecedences();
517
+
518
+ /* Compute the lambda-nonterminals and the first-sets for every
519
+ ** nonterminal */
520
+ $lem->FindFirstSets();
521
+
522
+ /* Compute all LR(0) states. Also record follow-set propagation
523
+ ** links so that the follow-set can be computed later */
524
+ $lem->nstate = 0;
525
+ $lem->FindStates();
526
+ $lem->sorted = PHP_ParserGenerator_State::State_arrayof();
527
+
528
+ /* Tie up loose ends on the propagation links */
529
+ $lem->FindLinks();
530
+
531
+ /* Compute the follow set of every reducible configuration */
532
+ $lem->FindFollowSets();
533
+
534
+ /* Compute the action tables */
535
+ $lem->FindActions();
536
+
537
+ /* Compress the action tables */
538
+ if ($this->_compress===0) {
539
+ $lem->CompressTables();
540
+ }
541
+
542
+ /* Reorder and renumber the states so that states with fewer choices
543
+ ** occur at the end. */
544
+ $lem->ResortStates();
545
+
546
+ /* Generate a report of the parser generated. (the "y.output" file) */
547
+ if (!$this->_quiet) {
548
+ $lem->ReportOutput();
549
+ }
550
+
551
+ /* Generate the source code for the parser */
552
+ $lem->ReportTable($this->_mhflag);
553
+
554
+ /* Produce a header file for use by the scanner. (This step is
555
+ ** omitted if the "-m" option is used because makeheaders will
556
+ ** generate the file for us.) */
557
+ //if (!$this->_mhflag) {
558
+ // $this->ReportHeader();
559
+ //}
560
+ }
561
+ if ($this->_statistics) {
562
+ printf(
563
+ "Parser statistics: %d terminals, %d nonterminals, %d rules\n",
564
+ $lem->nterminal,
565
+ $lem->nsymbol - $lem->nterminal,
566
+ $lem->nrule
567
+ );
568
+ printf(
569
+ " %d states, %d parser table entries, %d conflicts\n",
570
+ $lem->nstate,
571
+ $lem->tablesize,
572
+ $lem->nconflict
573
+ );
574
+ }
575
+ if ($lem->nconflict) {
576
+ printf("%d parsing conflicts.\n", $lem->nconflict);
577
+ }
578
+ //exit($lem->errorcnt + $lem->nconflict);
579
+ echo $lem->errorcnt + $lem->nconflict;
580
+ return ($lem->errorcnt + $lem->nconflict);
581
+ }
582
+
583
+ /**
584
+ * SetSize
585
+ *
586
+ * @param int $n
587
+ *
588
+ * @access public
589
+ * @return void
590
+ */
591
+ function SetSize($n)
592
+ {
593
+ $this->_size = $n + 1;
594
+ }
595
+
596
+ /**
597
+ * Merge in a merge sort for a linked list
598
+ *
599
+ * Side effects:
600
+ * The "next" pointers for elements in the lists a and b are
601
+ * changed.
602
+ *
603
+ * @param mixed $a A sorted, null-terminated linked list. (May be null).
604
+ * @param mixed $b A sorted, null-terminated linked list. (May be null).
605
+ * @param function $cmp A pointer to the comparison function.
606
+ * @param integer $offset Offset in the structure to the "next" field.
607
+ *
608
+ * @return mixed A pointer to the head of a sorted list containing the
609
+ * elements of both a and b.
610
+ */
611
+ static function merge($a, $b, $cmp, $offset)
612
+ {
613
+ if ($a === 0) {
614
+ $head = $b;
615
+ } elseif ($b === 0) {
616
+ $head = $a;
617
+ } else {
618
+ if (call_user_func($cmp, $a, $b) < 0) {
619
+ $ptr = $a;
620
+ $a = $a->$offset;
621
+ } else {
622
+ $ptr = $b;
623
+ $b = $b->$offset;
624
+ }
625
+ $head = $ptr;
626
+ while ($a && $b) {
627
+ if (call_user_func($cmp, $a, $b) < 0) {
628
+ $ptr->$offset = $a;
629
+ $ptr = $a;
630
+ $a = $a->$offset;
631
+ } else {
632
+ $ptr->$offset = $b;
633
+ $ptr = $b;
634
+ $b = $b->$offset;
635
+ }
636
+ }
637
+ if ($a !== 0) {
638
+ $ptr->$offset = $a;
639
+ } else {
640
+ $ptr->$offset = $b;
641
+ }
642
+ }
643
+ return $head;
644
+ }
645
+
646
+ #define LISTSIZE 30
647
+ /**
648
+ * Side effects:
649
+ * The "next" pointers for elements in list are changed.
650
+ *
651
+ * @param mixed $list Pointer to a singly-linked list of structures.
652
+ * @param mixed $next Pointer to pointer to the second element of the list.
653
+ * @param function $cmp A comparison function.
654
+ *
655
+ * @return mixed A pointer to the head of a sorted list containing the
656
+ * elements orginally in list.
657
+ */
658
+ static function msort($list, $next, $cmp)
659
+ {
660
+ if ($list === 0) {
661
+ return $list;
662
+ }
663
+ if ($list->$next === 0) {
664
+ return $list;
665
+ }
666
+ $set = array_fill(0, 30, 0);
667
+ while ($list) {
668
+ $ep = $list;
669
+ $list = $list->$next;
670
+ $ep->$next = 0;
671
+ for ($i = 0; $i < 29 && $set[$i] !== 0; $i++) {
672
+ $ep = self::merge($ep, $set[$i], $cmp, $next);
673
+ $set[$i] = 0;
674
+ }
675
+ $set[$i] = $ep;
676
+ }
677
+ $ep = 0;
678
+ for ($i = 0; $i < 30; $i++) {
679
+ if ($set[$i] !== 0) {
680
+ $ep = self::merge($ep, $set[$i], $cmp, $next);
681
+ }
682
+ }
683
+ return $ep;
684
+ }
685
+
686
+ /* Find a good place to break "msg" so that its length is at least "min"
687
+ ** but no more than "max". Make the point as close to max as possible.
688
+ */
689
+ static function findbreak($msg, $min, $max)
690
+ {
691
+ if ($min >= strlen($msg)) {
692
+ return strlen($msg);
693
+ }
694
+ for ($i = $spot = $min; $i <= $max && $i < strlen($msg); $i++) {
695
+ $c = $msg[$i];
696
+ if ($c == '-' && $i < $max - 1) {
697
+ $spot = $i + 1;
698
+ }
699
+ if ($c == ' ') {
700
+ $spot = $i;
701
+ }
702
+ }
703
+ return $spot;
704
+ }
705
+
706
+ static function ErrorMsg($filename, $lineno, $format)
707
+ {
708
+ /* Prepare a prefix to be prepended to every output line */
709
+ if ($lineno > 0) {
710
+ $prefix = sprintf("%20s:%d: ", $filename, $lineno);
711
+ } else {
712
+ $prefix = sprintf("%20s: ", $filename);
713
+ }
714
+ $prefixsize = strlen($prefix);
715
+ $availablewidth = 79 - $prefixsize;
716
+
717
+ /* Generate the error message */
718
+ $ap = func_get_args();
719
+ array_shift($ap); // $filename
720
+ array_shift($ap); // $lineno
721
+ array_shift($ap); // $format
722
+ $errmsg = vsprintf($format, $ap);
723
+ $linewidth = strlen($errmsg);
724
+ /* Remove trailing "\n"s from the error message. */
725
+ while ($linewidth > 0
726
+ && in_array($errmsg[$linewidth-1], array("\n", "\r"), true)
727
+ ) {
728
+ --$linewidth;
729
+ $errmsg = substr($errmsg, 0, strlen($errmsg) - 1);
730
+ }
731
+
732
+ /* Print the error message */
733
+ $base = 0;
734
+ $errmsg = str_replace(
735
+ array("\r", "\n", "\t"),
736
+ array(' ', ' ', ' '),
737
+ $errmsg
738
+ );
739
+ while (strlen($errmsg)) {
740
+ $end = $restart = self::findbreak($errmsg, 0, $availablewidth);
741
+ if (strlen($errmsg) <= 79 && $end < strlen($errmsg) && $end <= 79) {
742
+ $end = $restart = strlen($errmsg);
743
+ }
744
+ while (isset($errmsg[$restart]) && $errmsg[$restart] == ' ') {
745
+ $restart++;
746
+ }
747
+ printf("%s%.${end}s\n", $prefix, $errmsg);
748
+ $errmsg = substr($errmsg, $restart);
749
+ }
750
+ }
751
+
752
+ /**
753
+ * Duplicate the input file without comments and without actions
754
+ * on rules
755
+ *
756
+ * @return void
757
+ */
758
+ function Reprint()
759
+ {
760
+ printf("// Reprint of input file \"%s\".\n// Symbols:\n", $this->filename);
761
+ $maxlen = 10;
762
+ for ($i = 0; $i < $this->nsymbol; $i++) {
763
+ $sp = $this->symbols[$i];
764
+ $len = strlen($sp->name);
765
+ if ($len > $maxlen ) {
766
+ $maxlen = $len;
767
+ }
768
+ }
769
+ $ncolumns = 76 / ($maxlen + 5);
770
+ if ($ncolumns < 1) {
771
+ $ncolumns = 1;
772
+ }
773
+ $skip = ($this->nsymbol + $ncolumns - 1) / $ncolumns;
774
+ for ($i = 0; $i < $skip; $i++) {
775
+ print "//";
776
+ for ($j = $i; $j < $this->nsymbol; $j += $skip) {
777
+ $sp = $this->symbols[$j];
778
+ //assert( sp->index==j );
779
+ printf(" %3d %-${maxlen}.${maxlen}s", $j, $sp->name);
780
+ }
781
+ print "\n";
782
+ }
783
+ for ($rp = $this->rule; $rp; $rp = $rp->next) {
784
+ printf("%s", $rp->lhs->name);
785
+ /*if ($rp->lhsalias) {
786
+ printf("(%s)", $rp->lhsalias);
787
+ }*/
788
+ print " ::=";
789
+ for ($i = 0; $i < $rp->nrhs; $i++) {
790
+ $sp = $rp->rhs[$i];
791
+ printf(" %s", $sp->name);
792
+ if ($sp->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) {
793
+ for ($j = 1; $j < $sp->nsubsym; $j++) {
794
+ printf("|%s", $sp->subsym[$j]->name);
795
+ }
796
+ }
797
+ /*if ($rp->rhsalias[$i]) {
798
+ printf("(%s)", $rp->rhsalias[$i]);
799
+ }*/
800
+ }
801
+ print ".";
802
+ if ($rp->precsym) {
803
+ printf(" [%s]", $rp->precsym->name);
804
+ }
805
+ /*if ($rp->code) {
806
+ print "\n " . $rp->code);
807
+ }*/
808
+ print "\n";
809
+ }
810
+ }
811
+ }