aboutsummaryrefslogtreecommitdiff
path: root/lptree.h
diff options
context:
space:
mode:
authorSergio Queiroz <sqmedeiros@gmail.com>2017-07-06 11:21:56 -0300
committerSergio Queiroz <sqmedeiros@gmail.com>2017-07-06 11:21:56 -0300
commit8ee42c29131e1c7de48575d6d8a9b24ea6977cbd (patch)
tree4267e0cf0609a909be1f2eaea17d11b0efc12c98 /lptree.h
parentaad9b29e755d67d6cb4e4b861111df0d173819ce (diff)
downloadlpeglabel-8ee42c29131e1c7de48575d6d8a9b24ea6977cbd.tar.gz
lpeglabel-8ee42c29131e1c7de48575d6d8a9b24ea6977cbd.tar.bz2
lpeglabel-8ee42c29131e1c7de48575d6d8a9b24ea6977cbd.zip
Updating lpeglabel to the codebase of LPeg 1.0.1
Diffstat (limited to 'lptree.h')
-rw-r--r--lptree.h57
1 files changed, 32 insertions, 25 deletions
diff --git a/lptree.h b/lptree.h
index b75f323..e4e8901 100644
--- a/lptree.h
+++ b/lptree.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lptree.h,v 1.2 2013/03/24 13:51:12 roberto Exp $ 2** $Id: lptree.h,v 1.3 2016/09/13 18:07:51 roberto Exp $
3*/ 3*/
4 4
5#if !defined(lptree_h) 5#if !defined(lptree_h)
@@ -13,32 +13,39 @@
13** types of trees 13** types of trees
14*/ 14*/
15typedef enum TTag { 15typedef enum TTag {
16 TChar = 0, TSet, TAny, /* standard PEG elements */ 16 TChar = 0, /* 'n' = char */
17 TTrue, TFalse, 17 TSet, /* the set is stored in next CHARSETSIZE bytes */
18 TRep, 18 TAny,
19 TSeq, TChoice, 19 TTrue,
20 TNot, TAnd, 20 TFalse,
21 TCall, 21 TRep, /* 'sib1'* */
22 TOpenCall, 22 TSeq, /* 'sib1' 'sib2' */
23 TRule, /* sib1 is rule's pattern, sib2 is 'next' rule */ 23 TChoice, /* 'sib1' / 'sib2' */
24 TGrammar, /* sib1 is initial (and first) rule */ 24 TNot, /* !'sib1' */
25 TBehind, /* match behind */ 25 TAnd, /* &'sib1' */
26 TCapture, /* regular capture */ 26 TCall, /* ktable[key] is rule's key; 'sib2' is rule being called */
27 TRunTime, /* run-time capture */ 27 TOpenCall, /* ktable[key] is rule's key */
28 TThrow, TRecov /* labeled failure */ 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: 'label' = l */
39 TRecov /* labed failure: 'sib1' // 'sib2' */
40 /* the set of labels is stored in next CHARSETSIZE bytes */
29} TTag; 41} TTag;
30 42
31/* number of siblings for each tree */
32extern const byte numsiblings[];
33
34 43
35/* 44/*
36** Tree trees 45** Tree trees
37** The first sibling of a tree (if there is one) is immediately after 46** The first child of a tree (if there is one) is immediately after
38** the tree. A reference to a second sibling (ps) is its position 47** the tree. A reference to a second child (ps) is its position
39** relative to the position of the tree itself. A key in ktable 48** relative to the position of the tree itself.
40** uses the (unique) address of the original tree that created that
41** entry. NULL means no data.
42*/ 49*/
43typedef struct TTree { 50typedef struct TTree {
44 byte tag; 51 byte tag;
@@ -48,7 +55,7 @@ typedef struct TTree {
48 int n; /* occasional counter */ 55 int n; /* occasional counter */
49 int label; /* labeled failure */ 56 int label; /* labeled failure */
50 struct { /* labeled failure */ 57 struct { /* labeled failure */
51 int ps; /* occasional second sibling */ 58 int ps; /* occasional second child */
52 int plab; /* occasional label set */ 59 int plab; /* occasional label set */
53 } s; /* labeled failure */ 60 } s; /* labeled failure */
54 } u; 61 } u;
@@ -66,10 +73,10 @@ typedef struct Pattern {
66} Pattern; 73} Pattern;
67 74
68 75
69/* number of siblings for each tree */ 76/* number of children for each tree */
70extern const byte numsiblings[]; 77extern const byte numsiblings[];
71 78
72/* access to siblings */ 79/* access to children */
73#define sib1(t) ((t) + 1) 80#define sib1(t) ((t) + 1)
74#define sib2(t) ((t) + (t)->u.s.ps) 81#define sib2(t) ((t) + (t)->u.s.ps)
75 82