summaryrefslogtreecommitdiffstats
path: root/tksao/colorbar/lutlex.L
blob: 8e6af2e7c4a5b73c14bc6cd8e873ebb6e565c66c (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
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
/* Copyright (C) 1999-2018
 * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
 * For conditions of distribution and use, see copyright notice in "copyright"
 */

%option noyywrap
%option caseless
%option never-interactive
%option c++

%{
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  #include <ctype.h>

  #include "util.h"
  #include "lutparser.H"

  extern YYSTYPE* rgblval;
  extern rgbFlexLexer* rgblexx;
%}

%x DISCARD

D   [0-9]
E   [Ee][+-]?{D}+

/* rules */

%%

<DISCARD>[\n]	{ // special case-- #\n
		  BEGIN INITIAL;
		  yyless(0);             // put back the terminator
		  strcpy(rgblval->str,""); // feed a blank string
		  return STRING;
		}

<DISCARD>[^\n]* {  // Discard reset of line
		  BEGIN INITIAL;
		  int ll = yyleng <(LUTBUFSIZE-1) ? yyleng:(LUTBUFSIZE-1);
		  strncpy(rgblval->str,yytext,ll);
	          rgblval->str[ll] = '\0';
		  return STRING;
		}

debug		{return DEBUG_;}
false		{return FALSE_;}
no		{return NO_;}
off		{return OFF_;}
on		{return ON_;}
true		{return TRUE_;}
yes		{return YES_;}

[+-]?{D}+	{ // Integer
		  rgblval->integer = atoi(yytext);
		  return INT;
		}

[+-]?{D}+"."?({E})? |
[+-]?{D}*"."{D}+({E})? { // Real Number
		  rgblval->real = atof(yytext);
		  return REAL;
		}

[0-9A-Za-z]+	{ // General String
		  int ll = yyleng <(LUTBUFSIZE-1) ? yyleng:(LUTBUFSIZE-1);
		  strncpy(rgblval->str,yytext,ll);
	          rgblval->str[ll] = '\0';
		  return STRING;
		}

[ \t]+		{ // White Spaces
		} 

\r\n		{ // windows line feed
		  return '\n';
		}

\n		{ // linefeed
		  return '\n';
		}

<<EOF>>		{ // eof
		  return EOF_;
		}

.		{ // Else, return the char
		  return toupper(yytext[0]);
		}

%%

void rgbDiscard(int doit)
{
  if (rgblexx)
    rgblexx->begin(DISCARD, doit);
}

void rgbFlexLexer::begin(int which, int doit)
{
  BEGIN which;
  if (doit)
    yyless(0);
}