A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

94 rader
4.7 KiB

  1. /*
  2. Copyright (C) 2012-2016 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. #include "common.h"
  21. #include "textbuffer.h"
  22. /* Functions */
  23. static PyObject* Tokenizer_new(PyTypeObject*, PyObject*, PyObject*);
  24. static void Tokenizer_dealloc(Tokenizer*);
  25. static int Tokenizer_init(Tokenizer*, PyObject*, PyObject*);
  26. static PyObject* Tokenizer_tokenize(Tokenizer*, PyObject*);
  27. /* Structs */
  28. static PyMethodDef Tokenizer_methods[] = {
  29. {"tokenize", (PyCFunction) Tokenizer_tokenize, METH_VARARGS,
  30. "Build a list of tokens from a string of wikicode and return it."},
  31. {NULL}
  32. };
  33. static PyMemberDef Tokenizer_members[] = {
  34. {NULL}
  35. };
  36. static PyTypeObject TokenizerType = {
  37. PyVarObject_HEAD_INIT(NULL, 0)
  38. "_tokenizer.CTokenizer", /* tp_name */
  39. sizeof(Tokenizer), /* tp_basicsize */
  40. 0, /* tp_itemsize */
  41. (destructor) Tokenizer_dealloc, /* tp_dealloc */
  42. 0, /* tp_print */
  43. 0, /* tp_getattr */
  44. 0, /* tp_setattr */
  45. 0, /* tp_compare */
  46. 0, /* tp_repr */
  47. 0, /* tp_as_number */
  48. 0, /* tp_as_sequence */
  49. 0, /* tp_as_mapping */
  50. 0, /* tp_hash */
  51. 0, /* tp_call */
  52. 0, /* tp_str */
  53. 0, /* tp_getattro */
  54. 0, /* tp_setattro */
  55. 0, /* tp_as_buffer */
  56. Py_TPFLAGS_DEFAULT, /* tp_flags */
  57. "Creates a list of tokens from a string of wikicode.", /* tp_doc */
  58. 0, /* tp_traverse */
  59. 0, /* tp_clear */
  60. 0, /* tp_richcompare */
  61. 0, /* tp_weaklistoffset */
  62. 0, /* tp_iter */
  63. 0, /* tp_iternext */
  64. Tokenizer_methods, /* tp_methods */
  65. Tokenizer_members, /* tp_members */
  66. 0, /* tp_getset */
  67. 0, /* tp_base */
  68. 0, /* tp_dict */
  69. 0, /* tp_descr_get */
  70. 0, /* tp_descr_set */
  71. 0, /* tp_dictoffset */
  72. (initproc) Tokenizer_init, /* tp_init */
  73. 0, /* tp_alloc */
  74. Tokenizer_new, /* tp_new */
  75. };
  76. static PyModuleDef module_def = {
  77. PyModuleDef_HEAD_INIT,
  78. "_tokenizer",
  79. "Creates a list of tokens from a string of wikicode.",
  80. -1, NULL, NULL, NULL, NULL, NULL
  81. };