org.javacc.jjdoc.HTMLGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ph-javacc-maven-plugin Show documentation
Show all versions of ph-javacc-maven-plugin Show documentation
Maven 3 Plugin for processing JavaCC grammar files.
/* Copyright (c) 2006, Sun Microsystems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Sun Microsystems, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.javacc.jjdoc;
import java.util.Hashtable;
import org.javacc.parser.Expansion;
import org.javacc.parser.JavaCodeProduction;
import org.javacc.parser.NonTerminal;
import org.javacc.parser.NormalProduction;
import org.javacc.parser.RegularExpression;
import org.javacc.parser.TokenProduction;
/**
* Output BNF in HTML 3.2 format.
*/
public class HTMLGenerator extends TextGenerator implements Generator
{
private final Hashtable id_map = new Hashtable ();
private int id = 1;
public HTMLGenerator ()
{
super ();
}
protected String get_id (final String nt)
{
String i = (String) id_map.get (nt);
if (i == null)
{
i = "prod" + id++;
id_map.put (nt, i);
}
return i;
}
private void println (final String s)
{
print (s + "\n");
}
@Override
public void text (final String s)
{
String ss = "";
for (int i = 0; i < s.length (); ++i)
{
if (s.charAt (i) == '<')
{
ss += "<";
}
else
if (s.charAt (i) == '>')
{
ss += ">";
}
else
if (s.charAt (i) == '&')
{
ss += "&";
}
else
{
ss += s.charAt (i);
}
}
print (ss);
}
@Override
public void print (final String s)
{
ostr.print (s);
}
@Override
public void documentStart ()
{
ostr = create_output_stream ();
println ("");
println ("");
println ("");
if (!"".equals (JJDocOptions.getCSS ()))
{
println ("");
}
if (JJDocGlobals.input_file != null)
{
println ("BNF for " + JJDocGlobals.input_file + " ");
}
else
{
println ("A BNF grammar by JJDoc ");
}
println ("");
println ("");
println ("BNF for " + JJDocGlobals.input_file + "
");
}
@Override
public void documentEnd ()
{
println ("");
println ("");
ostr.close ();
}
/**
* Prints out comments, used for tokens and non-terminals. {@inheritDoc}
*
* @see org.javacc.jjdoc.TextGenerator#specialTokens(java.lang.String)
*/
@Override
public void specialTokens (final String s)
{
println (" ");
println (" ");
println (" ");
println ("");
print (s);
println ("
");
println (" ");
println (" ");
}
@Override
public void handleTokenProduction (final TokenProduction tp)
{
println (" ");
println (" ");
println (" ");
println (" ");
final String text = JJDoc.getStandardTokenProductionText (tp);
text (text);
println ("
");
println (" ");
println (" ");
}
@Override
public void nonterminalsStart ()
{
println ("NON-TERMINALS
");
if (JJDocOptions.getOneTable ())
{
println ("");
}
}
@Override
public void nonterminalsEnd ()
{
if (JJDocOptions.getOneTable ())
{
println ("
");
}
}
@Override
public void tokensStart ()
{
println ("TOKENS
");
println ("");
}
@Override
public void tokensEnd ()
{
println ("
");
}
@Override
public void javacode (final JavaCodeProduction jp)
{
productionStart (jp);
println ("java code");
productionEnd (jp);
}
@Override
public void productionStart (final NormalProduction np)
{
if (!JJDocOptions.getOneTable ())
{
println ("");
println ("");
println ("" + np.getLhs () + " ");
}
println ("");
println ("" + np.getLhs () + " ");
println ("::= ");
print ("");
}
@Override
public void productionEnd (final NormalProduction np)
{
if (!JJDocOptions.getOneTable ())
{
println ("
");
println ("
");
}
}
@Override
public void expansionStart (final Expansion e, final boolean first)
{
if (!first)
{
println ("");
println (" ");
println ("| ");
print ("");
}
}
@Override
public void expansionEnd (final Expansion e, final boolean first)
{
println (" ");
println (" ");
}
@Override
public void nonTerminalStart (final NonTerminal nt)
{
print ("");
}
@Override
public void nonTerminalEnd (final NonTerminal nt)
{
print ("");
}
@Override
public void reStart (final RegularExpression r)
{}
@Override
public void reEnd (final RegularExpression r)
{}
}