summaryrefslogtreecommitdiffstats
path: root/tksao/fitsy++/nrrdlex.L
blob: 8acfa2dad3b5f72ab9b9ae0748522af37258c256 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/* Copyright (C) 1999-2016
 * 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 "util.h"
  #include "nrrdparser.H"

  extern YYSTYPE* nrrdlval;
  extern nrrdFlexLexer* nrrdlexx;
%}

%x DISCARD

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

/* rules */

%%

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

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

debug           {return DEBUG_;}
on              {return ON_;}
off             {return OFF_;}

NRRD0001         {return NRRD0001_;}
NRRD0002         {return NRRD0002_;}
NRRD0003         {return NRRD0003_;}
NRRD0004         {return NRRD0004_;}
NRRD0005         {return NRRD0005_;}

data            {return DATA_;}
file            {return FILE_;}

space           {return SPACE_;}
units           {return UNITS_;}
dimentions      {return DIMENSIONS_;}
origin          {return ORIGIN_;}
directions      {return DIRECTIONS_;}

dimension       {return DIMENSION_;}

type            {return TYPE_;}
signed          {return SIGNED_;}
unsigned        {return UNSIGNED_;}
char            {return CHAR_;}
int8            {return INT8_;}
int8_t          {return INT8_T_;}
uchar           {return UCHAR_;}
uint8           {return UINT8_;}
uint8_t         {return UINT8_T_;}
short           {return SHORT_;}
int             {return INT_;}
int16           {return INT16_;}
int16_t         {return INT16_T_;}
ushort          {return USHORT_;}
unint16         {return UINT16_;}
unint16_t       {return UINT16_T_;}
int32           {return INT32_;}
int32_t         {return INT32_T_;}
uint            {return UINT_;}
uint32          {return UINT32_;}
uint32_t        {return UINT32_T_;}
long            {return LONG_;}
longlong        {return LONGLONG_;}
int64           {return INT64_;}
int64_t         {return INT64_T_;}
unlonglong      {return ULONGLONG_;}
unint64         {return UINT64_;}
unint64_t       {return UINT64_T_;}
float           {return FLOAT_;}
double          {return DOUBLE_;}

block           {return BLOCK_;}
size            {return SIZE_;}
blocksize       {return BLOCKSIZE_;}

encoding        {return ENCODING_;}
raw             {return RAW_;}
txt             {return TXT_;}
text            {return TEXT_;}
ascii           {return ASCII_;}
hex             {return HEX_;}
gz              {return GZ_;}
gzip            {return GZIP_;}
bz2             {return BZ2_;}
bzip2           {return BZIP2_;}

endian          {return ENDIAN_;}
big             {return BIG_;}
little          {return LITTLE_;}

content         {return CONTENT_;}

old             {return OLD_;}
min             {return MIN_;}
oldmin          {return OLDMIN_;}
max             {return MAX_;}
oldmax          {return OLDMAX_;}

skip            {return SKIP_;}
line            {return LINE_;}
lineskip        {return LINESKIP_;}
byte            {return BYTE_;}
byteskip        {return BYTESKIP_;}

number          {return NUMBER_;}

sample          {return SAMPLE_;}
sampleunits     {return SAMPLEUNITS_;}

sizes           {return SIZES_;}
spacings        {return SPACINGS_;}
thickness       {return THICKNESSES_;}
axis            {return AXIS_;}
mins            {return MINS_;}
axismins        {return AXISMINS_;}
maxs            {return MAXS_;}
axismaxs        {return AXISMAXS_;}
centers         {return CENTERS_;}
centerings      {return CENTERINGS_;}
cell            {return CELL_;}
node            {return NODE_;}
none            {return NONE_;}
labels          {return LABELS_;}
kinds           {return KINDS_;}
domains         {return DOMAINS_;}

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

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


\{[^\}\n]*\} 	{ // Quoted String
		  int ll = (yyleng-2)<(NRRDPARSERSIZE-1) ? (yyleng-2):(NRRDPARSERSIZE-1);
		  strncpy(nrrdlval->str,yytext+1,ll); // skip the '{'
	          nrrdlval->str[ll] = '\0'; // Remove the '}'
		  return STRING;
		}

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

[ \t]+		{ // White Spaces
		} 

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

\\n		{ // fake line feed
		  return '\n';
		}

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

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

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

%%

void nrrdDiscard(int doit)
{
  if (nrrdlexx)
    nrrdlexx->begin(DISCARD, doit);
}

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