190N/A/*
190N/A * CDDL HEADER START
190N/A *
190N/A * The contents of this file are subject to the terms of the
190N/A * Common Development and Distribution License (the "License").
190N/A * You may not use this file except in compliance with the License.
190N/A *
190N/A * See LICENSE.txt included in this distribution for the specific
190N/A * language governing permissions and limitations under the License.
190N/A *
190N/A * When distributing Covered Code, include this CDDL HEADER in each
190N/A * file and include the License file at LICENSE.txt.
190N/A * If applicable, add the following below this CDDL HEADER, with the
190N/A * fields enclosed by brackets "[]" replaced with your own identifying
190N/A * information: Portions Copyright [yyyy] [name of copyright owner]
190N/A *
190N/A * CDDL HEADER END
190N/A */
190N/A
190N/A/*
1058N/A * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
190N/A */
190N/A
190N/Apackage org.opensolaris.opengrok.analysis.sql;
850N/Aimport org.opensolaris.opengrok.analysis.JFlexXref;
850N/Aimport java.io.IOException;
850N/Aimport java.io.Writer;
850N/Aimport java.io.Reader;
190N/Aimport org.opensolaris.opengrok.web.Util;
190N/A
190N/A%%
1020N/A%public
190N/A%class SQLXref
850N/A%extends JFlexXref
190N/A%unicode
190N/A%ignorecase
190N/A%int
190N/A%{
190N/A private int commentLevel;
190N/A
1020N/A // TODO move this into an include file when bug #16053 is fixed
1020N/A @Override
1020N/A protected int getLineNumber() { return yyline; }
1020N/A @Override
1020N/A protected void setLineNumber(int x) { yyline = x; }
190N/A%}
190N/A
190N/ASign = "+" | "-"
190N/ASimpleNumber = [0-9]+ | [0-9]+ "." [0-9]* | [0-9]* "." [0-9]+
190N/AScientificNumber = ({SimpleNumber} [eE] {Sign}? [0-9]+)
190N/A
190N/ANumber = {Sign}? ({SimpleNumber} | {ScientificNumber})
190N/A
190N/AIdentifier = [a-zA-Z] [a-zA-Z0-9_]*
190N/A
936N/AWhitespace = [ \t\f]+
1020N/AEOL = \r|\n|\r\n
190N/A
190N/A%state STRING QUOTED_IDENTIFIER SINGLE_LINE_COMMENT BRACKETED_COMMENT
190N/A
190N/A%%
190N/A
190N/A<YYINITIAL> {
190N/A {Identifier} {
190N/A String id = yytext();
1469N/A writeSymbol(id, Consts.getReservedKeywords(), yyline, false);
190N/A }
190N/A
190N/A {Number} {
190N/A out.append("<span class=\"n\">").append(yytext()).append("</span>");
190N/A }
190N/A
1370N/A "'" { yybegin(STRING); out.append("<span class=\"s\">'"); spans.push("s"); }
190N/A
1370N/A \" { yybegin(QUOTED_IDENTIFIER); out.append("<span class=\"s\">\""); spans.push("s"); }
190N/A
1370N/A "--" { yybegin(SINGLE_LINE_COMMENT); out.append("<span class=\"c\">--"); spans.push("c"); }
190N/A
190N/A "/*" {
190N/A yybegin(BRACKETED_COMMENT);
190N/A commentLevel = 1;
1370N/A out.append("<span class=\"c\">/*"); spans.push("c");
190N/A }
190N/A}
190N/A
190N/A<STRING> {
190N/A "''" { out.append("''"); }
1370N/A "'" { yybegin(YYINITIAL); out.append("'</span>"); spans.pop(); }
190N/A}
190N/A
190N/A<QUOTED_IDENTIFIER> {
190N/A \"\" { out.append("\"\""); }
1370N/A \" { yybegin(YYINITIAL); out.append("\"</span>"); spans.pop(); }
190N/A}
190N/A
190N/A<SINGLE_LINE_COMMENT> {
936N/A {EOL} {
190N/A yybegin(YYINITIAL);
1370N/A out.append("</span>"); spans.pop();
1020N/A startNewLine();
190N/A }
190N/A}
190N/A
190N/A<BRACKETED_COMMENT> {
190N/A "/*" { out.append(yytext()); commentLevel++; }
190N/A "*/" {
190N/A commentLevel--;
190N/A out.append(yytext());
190N/A if (commentLevel == 0) {
190N/A yybegin(YYINITIAL);
1370N/A out.append("</span>"); spans.pop();
190N/A }
190N/A }
190N/A}
190N/A
190N/A<YYINITIAL, STRING, QUOTED_IDENTIFIER, SINGLE_LINE_COMMENT, BRACKETED_COMMENT> {
190N/A "&" { out.append( "&amp;"); }
190N/A "<" { out.append( "&lt;"); }
190N/A ">" { out.append( "&gt;"); }
1020N/A {EOL} { startNewLine(); }
190N/A {Whitespace} { out.append(yytext()); }
190N/A [ \t\f\r!-~] { out.append(yycharat(0)); }
963N/A . { writeUnicodeChar(yycharat(0)); }
190N/A}