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.

lptree.h 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. ** $Id: lptree.h,v 1.2 2013/03/24 13:51:12 roberto Exp $
  3. */
  4. #if !defined(lptree_h)
  5. #define lptree_h
  6. #include "lptypes.h"
  7. /*
  8. ** types of trees
  9. */
  10. typedef enum TTag {
  11. TChar = 0, TSet, TAny, /* standard PEG elements */
  12. TTrue, TFalse,
  13. TRep,
  14. TSeq, TChoice,
  15. TNot, TAnd,
  16. TCall,
  17. TOpenCall,
  18. TRule, /* sib1 is rule's pattern, sib2 is 'next' rule */
  19. TGrammar, /* sib1 is initial (and first) rule */
  20. TBehind, /* match behind */
  21. TCapture, /* regular capture */
  22. TRunTime /* run-time capture */
  23. } TTag;
  24. /* number of siblings for each tree */
  25. extern const byte numsiblings[];
  26. /*
  27. ** Tree trees
  28. ** The first sibling of a tree (if there is one) is immediately after
  29. ** the tree. A reference to a second sibling (ps) is its position
  30. ** relative to the position of the tree itself. A key in ktable
  31. ** uses the (unique) address of the original tree that created that
  32. ** entry. NULL means no data.
  33. */
  34. typedef struct TTree {
  35. byte tag;
  36. byte cap; /* kind of capture (if it is a capture) */
  37. unsigned short key; /* key in ktable for Lua data (0 if no key) */
  38. union {
  39. int ps; /* occasional second sibling */
  40. int n; /* occasional counter */
  41. } u;
  42. } TTree;
  43. /*
  44. ** A complete pattern has its tree plus, if already compiled,
  45. ** its corresponding code
  46. */
  47. typedef struct Pattern {
  48. union Instruction *code;
  49. int codesize;
  50. TTree tree[1];
  51. } Pattern;
  52. /* number of siblings for each tree */
  53. extern const byte numsiblings[];
  54. /* access to siblings */
  55. #define sib1(t) ((t) + 1)
  56. #define sib2(t) ((t) + (t)->u.ps)
  57. int luaopen_lpeg (lua_State *L);
  58. #endif