1 /* 2 * Yang 1.0 parser according to RFC6020. 3 * It is hopefully useful but not complete 4 * RFC7950 defines Yang version 1.1 5 * 6 ***** BEGIN LICENSE BLOCK ***** 7 8 Copyright (C) 2009-2019 Olof Hagsand 9 Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC(Netgate) 10 11 This file is part of CLIXON. 12 13 Licensed under the Apache License, Version 2.0 (the "License"); 14 you may not use this file except in compliance with the License. 15 You may obtain a copy of the License at 16 17 http://www.apache.org/licenses/LICENSE-2.0 18 19 Unless required by applicable law or agreed to in writing, software 20 distributed under the License is distributed on an "AS IS" BASIS, 21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 See the License for the specific language governing permissions and 23 limitations under the License. 24 25 Alternatively, the contents of this file may be used under the terms of 26 the GNU General Public License Version 3 or later (the "GPL"), 27 in which case the provisions of the GPL are applicable instead 28 of those above. If you wish to allow use of your version of this file only 29 under the terms of the GPL, and not to allow others to 30 use your version of this file under the terms of Apache License version 2, 31 indicate your decision by deleting the provisions above and replace them with 32 the notice and other provisions required by the GPL. If you do not delete 33 the provisions above, a recipient may use your version of this file under 34 the terms of any one of the Apache License version 2 or the GPL. 35 36 ***** END LICENSE BLOCK ***** 37 38 * Yang parser. Hopefully useful but not complete 39 * @see https://tools.ietf.org/html/rfc6020 YANG 1.0 40 * @see https://tools.ietf.org/html/rfc7950 YANG 1.1 41 */ 42 #ifndef _CLIXON_YANG_PARSE_H_ 43 #define _CLIXON_YANG_PARSE_H_ 44 45 /* 46 * Types 47 */ 48 49 struct ys_stack{ 50 struct ys_stack *ys_next; 51 yang_stmt *ys_node; 52 }; 53 54 struct clixon_yang_yacc { 55 char *yy_name; /* Name of syntax, typically filename 56 (for error string) */ 57 int yy_linenum; /* Number of \n in parsed buffer */ 58 char *yy_parse_string; /* original (copy of) parse string */ 59 void *yy_lexbuf; /* internal parse buffer from lex */ 60 struct ys_stack *yy_stack; /* Stack of levels: push/pop on () and [] */ 61 int yy_lex_state; /* lex start condition (ESCAPE/COMMENT) */ 62 int yy_lex_string_state; /* lex start condition (STRING) */ 63 yang_stmt *yy_module; /* top-level (sub)module - return value of parser */ 64 }; 65 typedef struct clixon_yang_yacc clixon_yang_yacc; 66 67 /* This is a malloced piece of code we attach to cligen objects used as db-specs. 68 * So if(when) we translate cg_obj to yang_obj (or something). These are the fields 69 * we should add. 70 */ 71 struct yang_userdata{ 72 char *du_indexvar; /* (clicon) This command is a list and 73 this string is the key/index of the list 74 */ 75 char *du_yang; /* (clicon) Save yang key for cli 76 generation */ 77 int du_optional; /* (clicon) Optional element in list */ 78 struct cg_var *du_default; /* default value(clicon) */ 79 char du_vector; /* (clicon) Possibly more than one element */ 80 }; 81 82 /* 83 * Variables 84 */ 85 extern char *clixon_yang_parsetext; 86 87 /* 88 * Prototypes 89 */ 90 int yang_scan_init(clixon_yang_yacc *ya); 91 int yang_scan_exit(clixon_yang_yacc *ya); 92 93 int yang_parse_init(clixon_yang_yacc *ya); 94 int yang_parse_exit(clixon_yang_yacc *ya); 95 96 int clixon_yang_parselex(void *_ya); 97 int clixon_yang_parseparse(void *); 98 void clixon_yang_parseerror(void *_ya, char*); 99 100 int ystack_pop(clixon_yang_yacc *ya); 101 struct ys_stack *ystack_push(clixon_yang_yacc *ya, yang_stmt *yn); 102 103 #endif /* _CLIXON_YANG_PARSE_H_ */ 104