aboutsummaryrefslogtreecommitdiff
path: root/lptree.h
diff options
context:
space:
mode:
authorSergio Queiroz <sqmedeiros@gmail.com>2019-01-10 10:06:33 -0300
committerSergio Queiroz <sqmedeiros@gmail.com>2019-01-10 10:06:33 -0300
commit4fb816d55f47c48c34cc4478e584b1567a75863b (patch)
tree54ec6965c9d3983b193cf000a521a06cb3d73b8a /lptree.h
parent9be59fb8f4b176a16643e707c74051b243202296 (diff)
downloadlpeglabel-lpeg-1.0.0.tar.gz
lpeglabel-lpeg-1.0.0.tar.bz2
lpeglabel-lpeg-1.0.0.zip
Adapting lpeglabel-1.5 to the codebase of lpeg-1.0.0lpeg-1.0.0
Diffstat (limited to 'lptree.h')
-rw-r--r--lptree.h53
1 files changed, 24 insertions, 29 deletions
diff --git a/lptree.h b/lptree.h
index 24a9ac7..70e9c61 100644
--- a/lptree.h
+++ b/lptree.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lptree.h,v 1.3 2016/09/13 18:07:51 roberto Exp $ 2** $Id: lptree.h,v 1.2 2013/03/24 13:51:12 roberto Exp $
3*/ 3*/
4 4
5#if !defined(lptree_h) 5#if !defined(lptree_h)
@@ -13,45 +13,40 @@
13** types of trees 13** types of trees
14*/ 14*/
15typedef enum TTag { 15typedef enum TTag {
16 TChar = 0, /* 'n' = char */ 16 TChar = 0, TSet, TAny, /* standard PEG elements */
17 TSet, /* the set is stored in next CHARSETSIZE bytes */ 17 TTrue, TFalse,
18 TAny, 18 TRep,
19 TTrue, 19 TSeq, TChoice,
20 TFalse, 20 TNot, TAnd,
21 TRep, /* 'sib1'* */ 21 TCall,
22 TSeq, /* 'sib1' 'sib2' */ 22 TOpenCall,
23 TChoice, /* 'sib1' / 'sib2' */ 23 TRule, /* sib1 is rule's pattern, sib2 is 'next' rule */
24 TNot, /* !'sib1' */ 24 TGrammar, /* sib1 is initial (and first) rule */
25 TAnd, /* &'sib1' */ 25 TBehind, /* match behind */
26 TCall, /* ktable[key] is rule's key; 'sib2' is rule being called */ 26 TCapture, /* regular capture */
27 TOpenCall, /* ktable[key] is rule's key */ 27 TRunTime, /* run-time capture */
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 TThrow, /* labeled failure: ktable[key] is label's name */ 28 TThrow, /* labeled failure: ktable[key] is label's name */
39} TTag; 29} TTag;
40 30
31/* number of siblings for each tree */
32extern const byte numsiblings[];
33
41 34
42/* 35/*
43** Tree trees 36** Tree trees
44** The first child of a tree (if there is one) is immediately after 37** The first sibling of a tree (if there is one) is immediately after
45** the tree. A reference to a second child (ps) is its position 38** the tree. A reference to a second sibling (ps) is its position
46** relative to the position of the tree itself. 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.
47*/ 42*/
48typedef struct TTree { 43typedef struct TTree {
49 byte tag; 44 byte tag;
50 byte cap; /* kind of capture (if it is a capture) */ 45 byte cap; /* kind of capture (if it is a capture) */
51 unsigned short key; /* key in ktable for Lua data (0 if no key) */ 46 unsigned short key; /* key in ktable for Lua data (0 if no key) */
52 union { 47 union {
48 int ps; /* occasional second sibling */
53 int n; /* occasional counter */ 49 int n; /* occasional counter */
54 int ps; /* occasional second child */
55 } u; 50 } u;
56} TTree; 51} TTree;
57 52
@@ -67,10 +62,10 @@ typedef struct Pattern {
67} Pattern; 62} Pattern;
68 63
69 64
70/* number of children for each tree */ 65/* number of siblings for each tree */
71extern const byte numsiblings[]; 66extern const byte numsiblings[];
72 67
73/* access to children */ 68/* access to siblings */
74#define sib1(t) ((t) + 1) 69#define sib1(t) ((t) + 1)
75#define sib2(t) ((t) + (t)->u.ps) 70#define sib2(t) ((t) + (t)->u.ps)
76 71