aboutsummaryrefslogtreecommitdiff
path: root/lpltree.h
diff options
context:
space:
mode:
Diffstat (limited to 'lpltree.h')
-rw-r--r--lpltree.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/lpltree.h b/lpltree.h
new file mode 100644
index 0000000..646ef48
--- /dev/null
+++ b/lpltree.h
@@ -0,0 +1,88 @@
1/*
2** $Id: lpltree.h $
3*/
4
5#if !defined(lpltree_h)
6#define lpltree_h
7
8
9#include "lpltypes.h"
10
11
12/*
13** types of trees
14*/
15typedef enum TTag {
16 TChar = 0, /* 'n' = char */
17 TSet, /* the set is stored in next CHARSETSIZE bytes */
18 TAny,
19 TTrue,
20 TFalse,
21 TUTFR, /* range of UTF-8 codepoints; 'n' has initial codepoint;
22 'cap' has length; 'key' has first byte;
23 extra info is similar for end codepoint */
24 TRep, /* 'sib1'* */
25 TSeq, /* 'sib1' 'sib2' */
26 TChoice, /* 'sib1' / 'sib2' */
27 TNot, /* !'sib1' */
28 TAnd, /* &'sib1' */
29 TCall, /* ktable[key] is rule's key; 'sib2' is rule being called */
30 TOpenCall, /* ktable[key] is rule's key */
31 TRule, /* ktable[key] is rule's key (but key == 0 for unused rules);
32 'sib1' is rule's pattern pre-rule; 'sib2' is next rule;
33 extra info 'n' is rule's sequential number */
34 TXInfo, /* extra info */
35 TGrammar, /* 'sib1' is initial (and first) rule */
36 TBehind, /* 'sib1' is pattern, 'n' is how much to go back */
37 TCapture, /* captures: 'cap' is kind of capture (enum 'CapKind');
38 ktable[key] is Lua value associated with capture;
39 'sib1' is capture body */
40 TRunTime, /* run-time capture: 'key' is Lua function;
41 'sib1' is capture body */
42 TThrow, /* labeled failure: ktable[key] is label's name */
43
44} TTag;
45
46
47/*
48** Tree trees
49** The first child of a tree (if there is one) is immediately after
50** the tree. A reference to a second child (ps) is its position
51** relative to the position of the tree itself.
52*/
53typedef struct TTree {
54 byte tag;
55 byte cap; /* kind of capture (if it is a capture) */
56 unsigned short key; /* key in ktable for Lua data (0 if no key) */
57 union {
58 int ps; /* occasional second child */
59 int n; /* occasional counter */
60 } u;
61} TTree;
62
63
64/*
65** A complete pattern has its tree plus, if already compiled,
66** its corresponding code
67*/
68typedef struct Pattern {
69 union Instruction *code;
70 int codesize;
71 TTree tree[1];
72} Pattern;
73
74
75/* number of children for each tree */
76LUAI_FUNC const byte numsiblings[];
77
78/* access to children */
79#define sib1(t) ((t) + 1)
80#define sib2(t) ((t) + (t)->u.ps)
81
82
83
84
85
86
87#endif
88