/* * phptok.l - a lex rule for PHP * * Copyright (C) 2005 MATSUNO Tokuhiro * All rights reserved. * This is free software with ABSOLUTELY NO WARRANTY. * * You can redistribute it and/or modify it under the terms of * the GNU General Public License version 2. */ %option reentrant %option prefix="langscan_php_lex_" %option noyywrap %option nodefault %x CLASSDEF %x FUNDEF %x SCRIPT %x HEREDOC %x HEREDOCBEG newline (\r\n|\r|\n) escseq \\. string '([^\\\']|{escseq})*'|\"([^\\\"]|{escseq})*\" integer 0x[0-9a-fA-F]+|[0-9]+ pointfloat [0-9]*\.[0-9]+|[0-9]+\.[0-9]* exponent [eE][+\-][0-9]+ ident [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* floatnumber {pointfloat}{exponent}?|[0-9]+{exponent} space [ \t\r\n] slash \/ star \* nonstar [^\*] nonslashstar [^\/\*] commentcontent {star}+{nonslashstar}{nonstar}* mullinecomment {slash}{star}{nonstar}*{commentcontent}*{star}+{slash} %{ #include "php.h" #define YY_EXTRA_TYPE langscan_php_lex_extra_t * #if YY_NULL != 0 #error "YY_NULL is not 0." #endif #define YY_DECL langscan_php_token_t langscan_php_lex_lex(yyscan_t yyscanner) #define YY_INPUT(buf,result,max_size) \ if (!yyextra->eof) { \ result = yyextra->user_read(&(yyextra->user_data), (buf), (max_size)); \ if (result == 0) \ yyextra->eof = 1; \ } #define UPD update_pos(yyextra, yytext, yyleng) static void update_pos(langscan_php_lex_extra_t *, char *, int); #define report(token) \ do { \ yyextra->text = yytext; \ yyextra->leng = yyleng; \ return langscan_php_##token; \ } while (0) char *heredocident=NULL; int heredocidentlen=0; %} %% " { UPD; BEGIN(SCRIPT); report(ident);} <%=?|""([^<]|<[^?s%])+ { UPD; report(comment);} . { UPD; report(comment);} {ident};?{newline} { int identlen = strpbrk(yytext, ";\r\n")-yytext; if (heredocidentlen==identlen && !strncmp(heredocident, yytext, identlen)) { free(heredocident); heredocident = NULL; BEGIN(SCRIPT); yyless(0); } else { UPD; report(string); } } [^\r\n]*{newline} { UPD; report(string);} [ \t]* { UPD; report(space); } {ident} { UPD; heredocident=strdup(yytext); heredocidentlen=yyleng; report(ident); } {newline} { UPD; if(heredocident) { BEGIN(HEREDOC); report(space); } else { /* invalid here-document */ BEGIN(SCRIPT); report(space); } }