123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174(*
* This file is part of the Watson Conversation Service OCaml API project.
*
* Copyright 2016-2017 IBM Corporation
*
* Licensed 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.
*)(** Spel lexer. *)openSpel_utilopenSpel_parser_jletkeyword_table=lettbl=Hashtbl.create37inbeginList.iter(fun(key,data)->Hashtbl.addtblkeydata)["or",OR;"and",AND;"not",NOT;"true",TRUE;"false",FALSE;"null",NULL;"new",NEW;"anything_else",ANYTHING_ELSE;"context",CONTEXT;"conversation_start",CONVERSATION_START;"entities",ENTITIES;"input",INPUT;"intents",INTENTS;"output",OUTPUT;];tblendletuident=[%sedlex.regexp?Plus(id_continue|'-')]letuintent=[%sedlex.regexp?Plus(id_continue|'-')]letnewline=[%sedlex.regexp?('\010'|'\013'|"\013\010")]letletter=[%sedlex.regexp?'A'..'Z'|'a'..'z'|'_']letident_char=[%sedlex.regexp?'A'..'Z'|'a'..'z'|'_'|'-'|'\''|'0'..'9']letident=[%sedlex.regexp?(letter,Starident_char)]letdigit=[%sedlex.regexp?'0'..'9']letfrac=[%sedlex.regexp?'.',Stardigit]letexp=[%sedlex.regexp?('e'|'E'),('-'|'+'),Plusdigit]letinteg=[%sedlex.regexp?Stardigit]letfloat=[%sedlex.regexp?Stardigit,((frac,Optexp)|exp)]letrectokensbufflexbuf=letbuf=lexbuf.streaminbeginmatch%sedlexbufwith|eof->EOF""|"=="->EQUALEQUAL|"!="->NOTEQUAL|"<"->LT|"<="->LTEQ|">"->GT|">="->GTEQ|"&&"->AND|"||"->OR|"!"->NOT|"."->DOT|"?"->QUESTION|":"->COLON|","->COMMA|"("->LPAREN|")"->RPAREN|"{"->LCURL|"}"->RCURL|"["->LBRACKET|"]"->RBRACKET|"+"->PLUS|"-"->MINUS|"*"->MULT|"/"->DIV|"%"->MOD|' '|'\t'->tokensbufflexbuf|newline->(* Sedlexing.new_line lexbuf; *)tokensbufflexbuf|float->REAL(float_of_string(Sedlexing.Utf8.lexemebuf))|integ->INT(int_of_string(Sedlexing.Utf8.lexemebuf))|'"'->reset_stringsbuff;STRING(stringsbufflexbuf)|"'"->reset_stringsbuff;STRING(qstringsbufflexbuf)|"#"->intentsbufflexbuf|"@"->ENTITY(colon_identsbufflexbuf)|"$"->VAR(colon_identsbufflexbuf)|ident->lets=Sedlexing.Utf8.lexemebufinbegintryHashtbl.findkeyword_table(String.lowercases)[@ocaml.warning"-3"]withNot_found->IDENTsend|"?>"->reset_stringsbuff;CLOSEEXPR|any->failwith"Unexpected character"|_->failwith"Unexpected character"endandintentsbufflexbuf=letbuf=lexbuf.streaminbeginmatch%sedlexbufwith|uintent->INTENT(Sedlexing.Utf8.lexemebuf)|_->failwith"Unexpected character after"endandcolon_identsbufflexbuf=letbuf=lexbuf.streaminbeginmatch%sedlexbufwith|uident->colon_ident_restsbuff(Sedlexing.Utf8.lexemebuf)lexbuf|_->failwith"Unexpected character after"endandcolon_ident_restsbuffcolon_ident_namelexbuf=letbuf=lexbuf.streaminbeginmatch%sedlexbufwith|':',uident->lettoken=Sedlexing.Utf8.lexemebufinletident=String.subtoken1((String.lengthtoken)-1)in(colon_ident_name,Someident)|':','('->reset_stringsbuff;(colon_ident_name,Some(qparensbufflexbuf))|_->(colon_ident_name,None)endandstringsbufflexbuf=letbuf=lexbuf.streaminbeginmatch%sedlexbufwith|'"'->get_stringsbuff|any->add_string_to_stringsbuff(Sedlexing.Utf8.lexemebuf);stringsbufflexbuf|_->failwith"Unexpected character"endandqstringsbufflexbuf=letbuf=lexbuf.streaminbeginmatch%sedlexbufwith|"'"->get_stringsbuff|any->add_string_to_stringsbuff(Sedlexing.Utf8.lexemebuf);qstringsbufflexbuf|_->failwith"Unexpected character"endandqparensbufflexbuf=letbuf=lexbuf.streaminbeginmatch%sedlexbufwith|")"->get_stringsbuff|any->add_string_to_stringsbuff(Sedlexing.Utf8.lexemebuf);qparensbufflexbuf|_->failwith"Unexpected character"endandbodysbufflexbuf=letbuf=lexbuf.streaminbeginmatch%sedlexbufwith|"\\$"->add_string_to_stringsbuff"\\$";bodysbufflexbuf|"$"->lets=get_stringsbuffinreset_stringsbuff;body_variablesbuffslexbuf|eof->lets=get_stringsbuffinEOFs(* End of string *)|"<?"->lets=get_stringsbuffinreset_stringsbuff;OPENEXPRs(* End of string *)|any->add_string_to_stringsbuff(Sedlexing.Utf8.lexemebuf);bodysbufflexbuf|_->failwith"Unexpected character"endandbody_variablesbuffslexbuf=letbuf=lexbuf.streaminbeginmatch%sedlexbufwith|uident->BODYVAR(s,colon_ident_restsbuff(Sedlexing.Utf8.lexemebuf)lexbuf)|_->add_string_to_stringsbuff"$";bodysbufflexbufend