ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco/*
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * CDDL HEADER START
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco *
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * The contents of this file are subject to the terms of the
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * Common Development and Distribution License (the "License").
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * You may not use this file except in compliance with the License.
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco *
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * See LICENSE.txt included in this distribution for the specific
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * language governing permissions and limitations under the License.
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco *
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * When distributing Covered Code, include this CDDL HEADER in each
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * file and include the License file at LICENSE.txt.
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * If applicable, add the following below this CDDL HEADER, with the
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * fields enclosed by brackets "[]" replaced with your own identifying
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * information: Portions Copyright [yyyy] [name of copyright owner]
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco *
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * CDDL HEADER END
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco */
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco/*
4eda2f9f481542c575493b4d80a9297b6d43a032Knut Anders Hatlen * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco */
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco/*
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco * Cross reference a Javascript file
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco */
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Koscopackage org.opensolaris.opengrok.analysis.javascript;
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Koscoimport org.opensolaris.opengrok.analysis.JFlexXref;
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Koscoimport java.io.IOException;
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Koscoimport java.io.Writer;
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Koscoimport java.io.Reader;
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Koscoimport org.opensolaris.opengrok.web.Util;
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco%%
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco%public
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco%class JavaScriptXref
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco%extends JFlexXref
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco%unicode
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco%ignorecase
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco%int
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco%{
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco /* Must match WhiteSpace regex */
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco private final static String WHITE_SPACE = "[ \t\f\r]+";
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco // TODO move this into an include file when bug #16053 is fixed
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco @Override
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco protected int getLineNumber() { return yyline; }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco @Override
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco protected void setLineNumber(int x) { yyline = x; }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco%}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco/* Must match WHITE_SPACE constant */
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos KoscoWhiteSpace = [ \t\f]+
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos KoscoEOL = \r|\n|\r\n
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos KoscoIdentifier = [a-zA-Z_$] [a-zA-Z0-9_$]+
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos KoscoURIChar = [\?\+\%\&\:\/\.\@\_\;\=\$\,\-\!\~\*\\]
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos KoscoFNameChar = [a-zA-Z0-9_\-\.]
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos KoscoFile = [a-zA-Z]{FNameChar}* "." ("js"|"properties"|"props"|"xml"|"conf"|"txt"|"htm"|"html"|"ini"|"diff"|"patch")
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos KoscoPath = "/"? [a-zA-Z]{FNameChar}* ("/" [a-zA-Z]{FNameChar}*[a-zA-Z0-9])+
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos KoscoNumber = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*)?
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco%state STRING COMMENT SCOMMENT QSTRING
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco%%
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco<YYINITIAL>{
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco{Identifier} {
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco String id = yytext();
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco writeSymbol(id, Consts.kwd, yyline);
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco"<" ({File}|{Path}) ">" {
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco out.write("&lt;");
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco String path = yytext();
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco path = path.substring(1, path.length() - 1);
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco out.write("<a href=\""+urlPrefix+"path=");
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco out.write(path);
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco appendProject();
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco out.write("\">");
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco out.write(path);
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco out.write("</a>");
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco out.write("&gt;");
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco/*
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco { out.write(Util.breadcrumbPath(urlPrefix+"defs=",yytext(),'.'));}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco*/
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco{Number} { out.write("<span class=\"n\">"); out.write(yytext()); out.write("</span>"); }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco \" { yybegin(STRING);out.write("<span class=\"s\">\"");}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco \' { yybegin(QSTRING);out.write("<span class=\"s\">\'");}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco "/*" { yybegin(COMMENT);out.write("<span class=\"c\">/*");}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco "//" { yybegin(SCOMMENT);out.write("<span class=\"c\">//");}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco<STRING> {
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco \" {WhiteSpace} \" { out.write(yytext());}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco \" { yybegin(YYINITIAL); out.write("\"</span>"); }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco \\\\ { out.write("\\\\"); }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco \\\" { out.write("\\\""); }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco<QSTRING> {
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco "\\\\" { out.write("\\\\"); }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco "\\\'" { out.write("\\\'"); }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco \' {WhiteSpace} \' { out.write(yytext()); }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco \' { yybegin(YYINITIAL); out.write("'</span>"); }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco<COMMENT> {
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco"*/" { yybegin(YYINITIAL); out.write("*/</span>"); }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco<SCOMMENT> {
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco {WhiteSpace}*{EOL} {
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco yybegin(YYINITIAL); out.write("</span>");
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco startNewLine();
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco"&" {out.write( "&amp;");}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco"<" {out.write( "&lt;");}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco">" {out.write( "&gt;");}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco{WhiteSpace}*{EOL} { startNewLine(); }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco {WhiteSpace} { out.write(yytext()); }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco [!-~] { out.write(yycharat(0)); }
474ac6921d21d2e44cf9c1e91f17d6bcbb15c9e8Lubos Kosco [^\n] { writeUnicodeChar(yycharat(0)); }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco<STRING, COMMENT, SCOMMENT, STRING, QSTRING> {
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco{Path}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco { out.write(Util.breadcrumbPath(urlPrefix+"path=",yytext(),'/'));}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco{File}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco {
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco String path = yytext();
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco out.write("<a href=\""+urlPrefix+"path=");
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco out.write(path);
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco appendProject();
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco out.write("\">");
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco out.write(path);
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco out.write("</a>");}
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco("http" | "https" | "ftp" ) "://" ({FNameChar}|{URIChar})+[a-zA-Z0-9/]
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco {
4eda2f9f481542c575493b4d80a9297b6d43a032Knut Anders Hatlen appendLink(yytext());
4eda2f9f481542c575493b4d80a9297b6d43a032Knut Anders Hatlen }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco {
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco writeEMailAddress(yytext());
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco }
ecc9697029dc3bde02537b914756f7c49eb7cd1eLubos Kosco}