/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
%%
%int
%{
// State variables for the HEREDOC state. They tell what the stop word is,
// and whether leading tabs should be removed from the input lines before
// comparing with the stop word.
stateStack.clear();
styleStack.clear();
}
// TODO move this into an include file when bug #16053 is fixed
if (!styleStack.empty()) {
}
} else {
}
}
styleStack.pop();
if (!styleStack.empty()) {
} else {
}
}
}
/**
* Check the contents of a line to see if it matches the stop word for a
* here-document.
*
* @param line a line in the input file
* @return true if the line terminates a here-document, false otherwise
*/
// Skip leading tabs if heredocStripLeadingTabs is true.
int i = 0;
while (heredocStripLeadingTabs &&
i++;
}
// Compare remaining characters on the line with the stop word.
}
%}
WhiteSpace = [ \t\f]
EOL = \r|\n|\r\n
URIChar = [\?\+\%\&\:\/\.\@\_\;\=\$\,\-\!\~\*\\]
/*
* States:
* STRING - double-quoted string, ex: "hello, world!"
* SCOMMENT - single-line comment, ex: # this is a comment
* QSTRING - single-quoted string, ex: 'hello, world!'
* SUBSHELL - commands executed in a sub-shell,
* example 1: (echo $header; cat file.txt)
* example 2 (command substitution): $(cat file.txt)
* BACKQUOTE - command substitution using back-quotes, ex: `cat file.txt`
* BRACEGROUP - group of commands in braces, possibly ksh command substitution
* extension, ex: ${ cat file.txt; }
* HEREDOC - here-document, example: cat<<EOF ... EOF
*/
%%
<STRING>{
"$" {Identifier} {
}
/* This rule matches associative arrays inside strings,
for instance "${array["string"]}". Push a new STRING
state on the stack to prevent premature exit from the
STRING state. */
\$\{ {Identifier} \[\" {
out.write(yytext()); pushstate(STRING, "s");
}
}
<YYINITIAL, SUBSHELL, BACKQUOTE, BRACEGROUP> {
\$ ? {Identifier} {
String id = yytext();
writeSymbol(id, Consts.shkwd, yyline);
}
\$ ? \" { pushstate(STRING, "s"); out.write(yytext()); }
\$ ? \' { pushstate(QSTRING, "s"); out.write(yytext()); }
"#" { pushstate(SCOMMENT, "c"); out.write(yytext()); }
// Recognize here-documents. At least a subset of them.
"<<" "-"? {WhiteSpace}* {Identifier} {WhiteSpace}* {
String text = yytext();
out.write(Util.htmlize(text));
heredocStripLeadingTabs = (text.charAt(2) == '-');
heredocStopWord = text.substring(heredocStripLeadingTabs ? 3 : 2).trim();
pushstate(HEREDOC, "s");
}
// Any sequence of more than two < characters should not start HEREDOC. Use
// this rule to catch them before the HEREDOC rule.
"<<" "<" + {
out.write(Util.htmlize(yytext()));
}
}
<STRING> {
\" {WhiteSpace}* \" { out.write(yytext()); }
\" { out.write(yytext()); popstate(); }
\\\\ | \\\" | \\\$ | \\` { out.write(yytext()); }
\$\( { pushstate(SUBSHELL, null); out.write(yytext()); }
` { pushstate(BACKQUOTE, null); out.write(yytext()); }
/* Bug #15661: Recognize ksh command substitution within strings. According
* to ksh man page http://www2.research.att.com/~gsf/man/man1/ksh-man.html#Command%20Substitution
* the opening brace must be followed by a blank.
*/
"${" / {WhiteSpace} | {EOL} {
pushstate(BRACEGROUP, null); out.write(yytext());
}
}
<QSTRING> {
\' {WhiteSpace}* \' { out.write(yytext()); }
\\' { out.write("\\'"); }
\' { out.write(yytext()); popstate(); }
}
<SCOMMENT> {
{EOL} { popstate();
startNewLine();}
}
<SUBSHELL> {
\) { out.write(yytext()); popstate(); }
}
<BACKQUOTE> {
` { out.write(yytext()); popstate(); }
}
<BRACEGROUP> {
/* Bug #15661: Terminate a ksh brace group. According to ksh man page
* http://www2.research.att.com/~gsf/man/man1/ksh-man.html#Command%20Substitution
* the closing brace must be on beginning of line, or it must be preceeded by
* a semi-colon and (optionally) whitespace.
*/
^ {WhiteSpace}* \} { out.write(yytext()); popstate(); }
; {WhiteSpace}* \} { out.write(yytext()); popstate(); }
}
<HEREDOC> {
.* {
String line = yytext();
if (isHeredocStopWord(line)) {
popstate();
}
out.write(Util.htmlize(line));
}
{EOL} { startNewLine(); }
}
<YYINITIAL, SUBSHELL, BACKQUOTE, BRACEGROUP> {
\\\" | \\' | \\\$ | \\\# { out.write(yytext()); }
/* $# should not start a comment. */
"$#" { out.write(yytext()); }
\$ ? \( { pushstate(SUBSHELL, null); out.write(yytext()); }
` { pushstate(BACKQUOTE, null); out.write(yytext()); }
/* Bug #15661: Recognize ksh command substitution within strings. According
* to ksh man page http://www2.research.att.com/~gsf/man/man1/ksh-man.html#Command%20Substitution
* the opening brace must be followed by a blank. Make the initial dollar sign
* optional so that we get the nesting right and don't terminate the brace
* group too early if the ${ cmd; } expression contains nested { cmd; } groups.
*/
\$ ? \{ / {WhiteSpace} | {EOL} {
pushstate(BRACEGROUP, null); out.write(yytext());
}
}
<YYINITIAL, SUBSHELL, BACKQUOTE, BRACEGROUP, STRING, SCOMMENT, QSTRING> {
{File} {
String path = yytext();
}
{Path}
{EOL} { startNewLine(); }
. { writeUnicodeChar(yycharat(0)); }
}
{
}
{
}
}
<<EOF>> {
// If we reach EOF while being in a nested state, pop all the way up
// the initial state so that we close open HTML tags.
while (!stateStack.isEmpty()) {
popstate();
}
return YYEOF;
}