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 javacc Show documentation
Show all versions of javacc Show documentation
JavaCC is a parser/scanner generator for Java.
The newest version!
/* 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.CppCodeProduction;
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 {
private Hashtable id_map = new Hashtable();
private int id = 1;
public HTMLGenerator() {
super();
}
protected String get_id(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(String s) {
print(s + "\n");
}
public void text(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);
}
public void print(String s) {
ostr.print(s);
}
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 + "
");
}
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)
*/
public void specialTokens(String s) {
println(" ");
println(" ");
println(" ");
println("");
print(s);
println("
");
println(" ");
println(" ");
}
@Override
public void handleTokenProduction(TokenProduction tp) {
println(" ");
println(" ");
println(" ");
println(" ");
String text = JJDoc.getStandardTokenProductionText(tp);
text(text);
println("
");
println(" ");
println(" ");
}
public void nonterminalsStart() {
println("NON-TERMINALS
");
if (JJDocOptions.getOneTable()) {
println("");
}
}
public void nonterminalsEnd() {
if (JJDocOptions.getOneTable()) {
println("
");
}
}
public void tokensStart() {
println("TOKENS
");
println("");
}
public void tokensEnd() {
println("
");
}
public void javacode(JavaCodeProduction jp) {
productionStart(jp);
println("java code");
productionEnd(jp);
}
public void cppcode(CppCodeProduction cp) {
productionStart(cp);
println("cpp code");
productionEnd(cp);
}
public void productionStart(NormalProduction np) {
if (!JJDocOptions.getOneTable()) {
println("");
println("");
println("" + np.getLhs() + " ");
}
println("");
println("" + np.getLhs() + " ");
println("::= ");
print("");
}
public void productionEnd(NormalProduction np) {
if (!JJDocOptions.getOneTable()) {
println("
");
println("
");
}
}
public void expansionStart(Expansion e, boolean first) {
if (!first) {
println("");
println(" ");
println("| ");
print("");
}
}
public void expansionEnd(Expansion e, boolean first) {
println(" ");
println(" ");
}
public void nonTerminalStart(NonTerminal nt) {
print("");
}
public void nonTerminalEnd(NonTerminal nt) {
print("");
}
public void reStart(RegularExpression r) {
}
public void reEnd(RegularExpression r) {
}
}