FD.io VPP  v21.06-3-gbb25fbf28
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 {
42 #define _(f) VLIB_LEX_##f,
44 #undef _
46 
47 typedef enum
48 {
57 
58 typedef struct
59 {
64 
65 typedef struct
66 {
67  char *name;
70 
71 typedef struct
72 {
74 
75  union
76  {
78  void *as_pointer;
79  char *as_string;
80  } value;
82 
83 typedef struct
84 {
87 
88  /* Vector of token strings. */
90 
91  /* Hash mapping c string name to token index. */
93 
94  /* Hash mapping c string keyword name to token index. */
96 
98 
100 
102 
104 
106 
107  /* Input string we are lex-ing. */
109 
110  /* Current index into input vector. */
112 
113  /* Re-used vector for forming token strings and hashing them. */
116 
118 
119 always_inline void
121 {
122  if (t->token == VLIB_LEX_word)
123  {
124  u8 *tv = t->value.as_pointer;
125  vec_free (tv);
126  }
127 }
128 
129 u16 vlib_lex_add_table (char *name);
131 u16 vlib_lex_add_token (vlib_lex_main_t * lm, char *token_name);
132 void vlib_lex_set_action_range (u32 table_index, u8 lo, u8 hi, u16 action,
133  u16 token, u32 next_table_index);
134 void vlib_lex_reset (vlib_lex_main_t * lm, u8 * input_vector);
136 
137 #endif /* included_vlib_lex_h */
138 
139 /*
140  * fd.io coding-style-patch-verification: ON
141  *
142  * Local Variables:
143  * eval: (c-set-style "gnu")
144  * End:
145  */
vlib_lex_main_t::input_vector
u8 * input_vector
Definition: lex.h:108
vlib_lex_table_entry_t::token
u16 token
Definition: lex.h:62
vlib_lex_table_entry_t
Definition: lex.h:58
vlib_lex_add_token
u16 vlib_lex_add_token(vlib_lex_main_t *lm, char *token_name)
Definition: lex.c:148
vlib_lex_token_t::token
u32 token
Definition: lex.h:73
name
string name[64]
Definition: fib.api:25
VLIB_LEX_ADD_TO_TOKEN
@ VLIB_LEX_ADD_TO_TOKEN
Definition: lex.h:50
bitmap.h
vlib_lex_get_token
void vlib_lex_get_token(vlib_lex_main_t *lm, vlib_lex_token_t *result)
Definition: lex.c:36
vlib_lex_reset
void vlib_lex_reset(vlib_lex_main_t *lm, u8 *input_vector)
Definition: lex.c:233
foreach_vlib_lex_global_token
#define foreach_vlib_lex_global_token
Definition: lex.h:23
format_vlib_lex_token
format_function_t format_vlib_lex_token
Definition: lex.h:135
vlib_lex_main_t::pushback_vector
vlib_lex_token_t * pushback_vector
Definition: lex.h:97
u16
unsigned short u16
Definition: types.h:57
entries
u32 entries
Definition: flowhash_template.h:362
vlib_lex_table_t
Definition: lex.h:65
VLIB_LEX_RETURN
@ VLIB_LEX_RETURN
Definition: lex.h:51
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
i32
signed int i32
Definition: types.h:77
vlib_lex_main_t::lex_keywords
uword * lex_keywords
Definition: lex.h:95
vlib_lex_token_t::value
union vlib_lex_token_t::@618 value
vlib_lex_main_t
Definition: lex.h:83
error.h
vlib_lex_main_t::current_number_base
uword current_number_base
Definition: lex.h:105
vlib_lex_main_t::lex_tables_by_name
uword * lex_tables_by_name
Definition: lex.h:86
vlib_lex_global_token_t
vlib_lex_global_token_t
Definition: lex.h:40
vlib_lex_main_t::lex_tokens_by_name
uword * lex_tokens_by_name
Definition: lex.h:92
uword
u64 uword
Definition: types.h:112
pool.h
Fixed length block allocator. Pools are built from clib vectors and bitmaps. Use pools when repeatedl...
vlib_lex_set_action_range
void vlib_lex_set_action_range(u32 table_index, u8 lo, u8 hi, u16 action, u16 token, u32 next_table_index)
Definition: lex.c:190
vlib_lex_token_t::as_uword
uword as_uword
Definition: lex.h:77
VLIB_LEX_START_NUMBER
@ VLIB_LEX_START_NUMBER
Definition: lex.h:54
vlib_lex_main
vlib_lex_main_t vlib_lex_main
Definition: lex.c:18
VLIB_LEX_KEYWORD_CHECK
@ VLIB_LEX_KEYWORD_CHECK
Definition: lex.h:53
vlib_lex_token_t::as_pointer
void * as_pointer
Definition: lex.h:78
vlib_lex_add_table
u16 vlib_lex_add_table(char *name)
Definition: lex.c:207
vlib_lex_main_t::current_index
u32 current_index
Definition: lex.h:111
vlib_lex_table_entry_t::next_table_index
u16 next_table_index
Definition: lex.h:61
vlib_lex_table_entry_t::action
u16 action
Definition: lex.h:60
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
vlib_lex_action_t
vlib_lex_action_t
Definition: lex.h:47
VLIB_LEX_RETURN_AND_RESCAN
@ VLIB_LEX_RETURN_AND_RESCAN
Definition: lex.h:52
u32
unsigned int u32
Definition: types.h:88
vlib_lex_main_t::pushback_sp
i32 pushback_sp
Definition: lex.h:99
value
u8 value
Definition: qos.api:54
vlib_lex_cleanup_token
static void vlib_lex_cleanup_token(vlib_lex_token_t *t)
Definition: lex.h:120
vlib_lex_main_t::lex_token_names
char ** lex_token_names
Definition: lex.h:89
vlib_lex_token_t::as_string
char * as_string
Definition: lex.h:79
hash.h
u8
unsigned char u8
Definition: types.h:56
vlib_lex_main_t::lex_tables
vlib_lex_table_t * lex_tables
Definition: lex.h:85
VLIB_LEX_IGNORE
@ VLIB_LEX_IGNORE
Definition: lex.h:49
vlib_lex_main_t::token_buffer
u8 * token_buffer
Definition: lex.h:114
vlib_lex_main_t::current_table_index
u32 current_table_index
Definition: lex.h:101
vlib_lex_main_t::current_token_value
uword current_token_value
Definition: lex.h:103
vlib_lex_token_t
Definition: lex.h:71
VLIB_LEX_ADD_TO_NUMBER
@ VLIB_LEX_ADD_TO_NUMBER
Definition: lex.h:55
action
vl_api_mac_event_action_t action
Definition: l2.api:211
lo
lo
Definition: vector_altivec.h:95
vlib_lex_table_t::name
char * name
Definition: lex.h:67