summaryrefslogtreecommitdiff
path: root/contrib/seg/segscan.l
blob: ea9032685a9d990fbeddc1a19131ca8d6fc871db (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
%{
/* 
** A scanner for EMP-style numeric ranges 
*/

#include <string.h>
#include <stdio.h>
#include "segparse.h"
#include "buffer.h"

#define YY_NO_UNPUT 1
#undef  yywrap

/* flex screws a couple symbols when used with the -P otion; fix those */
#define YY_DECL int seg_yylex YY_PROTO(( void )); \
int seg_yylex YY_PROTO(( void ))
#define yylval seg_yylval

/* redefined YY_INPUT reads byte-wise from the memory area defined in buffer.c */
#undef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
{ \
        int c = read_parse_buffer(); \
        result = (c == '\0') ?  YY_NULL : (buf[0] = c, 1); \
}

void seg_flush_scanner_buffer(void); 
%}

range        (\.\.)(\.)?
plumin       (\'\+\-\')|(\(\+\-)\)
integer      [+-]?[0-9]+
real         [+-]?[0-9]+\.[0-9]+
float        ({integer}|{real})([eE]{integer})?

%%

{range}      yylval.text = yytext; return RANGE;
{plumin}     yylval.text = yytext; return PLUMIN;
{float}      yylval.text = yytext; return FLOAT;
\<           yylval.text = "<"; return EXTENSION;
\>           yylval.text = ">"; return EXTENSION;
\~           yylval.text = "~"; return EXTENSION;
[ ]+         /* discard spaces */
.            return yytext[0]; /* alert parser of the garbage */

%%

int seg_yylex();

void seg_flush_scanner_buffer(void) {
  YY_FLUSH_BUFFER;
}