summaryrefslogtreecommitdiffstats
path: root/discover/native/native-lexer.l
blob: bf1408aeff264b7284eb9d155fa8fe83bc49306e (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
%{
#include "native.h"
#include "native-parser.h"
#include <talloc/talloc.h>

#define YYSTYPE NSTYPE

void yyerror(struct native_parser *parser, const char *fmt, ...);
%}

%option nounput noinput
%option batch never-interactive
%option warn
%option noyywrap
%option reentrant
%option bison-bridge
%option yylineno
%option noyyalloc noyyfree noyyrealloc
%option extra-type="struct native_parser *"
%option prefix="n"

%x label
%x args

DELIM	[ \t]+
NUMBER	0|[1-9][0-9]*
WORDS	[^\n]+
NEWLINE [\n]+

%%

name		{ BEGIN(label); return TOKEN_NAME; }
image		{ BEGIN(label); return TOKEN_IMAGE; }
initrd		{ BEGIN(label); return TOKEN_INITRD; }
args		{ BEGIN(label); return TOKEN_ARGS; }
dtb		{ BEGIN(label); return TOKEN_DTB; }
description	{ BEGIN(label); return TOKEN_DESCRIPTION; }
default		{ BEGIN(label); return TOKEN_DEFAULT; }
dev_description { BEGIN(label); return TOKEN_DEV_DESCRIPTION; }
{DELIM}		{ ; }
{NEWLINE}	{ ; }
<label>{DELIM}	{ BEGIN(args); return TOKEN_DELIM; }
<args>{WORDS}	{ yylval->word = strdup(yytext); return TOKEN_WORD; }
<args>{NEWLINE}	{ BEGIN(INITIAL); ; }

%%

struct native_parser;

void *yyalloc(size_t bytes, void *yyscanner)
{
	struct native_parser *parser = yyget_extra(yyscanner);
	return talloc_size(parser, bytes);
}

void *yyrealloc(void *ptr, size_t bytes, void *yyscanner)
{
	struct native_parser *parser = yyget_extra(yyscanner);
	return talloc_realloc_size(parser, ptr, bytes);
}

void yyfree(void *ptr, void *yyscanner __attribute__((unused)))
{
	talloc_free(ptr);
}
OpenPOWER on IntegriCloud