/**
 * Copyright (c) 2006- Facebook
 * Distributed under the Thrift Software License
 *
 * See accompanying file LICENSE or visit the Thrift site at:
 * http://developers.facebook.com/thrift/
 */

/**
 * Thrift scanner.
 *
 * Tokenizes a thrift definition file.
 * @author Mark Slee <mcslee@facebook.com>
 */

%{

#include "main.h"
#include "globals.h"
#include "parse/t_program.h"

/**
 * Must be included AFTER parse/t_program.h, but I can't remember why anymore
 * because I wrote this a while ago.
 */
#include "thrifty.h"

void thrift_reserved_keyword(char* keyword) {
  yyerror("Cannot use reserved language keyword: \"%s\"\n", keyword);
  exit(1);
}

%}

/**
 * Provides the yylineno global, useful for debugging output
 */
%option lex-compat

/**
 * Helper definitions, comments, constants, and whatnot
 */

intconstant  ([+-]?[0-9]+)
hexconstant  ("0x"[0-9A-Fa-f]+)
dubconstant  ([+-]?[0-9]*(\.[0-9]+)?([eE][+-]?[0-9]+)?)
identifier   ([a-zA-Z_][\.a-zA-Z_0-9]*)
whitespace   ([ \t\r\n]*)
sillycomm    ("/*""*"*"*/")
multicomm    ("/*"[^*]"/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/")
doctext      ("/**"([^*/]|[^*]"/"|"*"[^/])*"*"*"*/")
comment      ("//"[^\n]*)
unixcomment  ("#"[^\n]*)
symbol       ([:;\,\{\}\(\)\=<>\[\]])
dliteral     ("\""[^"]*"\"")
sliteral     ("'"[^']*"'")


%%

{whitespace}  { /* do nothing */ }
{sillycomm}   { /* do nothing */ }
{multicomm}   { /* do nothing */ }
{comment}     { /* do nothing */ }
{unixcomment} { /* do nothing */ }

{symbol}      { return yytext[0]; }

"namespace"      { return tok_namespace;      }
"cpp_namespace"  { return tok_cpp_namespace;  }
"cpp_include"    { return tok_cpp_include;    }
"cpp_type"       { return tok_cpp_type;       }
"java_package"   { return tok_java_package;   }
"cocoa_prefix"   { return tok_cocoa_prefix;   }
"php_namespace"  { return tok_php_namespace;  }
"py_module"      { return tok_py_module;      }
"perl_package"   { return tok_perl_package;   }
"ruby_namespace" { return tok_ruby_namespace; }
"xsd_all"        { return tok_xsd_all;        }
"xsd_optional"   { return tok_xsd_optional;   }
"xsd_nillable"   { return tok_xsd_nillable;   }
"xsd_namespace"  { return tok_xsd_namespace;  }
"xsd_attrs"      { return tok_xsd_attrs;      }
"include"        { return tok_include;        }

"void"           { return tok_void;           }
"bool"           { return tok_bool;           }
"byte"           { return tok_byte;           }
"i16"            { return tok_i16;            }
"i32"            { return tok_i32;            }
"i64"            { return tok_i64;            }
"double"         { return tok_double;         }
"string"         { return tok_string;         }
"binary"         { return tok_binary;         }
"slist"          { return tok_slist;          }
"senum"          { return tok_senum;          }
"map"            { return tok_map;            }
"list"           { return tok_list;           }
"set"            { return tok_set;            }
"async"          { return tok_async;          }
"typedef"        { return tok_typedef;        }
"struct"         { return tok_struct;         }
"exception"      { return tok_xception;       }
"extends"        { return tok_extends;        }
"throws"         { return tok_throws;         }
"service"        { return tok_service;        }
"enum"           { return tok_enum;           }
"const"          { return tok_const;          }
"required"       { return tok_required;       }
"optional"       { return tok_optional;       }

"abstract" { thrift_reserved_keyword(yytext); }
"and" { thrift_reserved_keyword(yytext); }
"as" { thrift_reserved_keyword(yytext); }
"assert" { thrift_reserved_keyword(yytext); }
"break" { thrift_reserved_keyword(yytext); }
"case" { thrift_reserved_keyword(yytext); }
"class" { thrift_reserved_keyword(yytext); }
"continue" { thrift_reserved_keyword(yytext); }
"declare" { thrift_reserved_keyword(yytext); }
"def" { thrift_reserved_keyword(yytext); }
"default" { thrift_reserved_keyword(yytext); }
"del" { thrift_reserved_keyword(yytext); }
"delete" { thrift_reserved_keyword(yytext); }
"do" { thrift_reserved_keyword(yytext); }
"elif" { thrift_reserved_keyword(yytext); }
"else" { thrift_reserved_keyword(yytext); }
"elseif" { thrift_reserved_keyword(yytext); }
"except" { thrift_reserved_keyword(yytext); }
"exec" { thrift_reserved_keyword(yytext); }
"false" { thrift_reserved_keyword(yytext); }
"final" { thrift_reserved_keyword(yytext); }
"finally" { thrift_reserved_keyword(yytext); }
"float" { thrift_reserved_keyword(yytext); }
"for" { thrift_reserved_keyword(yytext); }
"foreach" { thrift_reserved_keyword(yytext); }
"function" { thrift_reserved_keyword(yytext); }
"global" { thrift_reserved_keyword(yytext); }
"goto" { thrift_reserved_keyword(yytext); }
"if" { thrift_reserved_keyword(yytext); }
"implements" { thrift_reserved_keyword(yytext); }
"import" { thrift_reserved_keyword(yytext); }
"in" { thrift_reserved_keyword(yytext); }
"inline" { thrift_reserved_keyword(yytext); }
"instanceof" { thrift_reserved_keyword(yytext); }
"interface" { thrift_reserved_keyword(yytext); }
"is" { thrift_reserved_keyword(yytext); }
"lambda" { thrift_reserved_keyword(yytext); }
"native" { thrift_reserved_keyword(yytext); }
"new" { thrift_reserved_keyword(yytext); }
"not" { thrift_reserved_keyword(yytext); }
"or" { thrift_reserved_keyword(yytext); }
"pass" { thrift_reserved_keyword(yytext); }
"public" { thrift_reserved_keyword(yytext); }
"print" { thrift_reserved_keyword(yytext); }
"private" { thrift_reserved_keyword(yytext); }
"protected" { thrift_reserved_keyword(yytext); }
"raise" { thrift_reserved_keyword(yytext); }
"return" { thrift_reserved_keyword(yytext); }
"sizeof" { thrift_reserved_keyword(yytext); }
"static" { thrift_reserved_keyword(yytext); }
"switch" { thrift_reserved_keyword(yytext); }
"synchronized" { thrift_reserved_keyword(yytext); }
"this" { thrift_reserved_keyword(yytext); }
"throw" { thrift_reserved_keyword(yytext); }
"transient" { thrift_reserved_keyword(yytext); }
"true" { thrift_reserved_keyword(yytext); }
"try" { thrift_reserved_keyword(yytext); }
"unsigned" { thrift_reserved_keyword(yytext); }
"var" { thrift_reserved_keyword(yytext); }
"virtual" { thrift_reserved_keyword(yytext); }
"volatile" { thrift_reserved_keyword(yytext); }
"while" { thrift_reserved_keyword(yytext); }
"with" { thrift_reserved_keyword(yytext); }
"union" { thrift_reserved_keyword(yytext); }
"yield" { thrift_reserved_keyword(yytext); }

{intconstant} {
  yylval.iconst = atoi(yytext);
  return tok_int_constant;
}

{hexconstant} {
  sscanf(yytext+2, "%x", &yylval.iconst);
  return tok_int_constant;
}

{dubconstant} {
  yylval.dconst = atof(yytext);
  return tok_dub_constant;
}

{identifier} {
  yylval.id = strdup(yytext);
  return tok_identifier;
}

{dliteral} {
  yylval.id = strdup(yytext+1);
  yylval.id[strlen(yylval.id)-1] = '\0';
  return tok_literal;
}

{sliteral} {
  yylval.id = strdup(yytext+1);
  yylval.id[strlen(yylval.id)-1] = '\0';
  return tok_literal;
}

{doctext} {
 /* This does not show up in the parse tree. */
 /* Rather, the parser will grab it out of the global. */
  if (g_parse_mode == PROGRAM) {
    clear_doctext();
    g_doctext = strdup(yytext + 3);
    g_doctext[strlen(g_doctext) - 2] = '\0';
    g_doctext = clean_up_doctext(g_doctext);
    g_doctext_lineno = yylineno;
  }
}


%%
