diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-02-20 10:13:46 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-02-20 10:13:46 -0300 |
commit | e08e5df853560de6482d84066a7accc6a18de545 (patch) | |
tree | ee19686bb35da90709a32ed24bf7855de1a3946a /lptree.h | |
download | lpeg-e08e5df853560de6482d84066a7accc6a18de545.tar.gz lpeg-e08e5df853560de6482d84066a7accc6a18de545.tar.bz2 lpeg-e08e5df853560de6482d84066a7accc6a18de545.zip |
Fist version of LPeg on GIT
LPeg repository is being moved to git. Past versions won't be moved;
they are still available in RCS.
Diffstat (limited to 'lptree.h')
-rw-r--r-- | lptree.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lptree.h b/lptree.h new file mode 100644 index 0000000..34ee15c --- /dev/null +++ b/lptree.h | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | ** $Id: lptree.h,v 1.3 2016/09/13 18:07:51 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, /* 'n' = char */ | ||
17 | TSet, /* the set is stored in next CHARSETSIZE bytes */ | ||
18 | TAny, | ||
19 | TTrue, | ||
20 | TFalse, | ||
21 | TRep, /* 'sib1'* */ | ||
22 | TSeq, /* 'sib1' 'sib2' */ | ||
23 | TChoice, /* 'sib1' / 'sib2' */ | ||
24 | TNot, /* !'sib1' */ | ||
25 | TAnd, /* &'sib1' */ | ||
26 | TCall, /* ktable[key] is rule's key; 'sib2' is rule being called */ | ||
27 | TOpenCall, /* ktable[key] is rule's key */ | ||
28 | TRule, /* ktable[key] is rule's key (but key == 0 for unused rules); | ||
29 | 'sib1' is rule's pattern; | ||
30 | 'sib2' is next rule; 'cap' is rule's sequential number */ | ||
31 | TGrammar, /* 'sib1' is initial (and first) rule */ | ||
32 | TBehind, /* 'sib1' is pattern, 'n' is how much to go back */ | ||
33 | TCapture, /* captures: 'cap' is kind of capture (enum 'CapKind'); | ||
34 | ktable[key] is Lua value associated with capture; | ||
35 | 'sib1' is capture body */ | ||
36 | TRunTime /* run-time capture: 'key' is Lua function; | ||
37 | 'sib1' is capture body */ | ||
38 | } TTag; | ||
39 | |||
40 | |||
41 | /* | ||
42 | ** Tree trees | ||
43 | ** The first child of a tree (if there is one) is immediately after | ||
44 | ** the tree. A reference to a second child (ps) is its position | ||
45 | ** relative to the position of the tree itself. | ||
46 | */ | ||
47 | typedef struct TTree { | ||
48 | byte tag; | ||
49 | byte cap; /* kind of capture (if it is a capture) */ | ||
50 | unsigned short key; /* key in ktable for Lua data (0 if no key) */ | ||
51 | union { | ||
52 | int ps; /* occasional second child */ | ||
53 | int n; /* occasional counter */ | ||
54 | } u; | ||
55 | } TTree; | ||
56 | |||
57 | |||
58 | /* | ||
59 | ** A complete pattern has its tree plus, if already compiled, | ||
60 | ** its corresponding code | ||
61 | */ | ||
62 | typedef struct Pattern { | ||
63 | union Instruction *code; | ||
64 | int codesize; | ||
65 | TTree tree[1]; | ||
66 | } Pattern; | ||
67 | |||
68 | |||
69 | /* number of children for each tree */ | ||
70 | extern const byte numsiblings[]; | ||
71 | |||
72 | /* access to children */ | ||
73 | #define sib1(t) ((t) + 1) | ||
74 | #define sib2(t) ((t) + (t)->u.ps) | ||
75 | |||
76 | |||
77 | |||
78 | |||
79 | |||
80 | |||
81 | #endif | ||
82 | |||