summaryrefslogtreecommitdiffstats
path: root/tksao/fitsy++/lex.L
blob: a25e7be22a0054643b213bca7b87b0ae8e375914 (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
/* 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 "parser.H"

  extern YYSTYPE* fflval;
  extern ffFlexLexer* fflexx;

  extern char ff_filter[];
  #define RET(x) {strcat(ff_filter,yytext);return x;}
  #define CLEARFILTER {ff_filter[0]='\0';}
%}

%x EXT
%x FILTER
%x ARRAY

/* rules */

%%

[^[\]\t]+	{ // File
		  strcpy(fflval->str,yytext);
		  return STRING;
		}

\[		{ // first bracket
		  BEGIN EXT;
		  CLEARFILTER
		  return yytext[0];
		}

[ \t]+		{ // White Spaces
		} 

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

<EXT>{

arch		{RET(ARCH_)}
array		{RET(ARRAY_)}
big	        {RET(BIG_)}
bigendian	{RET(BIGENDIAN_)}
bin		{RET(BIN_)}
binkey		{RET(BINKEY_)}
bincol		{RET(BINCOL_)}
bitpix		{RET(BITPIX_)}
col		{RET(COL_)}
dim		{RET(DIM_)}
dims		{RET(DIMS_)}
ecliptic	{RET(ECLIPTIC_)}
endian          {RET(ENDIAN_)}
equatorial	{RET(EQUATORIAL_)}
galactic	{RET(GALACTIC_)}
key		{RET(KEY_)}
layout		{RET(LAYOUT_)}
little   	{RET(LITTLE_)}
littleendian	{RET(LITTLEENDIAN_)}
nested		{RET(NESTED_)}
north		{RET(NORTH_)}
order		{RET(ORDER_)}
quad		{RET(QUAD_)}
ring		{RET(RING_)}
skip		{RET(SKIP_)}
south		{RET(SOUTH_)}
system		{RET(SYSTEM_)}
unknown		{RET(UNKNOWN_)}
xdim		{RET(XDIM_)}
ydim		{RET(YDIM_)}
zdim		{RET(ZDIM_)}

[-+]?[0-9]+	{ // Integer
		  fflval->integer = atoi(yytext);
		  RET(INT)
		}

[0-9A-Za-z_.-]+	{ // Extn/Col Name
		  strcpy(fflval->str,yytext);
		  RET(STRING)
		}

\[		{ // bracket
		  CLEARFILTER
		  return yytext[0];
		}

,		{ // comma
		  CLEARFILTER
		  return yytext[0];
		}

[ \t]+		{ // White Spaces
		  strcat(ff_filter,yytext); 
		} 

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

}

<FILTER>.*	{  // rest of Filter
		  strcpy(fflval->str,yytext);
	          fflval->str[yyleng-1] = '\0'; // Remove the ']'
		  strcat(ff_filter,fflval->str);
		  return STRING;
		}

<ARRAY>{

[-+]?[0-9]+	{ // Integer
		  fflval->integer = atoi(yytext);
		  return INT;
		}

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

}

%%

void ffFilter(int doit)
{
  if (fflexx)
    fflexx->begin(FILTER, doit);
}

void ffArray(int doit)
{
  if (fflexx)
    fflexx->begin(ARRAY, doit);
}

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