PageRenderTime 71ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/xhp/xhp.hpp

http://github.com/facebook/xhp
C++ Header | 101 lines | 76 code | 9 blank | 16 comment | 0 complexity | 546a50cd54fd15e68b62b30da2f4b0a2 MD5 | raw file
Possible License(s): MIT, MPL-2.0-no-copyleft-exception
  1. /*
  2. +----------------------------------------------------------------------+
  3. | XHP |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2009 - 2010 Facebook, Inc. (http://www.facebook.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE.PHP, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. */
  16. #pragma once
  17. #include <stdint.h>
  18. #include <deque>
  19. #include <stack>
  20. #include <string>
  21. #include "code_rope.hpp"
  22. class yy_extra_type {
  23. public:
  24. yy_extra_type() {
  25. lineno = 1;
  26. terminated = false;
  27. used = false;
  28. short_tags = true;
  29. asp_tags = false;
  30. idx_expr = false;
  31. include_debug = false;
  32. has_doc_block = false;
  33. emit_namespaces = false;
  34. expecting_xhp_class_statements = false;
  35. pushStack();
  36. }
  37. bool short_tags; // `short_open_tag` in php.ini
  38. bool asp_tags; // `asp_tags` in php.ini
  39. bool idx_expr; // allow code like `foo()['bar']`
  40. bool include_debug; // include line numbers and file names in XHP object creation
  41. bool emit_namespaces; // put everything in the global namespace (php 5.3+)
  42. size_t first_lineno; // line number before scanning the current token
  43. size_t lineno; // current line number being scanned.
  44. std::string error; // description of error (if terminated true)
  45. bool terminated; // becomes true when the parser terminates with an error
  46. bool used; // were any XHP-specific extensions found in this code?
  47. int last_token; // the last token to be returned by the scanner
  48. int insert_token; // insert this token without reading from buffer
  49. size_t heredoc_yyleng; // last length of yytext while scannling
  50. const char* heredoc_data; // where our heredoc data starts
  51. std::string heredoc_label; // heredoc sentinel label
  52. code_rope doc_block; // last docblock to be scanned
  53. bool has_doc_block; // is there a scanned docblock that needs to inserted?
  54. std::stack<int> curly_stack; // tokens appearing before a {
  55. bool expecting_xhp_class_statements; // when we're one level deep in a class
  56. bool old_expecting_xhp_class_statements; // store old value while inside class method
  57. bool used_attributes; // did this class use the `attribute` keyword
  58. code_rope attribute_decls; // array keys and values for __xhpAttributeDescription
  59. code_rope attribute_inherit; // from which classes this class should inherit attributes
  60. /* Utility functions for checking proper tag closing */
  61. bool haveTag() {
  62. return !tag_stack.front().empty();
  63. }
  64. const std::string &peekTag() {
  65. return tag_stack.front().front();
  66. }
  67. void pushTag(const std::string &tag) {
  68. tag_stack.front().push_front(tag);
  69. }
  70. void popTag() {
  71. tag_stack.front().pop_front();
  72. }
  73. void pushStack() {
  74. tag_stack.push_front(std::deque<std::string>());
  75. }
  76. void popStack() {
  77. tag_stack.pop_front();
  78. }
  79. protected:
  80. std::deque<std::deque<std::string> > tag_stack;
  81. };
  82. #define YYSTYPE code_rope
  83. #define YY_HEADER_EXPORT_START_CONDITIONS
  84. #define YY_EXTRA_TYPE yy_extra_type*
  85. #include "parser.yacc.hpp"
  86. #ifndef FLEX_SCANNER
  87. #include "scanner.lex.hpp"
  88. #endif
  89. int xhpparse(void*, code_rope*);
  90. void xhp_new_push_state(int s, struct yyguts_t* yyg);
  91. void xhp_new_pop_state(struct yyguts_t* yyg);
  92. void xhp_set_state(int s, struct yyguts_t* yyg);