-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlexer.l
106 lines (76 loc) · 4 KB
/
lexer.l
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
%option noyywrap
%top {
#include "parser.h"
}
%s STRING_DECL_MODE
%s STRING_ASSIGNMENT_MODE
%s COMMENT_MODE
lowercase [a-z]
uppercase [A-Z]
digit [0-9]
lex_assignment "="
open_bracket "["
close_bracket "]"
hash "#"
underscore "_"
slash "/"
dot "."
lex_identifier ({lowercase}|{uppercase})({lowercase}|{uppercase}|{digit}|{underscore})*
unicode_classZS "\u0020"|"\u00A0"|"\u1680"|"\u180E"|"\u2000"|"\u2001"|"\u2002"|"\u2003"|"\u2004"|"\u2005"|"\u2006"|"\u2008"|"\u2009"|"\u200A"|"\u202F"|"\u3000"|"\u205F"
whitespace {unicode_classZS}|"\u0009"|"\u000B"|"\u000C"
whitespaces {whitespace}+
newline "\r\n"|"\r"|"\n"|"\u0085"|"\u2028"|"\u2029"
newlines {newline}+
true "true"
false "false"
input_character ~[\r\n]
integer_literal {digit}+
plus "+"
minus "-"
mesg_separator "---"
%%
<STRING_DECL_MODE>{lex_assignment} { BEGIN(STRING_ASSIGNMENT_MODE); }
<STRING_DECL_MODE>{lex_identifier} { return STRING_IDENTIFIER; }
<STRING_DECL_MODE>{open_bracket} { return STRING_OPEN_BRACKET; }
<STRING_DECL_MODE>{close_bracket} { return STRING_CLOSE_BRACKET; }
<STRING_DECL_MODE>{integer_literal} { return STRING_INTEGER_LITERAL; }
<STRING_DECL_MODE>{hash} { BEGIN(COMMENT_MODE); return STRING_HASH; }
<STRING_DECL_MODE>.+ { return STRING_VALUE; }
<STRING_DECL_MODE>{newline} { BEGIN(INITIAL); }
<STRING_ASSIGNMENT_MODE>.+
<STRING_ASSIGNMENT_MODE>{newline} { BEGIN(INITIAL); }
<COMMENT_MODE>.+ { return COMMENT; }
<COMMENT_MODE>{newline} { BEGIN(INITIAL); }
bool { yylval.ident.name=strdup(yytext); return BOOL; }
int8 { yylval.ident.name=strdup(yytext); return INT8; }
uint8 { yylval.ident.name=strdup(yytext); return UINT8; }
byte { yylval.ident.name=strdup(yytext); return BYTE; }
char { yylval.ident.name=strdup(yytext); return CHAR; }
int16 { yylval.ident.name=strdup(yytext); return INT16; }
uint16 { yylval.ident.name=strdup(yytext); return UINT16; }
int32 { yylval.ident.name=strdup(yytext); return INT32; }
uint32 { yylval.ident.name=strdup(yytext); return UINT32; }
int64 { yylval.ident.name=strdup(yytext); return INT64; }
uint64 { yylval.ident.name=strdup(yytext); return UINT64; }
float32 { yylval.ident.name=strdup(yytext); return FLOAT32; }
float64 { yylval.ident.name=strdup(yytext); return FLOAT64; }
string { BEGIN(STRING_DECL_MODE); yylval.ident.name=strdup(yytext); return STRING; }
time { yylval.ident.name=strdup(yytext); return TIME; }
duration { yylval.ident.name=strdup(yytext); return DURATION; }
{slash} { yylval.ident.name=strdup(yytext); return SLASH; }
{lex_assignment} { return ASSIGNMENT; }
{open_bracket} { return OPEN_BRACKET; }
{close_bracket} { return CLOSE_BRACKET; }
{hash} { BEGIN(COMMENT_MODE); return HASH; }
{plus} { return PLUS; }
{minus} { return MINUS; }
{mesg_separator} { return MESSAGE_SEPARATOR; }
{integer_literal} { return INTEGER_LITERAL; }
{digit}*{dot}{digit}+ { return REAL_LITERAL; }
{true} { return TRUE; }
{false} { return FALSE; }
<INITIAL>{lex_identifier} {yylval.ident.name=strdup(yytext); return IDENTIFIER; }
"="+{newline}"MSG:" { return ROSBAG_MESSAGE_SEPARATOR; }
{newline} { BEGIN(INITIAL); }
. { }
%%