A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

114 lines
4.8 KiB

  1. /*
  2. Copyright (C) 2012-2017 Ben Kurtovic <ben.kurtovic@gmail.com>
  3. Permission is hereby granted, free of charge, to any person obtaining a copy of
  4. this software and associated documentation files (the "Software"), to deal in
  5. the Software without restriction, including without limitation the rights to
  6. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  7. of the Software, and to permit persons to whom the Software is furnished to do
  8. so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.
  18. */
  19. #pragma once
  20. /* Local contexts */
  21. #define LC_TEMPLATE 0x0000000000000007
  22. #define LC_TEMPLATE_NAME 0x0000000000000001
  23. #define LC_TEMPLATE_PARAM_KEY 0x0000000000000002
  24. #define LC_TEMPLATE_PARAM_VALUE 0x0000000000000004
  25. #define LC_ARGUMENT 0x0000000000000018
  26. #define LC_ARGUMENT_NAME 0x0000000000000008
  27. #define LC_ARGUMENT_DEFAULT 0x0000000000000010
  28. #define LC_WIKILINK 0x0000000000000060
  29. #define LC_WIKILINK_TITLE 0x0000000000000020
  30. #define LC_WIKILINK_TEXT 0x0000000000000040
  31. #define LC_EXT_LINK 0x0000000000000180
  32. #define LC_EXT_LINK_URI 0x0000000000000080
  33. #define LC_EXT_LINK_TITLE 0x0000000000000100
  34. #define LC_HEADING 0x0000000000007E00
  35. #define LC_HEADING_LEVEL_1 0x0000000000000200
  36. #define LC_HEADING_LEVEL_2 0x0000000000000400
  37. #define LC_HEADING_LEVEL_3 0x0000000000000800
  38. #define LC_HEADING_LEVEL_4 0x0000000000001000
  39. #define LC_HEADING_LEVEL_5 0x0000000000002000
  40. #define LC_HEADING_LEVEL_6 0x0000000000004000
  41. #define LC_TAG 0x0000000000078000
  42. #define LC_TAG_OPEN 0x0000000000008000
  43. #define LC_TAG_ATTR 0x0000000000010000
  44. #define LC_TAG_BODY 0x0000000000020000
  45. #define LC_TAG_CLOSE 0x0000000000040000
  46. #define LC_STYLE 0x0000000000780000
  47. #define LC_STYLE_ITALICS 0x0000000000080000
  48. #define LC_STYLE_BOLD 0x0000000000100000
  49. #define LC_STYLE_PASS_AGAIN 0x0000000000200000
  50. #define LC_STYLE_SECOND_PASS 0x0000000000400000
  51. #define LC_DLTERM 0x0000000000800000
  52. #define LC_SAFETY_CHECK 0x000000007F000000
  53. #define LC_HAS_TEXT 0x0000000001000000
  54. #define LC_FAIL_ON_TEXT 0x0000000002000000
  55. #define LC_FAIL_NEXT 0x0000000004000000
  56. #define LC_FAIL_ON_LBRACE 0x0000000008000000
  57. #define LC_FAIL_ON_RBRACE 0x0000000010000000
  58. #define LC_FAIL_ON_EQUALS 0x0000000020000000
  59. #define LC_HAS_TEMPLATE 0x0000000040000000
  60. #define LC_TABLE 0x0000001F80000000
  61. #define LC_TABLE_CELL_LINE_CONTEXTS 0x0000001A00000000
  62. #define LC_TABLE_OPEN 0x0000000080000000
  63. #define LC_TABLE_CELL_OPEN 0x0000000100000000
  64. #define LC_TABLE_CELL_STYLE 0x0000000200000000
  65. #define LC_TABLE_ROW_OPEN 0x0000000400000000
  66. #define LC_TABLE_TD_LINE 0x0000000800000000
  67. #define LC_TABLE_TH_LINE 0x0000001000000000
  68. #define LC_HTML_ENTITY 0x0000002000000000
  69. /* Global contexts */
  70. #define GL_HEADING 0x1
  71. /* Aggregate contexts */
  72. #define AGG_FAIL \
  73. (LC_TEMPLATE | LC_ARGUMENT | LC_WIKILINK | LC_EXT_LINK_TITLE | LC_HEADING | \
  74. LC_TAG | LC_STYLE | LC_TABLE_OPEN)
  75. #define AGG_UNSAFE \
  76. (LC_TEMPLATE_NAME | LC_WIKILINK_TITLE | LC_EXT_LINK_TITLE | \
  77. LC_TEMPLATE_PARAM_KEY | LC_ARGUMENT_NAME)
  78. #define AGG_DOUBLE (LC_TEMPLATE_PARAM_KEY | LC_TAG_CLOSE | LC_TABLE_ROW_OPEN)
  79. #define AGG_NO_WIKILINKS \
  80. (LC_TEMPLATE_NAME | LC_ARGUMENT_NAME | LC_WIKILINK_TITLE | LC_EXT_LINK_URI)
  81. #define AGG_NO_EXT_LINKS \
  82. (LC_TEMPLATE_NAME | LC_ARGUMENT_NAME | LC_WIKILINK_TITLE | LC_EXT_LINK)
  83. /* Tag contexts */
  84. #define TAG_NAME 0x01
  85. #define TAG_ATTR_READY 0x02
  86. #define TAG_ATTR_NAME 0x04
  87. #define TAG_ATTR_VALUE 0x08
  88. #define TAG_QUOTED 0x10
  89. #define TAG_NOTE_SPACE 0x20
  90. #define TAG_NOTE_EQUALS 0x40
  91. #define TAG_NOTE_QUOTE 0x80