%{ /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ // on some systems, won't find an EOF definition #ifndef EOF #define EOF (-1) #endif #include "AvroYacc.hh" // this undef is a hack for my mac implementation #undef yyFlexLexer #include "Compiler.hh" #define YY_STACK_USED 1 using std::cin; using std::cout; using std::cerr; %} %option c++ %option noyywrap %{ int yylex(int *val, void *ctx) { avro::CompilerContext *c = static_cast(ctx); int ret = c->lexer().yylex(); if( ret > AVRO_LEX_OUTPUT_TEXT_BEGIN && ret < AVRO_LEX_OUTPUT_TEXT_END ) { c->setText( c->lexer().YYText()) ; } return ret; } %} %x READTYPE %x STARTTYPE %x STARTSCHEMA %x READNAME %x READFIELD %x READFIELDS %x READFIELDNAME %x READSYMBOLS %x READSYMBOL %x READSIZE %x INUNION %x INOBJECT %x READMETADATA %x SKIPJSONSTRING %x SKIPJSONARRAY %x SKIPJSONOBJECT ws [ \t\r\n] nonws [^ \t\r\n] delim {ws}*:{ws}* avrotext [a-zA-Z_][a-zA-Z0-9_.]* startunion \[ startobject \{ integer [0-9]+ anytext .* %% int return AVRO_LEX_INT; long return AVRO_LEX_LONG; null return AVRO_LEX_NULL; boolean return AVRO_LEX_BOOL; float return AVRO_LEX_FLOAT; double return AVRO_LEX_DOUBLE; string return AVRO_LEX_STRING; bytes return AVRO_LEX_BYTES; record return AVRO_LEX_RECORD; enum return AVRO_LEX_ENUM; map return AVRO_LEX_MAP; array return AVRO_LEX_ARRAY; fixed return AVRO_LEX_FIXED; {avrotext} return AVRO_LEX_NAMED_TYPE; \" yy_pop_state(); {avrotext} return AVRO_LEX_NAME; \" yy_pop_state(); {avrotext} return AVRO_LEX_SYMBOL; \" yy_pop_state(); {avrotext} return AVRO_LEX_FIELD_NAME; \" yy_pop_state(); \"type\"{delim} yy_push_state(STARTSCHEMA); \"name\"{delim}\" yy_push_state(READFIELDNAME); \} yy_pop_state(); return AVRO_LEX_FIELD_END; , return yytext[0]; \"{avrotext}\"+{delim} yy_push_state(READMETADATA); return AVRO_LEX_METADATA; {ws} ; \{ yy_push_state(READFIELD); return AVRO_LEX_FIELD; \] yy_pop_state(); return AVRO_LEX_FIELDS_END; , return yytext[0]; {ws} ; \" yy_push_state(READSYMBOL); , return yytext[0]; \] yy_pop_state(); return AVRO_LEX_SYMBOLS_END; {ws} ; {integer} yy_pop_state(); return AVRO_LEX_SIZE; \" yy_push_state(READTYPE); return AVRO_LEX_SIMPLE_TYPE; {startobject} yy_push_state(INOBJECT); return yytext[0]; \] yy_pop_state(); return yytext[0]; , return yytext[0]; {ws} ; \" yy_pop_state(); \\. ; [^\"\\]+ ; \} yy_pop_state(); \{ yy_push_state(SKIPJSONOBJECT); \" yy_push_state(SKIPJSONSTRING); [^\{\}\"]+ ; \] yy_pop_state(); \[ yy_push_state(SKIPJSONARRAY); \" yy_push_state(SKIPJSONSTRING); [^\[\]\"]+ ; \" yy_pop_state(); yy_push_state(SKIPJSONSTRING); \{ yy_pop_state(); yy_push_state(SKIPJSONOBJECT); \[ yy_pop_state(); yy_push_state(SKIPJSONARRAY); [^\"\{\[,\}]+ yy_pop_state(); \"type\"{delim} yy_push_state(STARTTYPE); return AVRO_LEX_TYPE; \"name\"{delim}\" yy_push_state(READNAME); \"size\"{delim} yy_push_state(READSIZE); \"items\"{delim} yy_push_state(STARTSCHEMA); return AVRO_LEX_ITEMS; \"values\"{delim} yy_push_state(STARTSCHEMA); return AVRO_LEX_VALUES; \"fields\"{delim}\[ yy_push_state(READFIELDS); return AVRO_LEX_FIELDS; \"symbols\"{delim}\[ yy_push_state(READSYMBOLS); return AVRO_LEX_SYMBOLS; , return yytext[0]; \} yy_pop_state(); return yytext[0]; \"{avrotext}+\"{delim} yy_push_state(READMETADATA); return AVRO_LEX_METADATA; {ws} ; \" yy_pop_state(); yy_push_state(READTYPE); {startunion} yy_pop_state(); yy_push_state(INUNION); return yytext[0]; {startobject} yy_pop_state(); yy_push_state(INOBJECT); return yytext[0]; \" yy_pop_state(); yy_push_state(READTYPE); return AVRO_LEX_SIMPLE_TYPE; {startunion} yy_pop_state(); yy_push_state(INUNION); return yytext[0]; {startobject} yy_pop_state(); yy_push_state(INOBJECT); return yytext[0]; {startobject} yy_push_state(INOBJECT); return yytext[0]; {startunion} yy_push_state(INUNION); return yytext[0]; \" yy_push_state(READTYPE); return AVRO_LEX_SIMPLE_TYPE; {ws} ; <> { #if !YY_FLEX_SUBMINOR_VERSION || YY_FLEX_SUBMINOR_VERSION < 27 // The versions of flex before 3.5.27 do not free their stack when done, so explcitly free it. // Note that versions before did not actually define a subminor macro. if (yy_start_stack) { yy_flex_free(yy_start_stack); yy_start_stack = 0; } #endif #if YY_FLEX_SUBMINOR_VERSION > 35 // At this time, 3.5.35 is the latest version. #warning "Warning: untested version of flex" #endif #if YY_FLEX_SUBMINOR_VERSION >= 31 && YY_FLEX_SUBMINOR_VERSION < 34 // The versions of flex starting 3.5.31 do not free yy_buffer_stack, so do so // explicitly (first yy_delete_buffer must be called to free pointers stored on the stack, then it is // safe to remove the stack). This was fixed in 3.4.34. if(yy_buffer_stack) { yy_delete_buffer(YY_CURRENT_BUFFER); yyfree(yy_buffer_stack); yy_buffer_stack = 0; } #endif yyterminate(); } %%