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