]> git.ozlabs.org Git - petitboot/blob - discover/native/native-lexer.l
Various fixups and checks to make scan-build happy
[petitboot] / discover / native / native-lexer.l
1 %{
2 #include "native.h"
3 #include "native-parser.h"
4 #include <talloc/talloc.h>
5
6 #define YYSTYPE NSTYPE
7
8 void yyerror(struct native_parser *parser, const char *fmt, ...);
9 %}
10
11 %option nounput noinput
12 %option batch never-interactive
13 %option warn
14 %option noyywrap
15 %option reentrant
16 %option bison-bridge
17 %option yylineno
18 %option noyyalloc noyyfree noyyrealloc
19 %option extra-type="struct native_parser *"
20 %option prefix="n"
21
22 %x label
23 %x args
24
25 DELIM   [ \t]+
26 NUMBER  0|[1-9][0-9]*
27 WORDS   [^\n]+
28 NEWLINE [\n]+
29
30 %%
31
32 name            { BEGIN(label); return TOKEN_NAME; }
33 image           { BEGIN(label); return TOKEN_IMAGE; }
34 initrd          { BEGIN(label); return TOKEN_INITRD; }
35 args            { BEGIN(label); return TOKEN_ARGS; }
36 dtb             { BEGIN(label); return TOKEN_DTB; }
37 description     { BEGIN(label); return TOKEN_DESCRIPTION; }
38 default         { BEGIN(label); return TOKEN_DEFAULT; }
39 dev_description { BEGIN(label); return TOKEN_DEV_DESCRIPTION; }
40 {DELIM}         { ; }
41 {NEWLINE}       { ; }
42 <label>{DELIM}  { BEGIN(args); return TOKEN_DELIM; }
43 <args>{WORDS}   { yylval->word = strdup(yytext); return TOKEN_WORD; }
44 <args>{NEWLINE} { BEGIN(INITIAL); ; }
45
46 %%
47
48 struct native_parser;
49
50 void *yyalloc(size_t bytes, void *yyscanner)
51 {
52         struct native_parser *parser = yyget_extra(yyscanner);
53         return talloc_size(parser, bytes);
54 }
55
56 void *yyrealloc(void *ptr, size_t bytes, void *yyscanner)
57 {
58         struct native_parser *parser = yyget_extra(yyscanner);
59         return talloc_realloc_size(parser, ptr, bytes);
60 }
61
62 void yyfree(void *ptr, void *yyscanner __attribute__((unused)))
63 {
64         talloc_free(ptr);
65 }