diff options
Diffstat (limited to 'lptree.h')
-rw-r--r-- | lptree.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/lptree.h b/lptree.h new file mode 100644 index 0000000..43299a4 --- /dev/null +++ b/lptree.h | |||
@@ -0,0 +1,79 @@ | |||
1 | /* | ||
2 | ** $Id: lptree.h,v 1.2 2013/03/24 13:51:12 roberto Exp $ | ||
3 | */ | ||
4 | |||
5 | #if !defined(lptree_h) | ||
6 | #define lptree_h | ||
7 | |||
8 | |||
9 | #include "lptypes.h" | ||
10 | |||
11 | |||
12 | /* | ||
13 | ** types of trees | ||
14 | */ | ||
15 | typedef enum TTag { | ||
16 | TChar = 0, TSet, TAny, /* standard PEG elements */ | ||
17 | TTrue, TFalse, | ||
18 | TRep, | ||
19 | TSeq, TChoice, | ||
20 | TNot, TAnd, | ||
21 | TCall, | ||
22 | TOpenCall, | ||
23 | TRule, /* sib1 is rule's pattern, sib2 is 'next' rule */ | ||
24 | TGrammar, /* sib1 is initial (and first) rule */ | ||
25 | TBehind, /* match behind */ | ||
26 | TCapture, /* regular capture */ | ||
27 | TRunTime, /* run-time capture */ | ||
28 | TThrow, TLabChoice /* labeled failure */ | ||
29 | } TTag; | ||
30 | |||
31 | /* number of siblings for each tree */ | ||
32 | extern const byte numsiblings[]; | ||
33 | |||
34 | |||
35 | /* | ||
36 | ** Tree trees | ||
37 | ** The first sibling of a tree (if there is one) is immediately after | ||
38 | ** the tree. A reference to a second sibling (ps) is its position | ||
39 | ** relative to the position of the tree itself. A key in ktable | ||
40 | ** uses the (unique) address of the original tree that created that | ||
41 | ** entry. NULL means no data. | ||
42 | */ | ||
43 | typedef struct TTree { | ||
44 | byte tag; | ||
45 | byte cap; /* kind of capture (if it is a capture) */ | ||
46 | unsigned short key; /* key in ktable for Lua data (0 if no key) */ | ||
47 | Labelset labels; /* labeled failure */ | ||
48 | union { | ||
49 | int ps; /* occasional second sibling */ | ||
50 | int n; /* occasional counter */ | ||
51 | } u; | ||
52 | } TTree; | ||
53 | |||
54 | |||
55 | /* | ||
56 | ** A complete pattern has its tree plus, if already compiled, | ||
57 | ** its corresponding code | ||
58 | */ | ||
59 | typedef struct Pattern { | ||
60 | union Instruction *code; | ||
61 | int codesize; | ||
62 | TTree tree[1]; | ||
63 | } Pattern; | ||
64 | |||
65 | |||
66 | /* number of siblings for each tree */ | ||
67 | extern const byte numsiblings[]; | ||
68 | |||
69 | /* access to siblings */ | ||
70 | #define sib1(t) ((t) + 1) | ||
71 | #define sib2(t) ((t) + (t)->u.ps) | ||
72 | |||
73 | |||
74 | |||
75 | |||
76 | |||
77 | |||
78 | #endif | ||
79 | |||