33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist/*
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * CDDL HEADER START
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist *
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * The contents of this file are subject to the terms of the
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * Common Development and Distribution License (the "License").
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * You may not use this file except in compliance with the License.
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist *
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * See LICENSE.txt included in this distribution for the specific
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * language governing permissions and limitations under the License.
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist *
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * When distributing Covered Code, include this CDDL HEADER in each
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * file and include the License file at LICENSE.txt.
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * If applicable, add the following below this CDDL HEADER, with the
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * fields enclosed by brackets "[]" replaced with your own identifying
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * information: Portions Copyright [yyyy] [name of copyright owner]
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist *
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * CDDL HEADER END
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist */
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist/*
4eda2f9f481542c575493b4d80a9297b6d43a032Knut Anders Hatlen * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist */
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist/*
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * Cross reference a Golang file
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist */
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquistpackage org.opensolaris.opengrok.analysis.golang;
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquistimport org.opensolaris.opengrok.analysis.JFlexXref;
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquistimport org.opensolaris.opengrok.web.Util;
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist/**
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist * @author Patrick Lundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist */
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist%%
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist%public
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist%class GolangXref
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist%extends JFlexXref
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist%unicode
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist%ignorecase
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist%int
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist%{
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist // TODO move this into an include file when bug #16053 is fixed
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist @Override
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist protected int getLineNumber() { return yyline; }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist @Override
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist protected void setLineNumber(int x) { yyline = x; }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist%}
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquistWhiteSpace = [ \t\f]+
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquistEOL = \r|\n|\r\n
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquistIdentifier = [a-zA-Z_] [a-zA-Z0-9_']*
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquistFNameChar = [a-zA-Z0-9_\-\.]
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquistURIChar = [\?\+\%\&\:\/\.\@\_\;\=\$\,\-\!\~\*\\]
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquistPath = "/"? [a-zA-Z]{FNameChar}* ("/" [a-zA-Z]{FNameChar}*[a-zA-Z0-9])+
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquistFile = [a-zA-Z]{FNameChar}* "." ("go"|"txt"|"htm"|"html"|"diff"|"patch")
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquistNumber = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9][0-9_]*)([eE][+-]?[0-9]+)?
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist%state STRING COMMENT SCOMMENT QSTRING
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist%%
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist<YYINITIAL> {
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist {Identifier} {
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist String id = yytext();
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist writeSymbol(id, Consts.kwd, yyline);
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist {Number} { out.write("<span class=\"n\">"); out.write(yytext()); out.write("</span>"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist \" { yybegin(STRING); out.write("<span class=\"s\">\""); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist \' { yybegin(QSTRING); out.write("<span class=\"s\">\'"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist "/*" { yybegin(COMMENT); out.write("<span class=\"c\">/*"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist "//" { yybegin(SCOMMENT); out.write("<span class=\"c\">//"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist}
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist"<" ({File}|{Path}) ">" {
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist out.write("&lt;");
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist String path = yytext();
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist path = path.substring(1, path.length() - 1);
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist out.write("<a href=\""+urlPrefix+"path=");
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist out.write(path);
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist appendProject();
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist out.write("\">");
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist out.write(path);
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist out.write("</a>");
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist out.write("&gt;");
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist}
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist<STRING> {
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist \" {WhiteSpace} \" { out.write(yytext()); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist \" { yybegin(YYINITIAL); out.write("\"</span>"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist \\\\ { out.write("\\\\"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist \\\" { out.write("\\\""); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist}
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist<QSTRING> {
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist "\\\\" { out.write("\\\\"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist "\\'" { out.write("\\\'"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist \' {WhiteSpace} \' { out.write(yytext()); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist \' { yybegin(YYINITIAL); out.write("'</span>"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist}
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist<COMMENT> {
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist "*/" { yybegin(YYINITIAL); out.write("*/</span>"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist}
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist<SCOMMENT> {
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist {WhiteSpace}*{EOL} { yybegin(YYINITIAL); out.write("</span>"); startNewLine(); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist}
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist "&" { out.write( "&amp;"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist "<" { out.write( "&lt;"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist ">" { out.write( "&gt;"); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist {WhiteSpace}*{EOL} { startNewLine(); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist {WhiteSpace} { out.write(yytext()); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist [^\n] { writeUnicodeChar(yycharat(0)); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist}
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist<STRING, COMMENT, SCOMMENT, QSTRING> {
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist {Path} { out.write(Util.breadcrumbPath(urlPrefix + "path=", yytext(), '/')); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist {File} {
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist String path = yytext();
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist out.write("<a href=\""+urlPrefix+"path=");
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist out.write(path);
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist appendProject();
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist out.write("\">");
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist out.write(path);
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist out.write("</a>");
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist ("http" | "https" | "ftp") "://" ({FNameChar}|{URIChar})+[a-zA-Z0-9/] {
4eda2f9f481542c575493b4d80a9297b6d43a032Knut Anders Hatlen appendLink(yytext());
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist {FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+ { writeEMailAddress(yytext()); }
33a28b94ce2e89da8d1ca8d1b7c517907c141606patricklundquist}