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