/****************************************************************** highlight.js Muze Helene ------------------------------------------------------------------ Author: Muze (info@muze.nl) Date: 28 februari 2004 Copyright 2002 Muze This file is part of Helene. Helene is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Helene is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Helene; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------- This file contains the syntax highlighting parser ******************************************************************/ // Parsing smarty tags http://smarty.php.net/ // Cofigure the smarty delimiters below ('{%' and '%}' by default) // Unset this flag if you need to parse only PHP var parseSmarty = true; /* states */ var YY_STATE_HTML = 0; var YY_STATE_PINP = 1; var YY_STATE_DQSTRING = 2; var YY_STATE_SQSTRING = 3; var YY_STATE_SCRIPT = 4; var YY_STATE_BLOCKCOMMENT = 5; /* Smarty states */ var YYS_STATE_TAG = 101; var YYS_STATE_PARAM = 102; var YYS_STATE_QPARAM = 103; /* tokens */ var T_VAR = 0; var T_IDENT = 1; var T_FUNCTION = 2; var T_TOKEN = 3; var T_UNKNOWN = 4; var T_PINP_START = 5; var T_PINP_BLOCK = 6 var T_PINP_END = 7; var T_SPACE = 8; var T_DQUOTE = 9 var T_SQUOTE = 10; var T_ESCAPE = 11; var T_SPECIAL_CHAR = 12; var T_OPERATOR = 13; var T_SINGLE_COMMENTS = 14; var T_BLOCKCOMMENT = 15; var T_BLOCKCOMMENT_END = 16; var T_PHP_START = 17; var T_PHP_END = 18; var T_SCRIPT_START = 19; var T_SCRIPT_END = 20; var T_TAB = 21; /*Smarty tokens*/ var TS_SMARTY_START = 101; var TS_SMARTY_END = 102; var TS_KEYWORD = 103; var TS_ATTRIBUTE = 104; var TS_ATTRVALUE = 105; var TS_VAR = 106; var TS_ENDTAG = 107; var hLines = new Array(); var debug = 0; var scannerPos = 0; var hStyles = new Array(); var hStateStyles = new Array(); // May be there is the better place for it but now there initStyleDefault(); // Making object from keywords, it makes a big perfomance overhead in IE // and slightly better perfomance in Mozilla // You can define any amount of keyword groups // Words should match ([a-z0-9][a-z0-9_]*) and should be separated by spaces var hPHPKeywords = cacheKeywords( /// TODO: Add more keywords here "if foreach else elseif function class new", // language constructs "echo print count array" // standart functions ); var hSmartyKeywords = cacheKeywords( "if foreach capture section", // Block keywords "include assign math counter else foreachelse sectionelse cycle elseif", // Other keywords "getprices getarticles" // Own plugins for smarty ); function hLineToken(tokenType, tokenData) { this.type = tokenType; this.data = tokenData; this.reallength = tokenData.length; this.newState = -1; switch (this.data) { case '<': this.data='<'; break; case '>': this.data='>'; break; case '&': this.data='&'; break; } switch (this.type) { case T_PINP_START: case T_PHP_START: case T_PINP_END: case T_PHP_END: case T_SCRIPT_START: case T_SCRIPT_END: this.data = this.data.replace(/[<]/g, '<'); this.data = this.data.replace(/[>]/g, '>'); case T_SPACE: this.data = this.data.replace(/[ ]/g, ' '); break; case T_TAB: var myTabRest = scannerPos % 8; var addLength = 8 - myTabRest; // alert( 'scannerPos ' + scannerPos + ' myTabRest ' + myTabRest + ' addLength ' + addLength); this.data = this.data.replace(/[t]/g, ''); scannerPos += (addLength -1); break; } scannerPos += tokenData.length; } function getToken(sData) { var re, match; /* white space */ re = /^([ ]+)/; match = re.exec(sData); if (match) { result = new hLineToken(T_SPACE, match[1]); return result; } re = /^([t])/; match = re.exec(sData); if (match) { result = new hLineToken(T_TAB, match[1]); return result; } /* Smarty tokens */ if(parseSmarty) { re = /^{%/; // Matches $smarty->left_delimiter match = re.exec(sData); if(match) { return new hLineToken(TS_SMARTY_START, match[0]); } re = /^%}/; // Matches $smarty->right_delimiter match = re.exec(sData); if(match) { return new hLineToken(TS_SMARTY_END, match[0]); } re = /^/[a-z0-9][a-z0-9_]*/i; match = re.exec(sData); if (match) { result = new hLineToken(TS_ENDTAG, match[0]); return result; } } /* end of smarty tokens */ /* variable or ident */ re = /^([$]|->)?([a-z0-9][a-z0-9_]*)/i; match = re.exec(sData); if (match) { if (match[1]) { result = new hLineToken(T_VAR, match[0]); } else { result = new hLineToken(T_IDENT, match[2]); } return result; } /* single tokens */ re = /^([(){},"'\])/; match = re.exec(sData); if (match) { switch (match[1]) { case '\': result = new hLineToken(T_ESCAPE, match[1]); break; case '"': result = new hLineToken(T_DQUOTE, match[1]); break; case "'": result = new hLineToken(T_SQUOTE, match[1]); break; default: result = new hLineToken(T_SPECIAL_CHAR, match[1]); break; } return result; } re = /^((/[*])|([*]/))/; match = re.exec(sData); if (match) { if (match[2]) { result = new hLineToken(T_BLOCKCOMMENT, match[2]); } else { result = new hLineToken(T_BLOCKCOMMENT_END, match[3]); } return result; } /* comments */ re = /^(//.*)/; match = re.exec(sData); if (match) { result = new hLineToken(T_SINGLE_COMMENTS, match[1]); return result; } /* php end tags */ re = /^([?%]>)/; match = re.exec(sData); if (match) { result = new hLineToken(T_PHP_END, match[0]); return result; } re = /^([-+.*/=%])/; match = re.exec(sData); if (match) { result = new hLineToken(T_OPERATOR, match[1]); return result; } /* pinp/php tags */ re = /^((<(/)?pinp>)|(<[%?]php||
-
|
|