summaryrefslogtreecommitdiffstats
path: root/lib/command_lex.l
blob: 45f8f8e63691df1d2d5445c0fc1c12304d6faf7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
%{
#include "command_parse.h"

extern void set_buffer_string(const char *);
%}

WORD            [a-z][-_a-z0-9]+
IPV4            A\.B\.C\.D
IPV4_PREFIX     A\.B\.C\.D\/M
IPV6            X:X::X:X
IPV6_PREFIX     X:X::X:X\/M
VARIABLE        [A-Z][A-Z_]+
NUMBER          [0-9]{1,20}
RANGE           \({NUMBER}\-{NUMBER}\)

/* yytext shall be a pointer */
%pointer
%option noyywrap
%option nounput
%option noinput
%option outfile="command_lex.c"

%%
[ /t]           /* ignore whitespace */;
{WORD}          {yylval.string = strdup(yytext); return WORD;}
{IPV4}          {yylval.string = strdup(yytext); return IPV4;}
{IPV4_PREFIX}   {yylval.string = strdup(yytext); return IPV4_PREFIX;}
{IPV6}          {yylval.string = strdup(yytext); return IPV6;}
{IPV6_PREFIX}   {yylval.string = strdup(yytext); return IPV6_PREFIX;}
{VARIABLE}      {yylval.string = strdup(yytext); return VARIABLE;}
{NUMBER}        {yylval.integer = atoi(yytext); return NUMBER;}
{RANGE}         {yylval.string = strdup(yytext); return RANGE;}
.               {return yytext[0];}
%%

void
set_buffer_string(const char *string)
{
  yy_scan_string(string);
}