1 /*
2   CLI generator.
3 
4   ***** BEGIN LICENSE BLOCK *****
5 
6   Copyright (C) 2001-2020 Olof Hagsand
7 
8   This file is part of CLIgen.
9 
10   Licensed under the Apache License, Version 2.0 (the "License");
11   you may not use this file except in compliance with the License.
12   You may obtain a copy of the License at
13 
14     http://www.apache.org/licenses/LICENSE-2.0
15 
16   Unless required by applicable law or agreed to in writing, software
17   distributed under the License is distributed on an "AS IS" BASIS,
18   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   See the License for the specific language governing permissions and
20   limitations under the License.
21 
22   Alternatively, the contents of this file may be used under the terms of
23   the GNU General Public License Version 2 or later (the "GPL"),
24   in which case the provisions of the GPL are applicable instead
25   of those above. If you wish to allow use of your version of this file only
26   under the terms of the GPL, and not to allow others to
27   use your version of this file under the terms of Apache License version 2, indicate
28   your decision by deleting the provisions above and replace them with the
29   notice and other provisions required by the GPL. If you do not delete
30   the provisions above, a recipient may use your version of this file under
31   the terms of any one of the Apache License version 2 or the GPL.
32 
33   ***** END LICENSE BLOCK *****
34 
35 
36   Header files for yacc/lex parsing
37 */
38 
39 #ifndef _CLIGEN_PARSE_H_
40 #define _CLIGEN_PARSE_H_
41 
42 /*
43  * Types
44  */
45 
46 /*
47  * Two data structures: a list and a stack.
48  * The stack keeps track of syntactic levels: (decl) and [decl] so that
49  * the stack is pushed and later popped  to keep track of where you are.
50  * The list keeps track of the list of objects that are currently affected. Every choice and
51  * option extends the list. Operations apply to all objects on the list..
52  */
53 struct cgy_stack{
54     struct cgy_stack *cs_next;
55     struct cgy_list  *cs_list;   /* Pointer to a list (saved state)*/
56     struct cgy_list  *cs_saved;  /* Saved state for options (used in pop_add) */
57 };
58 
59 struct cgy_list{
60     struct cgy_list *cl_next;
61     cg_obj          *cl_obj;
62 };
63 
64 /*! CLIgen yacc parse structure, with all accumulated state of a parse session */
65 struct cligen_parse_yacc{
66     cligen_handle         cy_handle;       /* cligen_handle */
67     char                 *cy_name;         /* Name of syntax (for error string) */
68     char                 *cy_treename;     /* Name of syntax (for error string) */
69     int                   cy_linenum;      /* Number of \n in parsed buffer */
70     char                 *cy_parse_string; /* original (copy of) parse string */
71     void                 *cy_lexbuf;       /* internal parse buffer from lex */
72     cvec                 *cy_globals;      /* global variables after parsing */
73     cvec                 *cy_cvec;         /* local variables (per-command) */
74     struct cgy_stack     *cy_stack;        /* Stack of levels: push/pop on () and [] */
75     struct cgy_list      *cy_list;         /* (Parallel) List of objects currently 'active' */
76     cg_obj               *cy_var;
77     struct cg_callback   *cy_callbacks;
78     int                   cy_lex_state;  /* lex start condition (ESCAPE/COMMENT) */
79     int                   cy_lex_string_state; /* lex start condition (STRING) */
80 };
81 typedef struct cligen_parse_yacc cligen_yacc;
82 
83 /*
84  * Variables
85  */
86 extern char *cligen_parsetext;
87 
88 /*
89  * Prototypes
90  */
91 
92 int cgl_init(cligen_yacc *cy);
93 int cgl_exit(cligen_yacc *cy);
94 
95 int cgy_init(cligen_yacc *cy, cg_obj *co_top);
96 int cgy_exit(cligen_yacc *cy);
97 
98 int cligen_parselex(void *_ya);
99 int cligen_parseparse(void *);
100 void cligen_parseerror(void *_ya, char*);
101 int cligen_parse_debug(int d);
102 
103 #endif	/* _CLIGEN_PARSE_H_ */
104