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.
 
 
 
 

67 lines
2.8 KiB

  1. /*
  2. Copyright (C) 2012-2018 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. /* Functions */
  22. int Tokenizer_push(Tokenizer*, uint64_t);
  23. int Tokenizer_push_textbuffer(Tokenizer*);
  24. void Tokenizer_delete_top_of_stack(Tokenizer*);
  25. PyObject* Tokenizer_pop(Tokenizer*);
  26. PyObject* Tokenizer_pop_keeping_context(Tokenizer*);
  27. void Tokenizer_memoize_bad_route(Tokenizer*);
  28. void* Tokenizer_fail_route(Tokenizer*);
  29. int Tokenizer_check_route(Tokenizer*, uint64_t);
  30. void Tokenizer_free_bad_route_tree(Tokenizer*);
  31. int Tokenizer_emit_token(Tokenizer*, PyObject*, int);
  32. int Tokenizer_emit_token_kwargs(Tokenizer*, PyObject*, PyObject*, int);
  33. int Tokenizer_emit_char(Tokenizer*, Py_UCS4);
  34. int Tokenizer_emit_text(Tokenizer*, const char*);
  35. int Tokenizer_emit_textbuffer(Tokenizer*, Textbuffer*);
  36. int Tokenizer_emit_all(Tokenizer*, PyObject*);
  37. int Tokenizer_emit_text_then_stack(Tokenizer*, const char*);
  38. Py_UCS4 Tokenizer_read(Tokenizer*, Py_ssize_t);
  39. Py_UCS4 Tokenizer_read_backwards(Tokenizer*, Py_ssize_t);
  40. /* Macros */
  41. #define MAX_DEPTH 40
  42. #define Tokenizer_CAN_RECURSE(self) \
  43. (self->depth < MAX_DEPTH)
  44. #define Tokenizer_IS_CURRENT_STACK(self, id) \
  45. (self->topstack->ident.head == (id).head && \
  46. self->topstack->ident.context == (id).context)
  47. #define Tokenizer_emit(self, token) \
  48. Tokenizer_emit_token(self, token, 0)
  49. #define Tokenizer_emit_first(self, token) \
  50. Tokenizer_emit_token(self, token, 1)
  51. #define Tokenizer_emit_kwargs(self, token, kwargs) \
  52. Tokenizer_emit_token_kwargs(self, token, kwargs, 0)
  53. #define Tokenizer_emit_first_kwargs(self, token, kwargs) \
  54. Tokenizer_emit_token_kwargs(self, token, kwargs, 1)