FD.io VPP  v16.06
Vector Packet Processing
lex.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef included_vlib_lex_h
16 #define included_vlib_lex_h
17 
18 #include <vppinfra/hash.h>
19 #include <vppinfra/bitmap.h>
20 #include <vppinfra/error.h>
21 #include <vppinfra/pool.h>
22 
23 #define foreach_vlib_lex_global_token \
24  _ (invalid) \
25  _ (eof) \
26  _ (word) \
27  _ (number) \
28  _ (lt) \
29  _ (gt) \
30  _ (dot) \
31  _ (slash) \
32  _ (qmark) \
33  _ (equals) \
34  _ (plus) \
35  _ (minus) \
36  _ (star) \
37  _ (lpar) \
38  _ (rpar)
39 
40 typedef enum {
41 #define _(f) VLIB_LEX_##f,
43 #undef _
45 
46 typedef enum {
55 
56 typedef struct {
61 
62 typedef struct {
63  char *name;
64  vlib_lex_table_entry_t entries [128];
66 
67 typedef struct {
69 
70  union {
72  void * as_pointer;
73  char * as_string;
74  } value;
76 
77 typedef struct {
80 
81  /* Vector of token strings. */
82  char ** lex_token_names;
83 
84  /* Hash mapping c string name to token index. */
86 
87  /* Hash mapping c string keyword name to token index. */
89 
91 
93 
95 
97 
99 
100  /* Input string we are lex-ing. */
102 
103  /* Current index into input vector. */
105 
106  /* Re-used vector for forming token strings and hashing them. */
109 
111 
112 always_inline void
114 {
115  if (t->token == VLIB_LEX_word)
116  {
117  u8 * tv = t->value.as_pointer;
118  vec_free (tv);
119  }
120 }
121 
122 u16 vlib_lex_add_table (char *name);
124 u16 vlib_lex_add_token (vlib_lex_main_t *lm, char *token_name);
125 void vlib_lex_set_action_range (u32 table_index, u8 lo, u8 hi, u16 action,
126  u16 token, u32 next_table_index);
127 void vlib_lex_reset (vlib_lex_main_t *lm, u8 *input_vector);
129 
130 #endif /* included_vlib_lex_h */
char * as_string
Definition: lex.h:73
vmrglw vmrglh hi
u8 * input_vector
Definition: lex.h:101
Definition: lex.h:56
uword * lex_tables_by_name
Definition: lex.h:79
uword * lex_tokens_by_name
Definition: lex.h:85
void vlib_lex_get_token(vlib_lex_main_t *lm, vlib_lex_token_t *result)
Definition: lex.c:34
vlib_lex_action_t
Definition: lex.h:46
vlib_lex_main_t vlib_lex_main
Definition: lex.h:110
char ** lex_token_names
Definition: lex.h:82
#define always_inline
Definition: clib.h:84
int i32
Definition: types.h:81
u16 vlib_lex_add_table(char *name)
Definition: lex.c:197
u32 current_index
Definition: lex.h:104
char * name
Definition: lex.h:63
vlib_lex_token_t * pushback_vector
Definition: lex.h:90
u16 action
Definition: lex.h:57
vlib_lex_global_token_t
Definition: lex.h:40
i32 pushback_sp
Definition: lex.h:92
format_function_t format_vlib_lex_token
Definition: lex.h:128
void vlib_lex_reset(vlib_lex_main_t *lm, u8 *input_vector)
Definition: lex.c:222
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:298
vlib_lex_table_t * lex_tables
Definition: lex.h:78
u16 vlib_lex_add_token(vlib_lex_main_t *lm, char *token_name)
Definition: lex.c:143
u32 current_table_index
Definition: lex.h:94
uword current_token_value
Definition: lex.h:96
unsigned int u32
Definition: types.h:88
void * as_pointer
Definition: lex.h:72
union vlib_lex_token_t::@31 value
void vlib_lex_set_action_range(u32 table_index, u8 lo, u8 hi, u16 action, u16 token, u32 next_table_index)
Definition: lex.c:181
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
u64 uword
Definition: types.h:112
#define foreach_vlib_lex_global_token
Definition: lex.h:23
u16 token
Definition: lex.h:59
uword current_number_base
Definition: lex.h:98
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56
uword * lex_keywords
Definition: lex.h:88
u16 next_table_index
Definition: lex.h:58
uword as_uword
Definition: lex.h:71
u8 * token_buffer
Definition: lex.h:107
u32 token
Definition: lex.h:68
always_inline void vlib_lex_cleanup_token(vlib_lex_token_t *t)
Definition: lex.h:113