1%{ 2/* 3 Licensed to the Apache Software Foundation (ASF) under one 4 or more contributor license agreements. See the NOTICE file 5 distributed with this work for additional information 6 regarding copyright ownership. The ASF licenses this file 7 to you under the Apache License, Version 2.0 (the 8 "License"); you may not use this file except in compliance 9 with the License. You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18*/ 19 20// on some systems, won't find an EOF definition 21#ifndef EOF 22#define EOF (-1) 23#endif 24 25#include "AvroYacc.hh" 26 27// this undef is a hack for my mac implementation 28#undef yyFlexLexer 29#include "Compiler.hh" 30 31#define YY_STACK_USED 1 32 33using std::cin; 34using std::cout; 35using std::cerr; 36 37%} 38 39%option c++ 40%option noyywrap 41 42%{ 43 44int yylex(int *val, void *ctx) 45{ 46 avro::CompilerContext *c = static_cast<avro::CompilerContext *>(ctx); 47 int ret = c->lexer().yylex(); 48 if( ret > AVRO_LEX_OUTPUT_TEXT_BEGIN && ret < AVRO_LEX_OUTPUT_TEXT_END ) { 49 c->setText( c->lexer().YYText()) ; 50 } 51 return ret; 52} 53 54%} 55 56%x READTYPE 57%x STARTTYPE 58%x STARTSCHEMA 59%x READNAME 60%x READFIELD 61%x READFIELDS 62%x READFIELDNAME 63%x READSYMBOLS 64%x READSYMBOL 65%x READSIZE 66%x INUNION 67%x INOBJECT 68%x READMETADATA 69%x SKIPJSONSTRING 70%x SKIPJSONARRAY 71%x SKIPJSONOBJECT 72 73ws [ \t\r\n] 74nonws [^ \t\r\n] 75delim {ws}*:{ws}* 76avrotext [a-zA-Z_][a-zA-Z0-9_.]* 77startunion \[ 78startobject \{ 79integer [0-9]+ 80anytext .* 81 82%% 83<READTYPE>int return AVRO_LEX_INT; 84<READTYPE>long return AVRO_LEX_LONG; 85<READTYPE>null return AVRO_LEX_NULL; 86<READTYPE>boolean return AVRO_LEX_BOOL; 87<READTYPE>float return AVRO_LEX_FLOAT; 88<READTYPE>double return AVRO_LEX_DOUBLE; 89<READTYPE>string return AVRO_LEX_STRING; 90<READTYPE>bytes return AVRO_LEX_BYTES; 91<READTYPE>record return AVRO_LEX_RECORD; 92<READTYPE>enum return AVRO_LEX_ENUM; 93<READTYPE>map return AVRO_LEX_MAP; 94<READTYPE>array return AVRO_LEX_ARRAY; 95<READTYPE>fixed return AVRO_LEX_FIXED; 96<READTYPE>{avrotext} return AVRO_LEX_NAMED_TYPE; 97<READTYPE>\" yy_pop_state(); 98 99<READNAME>{avrotext} return AVRO_LEX_NAME; 100<READNAME>\" yy_pop_state(); 101 102<READSYMBOL>{avrotext} return AVRO_LEX_SYMBOL; 103<READSYMBOL>\" yy_pop_state(); 104 105<READFIELDNAME>{avrotext} return AVRO_LEX_FIELD_NAME; 106<READFIELDNAME>\" yy_pop_state(); 107 108<READFIELD>\"type\"{delim} yy_push_state(STARTSCHEMA); 109<READFIELD>\"name\"{delim}\" yy_push_state(READFIELDNAME); 110<READFIELD>\} yy_pop_state(); return AVRO_LEX_FIELD_END; 111<READFIELD>, return yytext[0]; 112<READFIELD>\"{avrotext}\"+{delim} yy_push_state(READMETADATA); return AVRO_LEX_METADATA; 113<READFIELD>{ws} ; 114 115<READFIELDS>\{ yy_push_state(READFIELD); return AVRO_LEX_FIELD; 116<READFIELDS>\] yy_pop_state(); return AVRO_LEX_FIELDS_END; 117<READFIELDS>, return yytext[0]; 118<READFIELDS>{ws} ; 119 120<READSYMBOLS>\" yy_push_state(READSYMBOL); 121<READSYMBOLS>, return yytext[0]; 122<READSYMBOLS>\] yy_pop_state(); return AVRO_LEX_SYMBOLS_END; 123<READSYMBOLS>{ws} ; 124 125<READSIZE>{integer} yy_pop_state(); return AVRO_LEX_SIZE; 126 127<INUNION>\" yy_push_state(READTYPE); return AVRO_LEX_SIMPLE_TYPE; 128<INUNION>{startobject} yy_push_state(INOBJECT); return yytext[0]; 129<INUNION>\] yy_pop_state(); return yytext[0]; 130<INUNION>, return yytext[0]; 131<INUNION>{ws} ; 132 133<SKIPJSONSTRING>\" yy_pop_state(); 134<SKIPJSONSTRING>\\. ; 135<SKIPJSONSTRING>[^\"\\]+ ; 136 137<SKIPJSONOBJECT>\} yy_pop_state(); 138<SKIPJSONOBJECT>\{ yy_push_state(SKIPJSONOBJECT); 139<SKIPJSONOBJECT>\" yy_push_state(SKIPJSONSTRING); 140<SKIPJSONOBJECT>[^\{\}\"]+ ; 141 142<SKIPJSONARRAY>\] yy_pop_state(); 143<SKIPJSONARRAY>\[ yy_push_state(SKIPJSONARRAY); 144<SKIPJSONARRAY>\" yy_push_state(SKIPJSONSTRING); 145<SKIPJSONARRAY>[^\[\]\"]+ ; 146 147<READMETADATA>\" yy_pop_state(); yy_push_state(SKIPJSONSTRING); 148<READMETADATA>\{ yy_pop_state(); yy_push_state(SKIPJSONOBJECT); 149<READMETADATA>\[ yy_pop_state(); yy_push_state(SKIPJSONARRAY); 150<READMETADATA>[^\"\{\[,\}]+ yy_pop_state(); 151 152<INOBJECT>\"type\"{delim} yy_push_state(STARTTYPE); return AVRO_LEX_TYPE; 153<INOBJECT>\"name\"{delim}\" yy_push_state(READNAME); 154<INOBJECT>\"size\"{delim} yy_push_state(READSIZE); 155<INOBJECT>\"items\"{delim} yy_push_state(STARTSCHEMA); return AVRO_LEX_ITEMS; 156<INOBJECT>\"values\"{delim} yy_push_state(STARTSCHEMA); return AVRO_LEX_VALUES; 157<INOBJECT>\"fields\"{delim}\[ yy_push_state(READFIELDS); return AVRO_LEX_FIELDS; 158<INOBJECT>\"symbols\"{delim}\[ yy_push_state(READSYMBOLS); return AVRO_LEX_SYMBOLS; 159<INOBJECT>, return yytext[0]; 160<INOBJECT>\} yy_pop_state(); return yytext[0]; 161<INOBJECT>\"{avrotext}+\"{delim} yy_push_state(READMETADATA); return AVRO_LEX_METADATA; 162<INOBJECT>{ws} ; 163 164<STARTTYPE>\" yy_pop_state(); yy_push_state(READTYPE); 165<STARTTYPE>{startunion} yy_pop_state(); yy_push_state(INUNION); return yytext[0]; 166<STARTTYPE>{startobject} yy_pop_state(); yy_push_state(INOBJECT); return yytext[0]; 167 168<STARTSCHEMA>\" yy_pop_state(); yy_push_state(READTYPE); return AVRO_LEX_SIMPLE_TYPE; 169<STARTSCHEMA>{startunion} yy_pop_state(); yy_push_state(INUNION); return yytext[0]; 170<STARTSCHEMA>{startobject} yy_pop_state(); yy_push_state(INOBJECT); return yytext[0]; 171 172{startobject} yy_push_state(INOBJECT); return yytext[0]; 173{startunion} yy_push_state(INUNION); return yytext[0]; 174\" yy_push_state(READTYPE); return AVRO_LEX_SIMPLE_TYPE; 175{ws} ; 176<<EOF>> { 177#if !YY_FLEX_SUBMINOR_VERSION || YY_FLEX_SUBMINOR_VERSION < 27 178// The versions of flex before 3.5.27 do not free their stack when done, so explcitly free it. 179// Note that versions before did not actually define a subminor macro. 180 if (yy_start_stack) { 181 yy_flex_free(yy_start_stack); 182 yy_start_stack = 0; 183 } 184#endif 185#if YY_FLEX_SUBMINOR_VERSION > 35 186// At this time, 3.5.35 is the latest version. 187#warning "Warning: untested version of flex" 188#endif 189#if YY_FLEX_SUBMINOR_VERSION >= 31 && YY_FLEX_SUBMINOR_VERSION < 34 190// The versions of flex starting 3.5.31 do not free yy_buffer_stack, so do so 191// explicitly (first yy_delete_buffer must be called to free pointers stored on the stack, then it is 192// safe to remove the stack). This was fixed in 3.4.34. 193 if(yy_buffer_stack) { 194 yy_delete_buffer(YY_CURRENT_BUFFER); 195 yyfree(yy_buffer_stack); 196 yy_buffer_stack = 0; 197 } 198#endif 199 yyterminate(); 200 } 201 202%% 203 204