📄 java2html.java
字号:
prTitle(args[0]);
prHead(END);
prBody(START);
while(st.nextToken() != StreamTokenizer.TT_EOF) {
switch(st.ttype) {
case StreamTokenizer.TT_WORD:
if(firstOfComment){
if((!comment && !lineComment)) prOperator("/");
}
firstOfComment=false;
if(primitives.contains(st.sval)) {
prPrimitive(st.sval);
isVar=true;
backslash=false;
break;
}
if(flow.contains(st.sval)) {
isVar=false;
prNumber(st.sval);
backslash=false;
break;
}
if(resWords.contains(st.sval)) {
isVar=false;
prResWord(st.sval);
backslash=false;
break;
}
if(varList.contains(st.sval)) {
isVar=false;
prVar(st.sval);
backslash=false;
break;
}
if(isVar && !(varList.contains(st.sval))) {
varList.add(st.sval);
prVar(st.sval);
} else {
prNormal(st.sval);
}
backslash=false;
break;
case StreamTokenizer.TT_EOL:
isVar=false;
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
firstOfComment=false;
lineComment=false;
prBr(START);
backslash=false;
break;
case StreamTokenizer.TT_NUMBER:
isVar=false;
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
firstOfComment=false;
if(String.valueOf((char)st.ttype).equals(".")) {
prFlow(".");
backslash=false;
break;
}
prNumber(new Double(st.nval).toString());
backslash=false;
break;
default:
isVar=false;
if(operators.contains(String.valueOf((char)st.ttype))) {
if (firstOfComment) {
if (comment) {
//there has been a star, waiting for slash
if (String.valueOf((char)st.ttype).equals("/")) {
firstOfComment=false;
prJComment("*/");
comment=false;
backslash=false;
firstOfComment=false;
break;
} else firstOfComment=false;
} else {
//there has been a slash, waiting for slash or star
if (String.valueOf((char)st.ttype).equals("/")) {
if (!stringlit) {
lineComment=true;
prJComment("//");
} else {
lineComment=false;
prNormal("//");
}
firstOfComment=false;
comment=false;
backslash=false;
break;
} else if (String.valueOf((char)st.ttype).equals("*")) {
if (!stringlit) {
comment=true;
prJComment("/*");
} else {
comment=false;
prNormal("/*");
}
firstOfComment=false;
lineComment=false;
backslash=false;
break;
} else {
firstOfComment=false;
if (!lineComment) prOperator("/");
prOperator(String.valueOf((char)st.ttype));
backslash=false;
break;
}
}
} else {
if (comment) {
//waiting for star
if (String.valueOf((char)st.ttype).equals("*")) {
firstOfComment=true;
backslash=false;
break;
} else firstOfComment=false;
} else {
//waiting for slash
if (String.valueOf((char)st.ttype).equals("/")) {
firstOfComment=true;
backslash=false;
break;
} else {
firstOfComment=false;
prOperator(String.valueOf((char)st.ttype));
backslash=false;
break;
}
}
}
}
if(String.valueOf((char)st.ttype).equals("\"")) {
if(firstOfComment) {
if (!(comment || lineComment)) prOperator("/");
firstOfComment=false;
}
if (!backslash) prStringTwo(!stringlit);
else prNormal("\"");
backslash=false;
break;
}
if(String.valueOf((char)st.ttype).equals("\\")) {
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
prNormal("\\");
backslash=!backslash;
break;
}
if(String.valueOf((char)st.ttype).equals("\'")) {
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
if (!backslash && !stringlit2) prStringOne(!stringlit);
else prNormal("\'");
backslash=false;
break;
}
if(String.valueOf((char)st.ttype).equals(";")) {
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
prFlow(";");
backslash=false;
break;
}
if(String.valueOf((char)st.ttype).equals(",")) {
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
prFlow(",");
backslash=false;
break;
}
if(String.valueOf((char)st.ttype).equals(".")) {
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
prFlow(".");
backslash=false;
break;
}
if(String.valueOf((char)st.ttype).equals(")")) {
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
prFlow(")");
backslash=false;
break;
}
if(String.valueOf((char)st.ttype).equals("(")) {
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
prFlow("(");
backslash=false;
break;
}
if(String.valueOf((char)st.ttype).equals("]")) {
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
prFlow("]");
backslash=false;
break;
}
if(String.valueOf((char)st.ttype).equals("[")) {
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
prFlow("[");
backslash=false;
break;
}
if(String.valueOf((char)st.ttype).equals("{")) {
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
tabIncrease(true);
prFlow("{");
backslash=false;
break;
}
if(String.valueOf((char)st.ttype).equals("}")) {
if(firstOfComment) {
prOperator("/");
firstOfComment=false;
}
tabIncrease(false);
if (out.substring(out.length()-24).equals(" ")) {
out.delete(out.length()-24,out.length());
}
prFlow("}");
backslash=false;
break;
}
prNormal(String.valueOf((char)st.ttype));
backslash=false;
break;
}
}
prBody(END);
prHtml(END);
} catch (FileNotFoundException e) {
System.out.println("Could not find the file: " + args[0]);
} catch (IOException e) {
e.printStackTrace();
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("There is no input file");
}
if(puthtml.put(htmlFile,out.toString()))
{
System.out.println("成功生成"+htmlFile+"文件");
}
else
{
System.out.println("生成"+htmlFile+"文件失败");
}
}
}
}
class putHtml
{
boolean put(String fileName , String fileBody)
{
boolean returnMessage = false;
String file = fileName;
try
{
PrintWriter pw = new PrintWriter(new FileOutputStream(file));
pw.println(fileBody);
pw.close();
returnMessage = true ;
} catch(IOException e) {
returnMessage = false;
}
return returnMessage;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -