1072N/A/*
1072N/A * CDDL HEADER START
1072N/A *
1072N/A * The contents of this file are subject to the terms of the
1072N/A * Common Development and Distribution License (the "License").
1072N/A * You may not use this file except in compliance with the License.
1072N/A *
1072N/A * See LICENSE.txt included in this distribution for the specific
1072N/A * language governing permissions and limitations under the License.
1072N/A *
1072N/A * When distributing Covered Code, include this CDDL HEADER in each
1072N/A * file and include the License file at LICENSE.txt.
1072N/A * If applicable, add the following below this CDDL HEADER, with the
1072N/A * fields enclosed by brackets "[]" replaced with your own identifying
1072N/A * information: Portions Copyright [yyyy] [name of copyright owner]
1072N/A *
1072N/A * CDDL HEADER END
1072N/A */
1072N/A
1072N/A/*
1072N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
1072N/A */
1072N/A
1072N/A/*
1072N/A * Cross reference a Perl file
1072N/A */
1072N/A
1072N/Apackage org.opensolaris.opengrok.analysis.perl;
1072N/Aimport org.opensolaris.opengrok.analysis.JFlexXref;
1072N/Aimport java.io.IOException;
1072N/Aimport java.io.Writer;
1072N/Aimport java.io.Reader;
1072N/Aimport org.opensolaris.opengrok.web.Util;
1072N/A
1072N/A%%
1072N/A%public
1072N/A%class PerlXref
1072N/A%extends JFlexXref
1072N/A%unicode
1072N/A%ignorecase
1072N/A%int
1072N/A%{
1072N/A // TODO move this into an include file when bug #16053 is fixed
1072N/A @Override
1072N/A protected int getLineNumber() { return yyline; }
1072N/A @Override
1072N/A protected void setLineNumber(int x) { yyline = x; }
1072N/A%}
1072N/A
1072N/AWhiteSpace = [ \t\f]+
1072N/AEOL = \r|\n|\r\n
1072N/AIdentifier = [a-zA-Z_] [a-zA-Z0-9_]+
1072N/A
1072N/AURIChar = [\?\+\%\&\:\/\.\@\_\;\=\$\,\-\!\~\*\\]
1072N/AFNameChar = [a-zA-Z0-9_\-\.]
1072N/AFile = [a-zA-Z]{FNameChar}* "." ("pl"|"perl"|"pm"|"conf"|"txt"|"htm"|"html"|"xml"|"ini"|"diff"|"patch")
1072N/APath = "/"? [a-zA-Z]{FNameChar}* ("/" [a-zA-Z]{FNameChar}*[a-zA-Z0-9])+
1072N/A
1073N/ANumber = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9][0-9_]*)([eE][+-]?[0-9]+)?
1072N/A
1072N/APods = "=back" | "=begin" | "=end" | "=for" | "=head1" | "=head2" | "=item" | "=over" | "=pod"
1072N/APodEND = "=cut"
1072N/A
1072N/A%state STRING SCOMMENT QSTRING POD
1072N/A
1072N/A%%
1072N/A<YYINITIAL>{
1072N/A
1072N/A{Identifier} {
1072N/A String id = yytext();
1469N/A writeSymbol(id, Consts.kwd, yyline, false);
1072N/A}
1072N/A
1073N/A("$"|"@"|"%"|"&") {Identifier} {
1073N/A //we ignore keywords if the identifier starts with one of variable chars ...
1073N/A String id = yytext().substring(1);
1469N/A char c = yytext().charAt(0);
1469N/A if (c == '&') {
1469N/A out.write("&amp;");
1469N/A } else {
1469N/A out.write(c);
1469N/A }
1469N/A writeSymbol(id, null, yyline, false);
1073N/A}
1073N/A
1072N/A"<" ({File}|{Path}) ">" {
1072N/A out.write("&lt;");
1072N/A String path = yytext();
1072N/A path = path.substring(1, path.length() - 1);
1072N/A out.write("<a href=\""+urlPrefix+"path=");
1072N/A out.write(path);
1072N/A appendProject();
1072N/A out.write("\">");
1072N/A out.write(path);
1072N/A out.write("</a>");
1072N/A out.write("&gt;");
1072N/A}
1072N/A
1072N/A{Number} { out.write("<span class=\"n\">"); out.write(yytext()); out.write("</span>"); }
1072N/A
1370N/A \" { yybegin(STRING);out.write("<span class=\"s\">\""); spans.push("s"); }
1370N/A \' { yybegin(QSTRING);out.write("<span class=\"s\">\'"); spans.push("s"); }
1370N/A "#" { yybegin(SCOMMENT);out.write("<span class=\"c\">#"); spans.push("c"); }
1370N/A^ {Pods} { yybegin(POD);out.write("<span class=\"c\">"+yytext()); spans.push("c"); }
1072N/A}
1072N/A
1072N/A<POD> {
1072N/A^ {PodEND} .* / {EOL} {
1370N/A yybegin(YYINITIAL); out.write(yytext()+"</span>"); spans.pop();
1072N/A // without eol lookahead one could perhaps just use below and use yytext().trim() above ?
1072N/A //startNewLine();
1072N/A }
1072N/A}
1072N/A
1072N/A<STRING> {
1370N/A \" { yybegin(YYINITIAL); out.write("\"</span>"); spans.pop(); }
1072N/A \\\\ { out.write("\\\\"); }
1072N/A \\\" { out.write("\\\""); }
1072N/A {WhiteSpace}*{EOL} {
1370N/A yybegin(YYINITIAL); out.write("</span>"); spans.pop();
1072N/A startNewLine();
1072N/A }
1072N/A}
1072N/A
1072N/A<QSTRING> {
1072N/A "\\\\" { out.write("\\\\"); }
1072N/A "\\\'" { out.write("\\\'"); }
1072N/A \' {WhiteSpace} \' { out.write(yytext()); }
1370N/A \' { yybegin(YYINITIAL); out.write("'</span>"); spans.pop(); }
1072N/A {WhiteSpace}*{EOL} {
1370N/A yybegin(YYINITIAL); out.write("</span>"); spans.pop();
1072N/A startNewLine();
1072N/A }
1072N/A}
1072N/A
1072N/A<SCOMMENT> {
1072N/A {WhiteSpace}*{EOL} {
1370N/A yybegin(YYINITIAL); out.write("</span>"); spans.pop();
1072N/A startNewLine();
1072N/A }
1072N/A}
1072N/A
1072N/A
1072N/A<YYINITIAL, STRING, SCOMMENT, QSTRING, POD> {
1072N/A"&" {out.write( "&amp;");}
1072N/A"<" {out.write( "&lt;");}
1072N/A">" {out.write( "&gt;");}
1072N/A{WhiteSpace}*{EOL} { startNewLine(); }
1072N/A {WhiteSpace} { out.write(yytext()); }
1072N/A [!-~] { out.write(yycharat(0)); }
1072N/A . { writeUnicodeChar(yycharat(0)); }
1072N/A}
1072N/A
1072N/A<STRING, SCOMMENT, STRING, QSTRING, POD> {
1072N/A{Path}
1072N/A { out.write(Util.breadcrumbPath(urlPrefix+"path=",yytext(),'/'));}
1072N/A
1072N/A{File}
1072N/A {
1072N/A String path = yytext();
1072N/A out.write("<a href=\""+urlPrefix+"path=");
1072N/A out.write(path);
1072N/A appendProject();
1072N/A out.write("\">");
1072N/A out.write(path);
1072N/A out.write("</a>");}
1072N/A
1072N/A("http" | "https" | "ftp" ) "://" ({FNameChar}|{URIChar})+[a-zA-Z0-9/]
1072N/A {
1072N/A String url = yytext();
1072N/A out.write("<a href=\"");
1472N/A out.write(Util.uriEncodeURL(url));out.write("\">");
1469N/A out.write(Util.htmlize(url));out.write("</a>");}
1072N/A
1072N/A{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+
1072N/A {
1122N/A writeEMailAddress(yytext());
1072N/A }
1072N/A}