开发者

javacc, translate from dir/x/s to HTML

I would like to translate from dir/x/s language to html.

I have Analyzer.j :

PARSER_BEGIN(Analyzer)

import java.io.*;

public class Analyzer
{
    public static void main(String args[]) throws ParseException, 
                                                  FileNotFoundException 
    {
 Analyzer analyzer;
 try {
   analyzer = new Analyzer(new FileInputStream(args[0]));
   analyzer.Start();
 } catch(ParseException pe) {
   System.out.println(pe);
 } catch(FileNotFoundException fe) {
   System.out.println(fe);
 } 

    }
}
PARSER_END(Analyzer)
SKIP :                              
{
      " "
    | "\t"
    | "\r"
    | "\n"

}
TOKEN:
{
      <DIR:   "<DIR>">
    | <BYTES:   "bytes">
    | <DOTDOT:   "..">
    | <DOT:   ".">
    | <BACKSLASH:  "\\">
    | <COLON:   ":">
    | <DASH:   "-">
    | <SLASH:   "/">
    | <COMMA:   ",">
    | <INTEGER:  (["0"-"9"])+>
    | <STRING:   (["a"-"z", "A"-"Z", "0"-"9"])+>
}

void Start():
{}
{
  (ListLine())+
}
void Date():
{}
{
  <INTEGER>[<DOT><INTEGER><DOT><INTEGER>]
}
void Time():
{}
{
  <INTEGER><COLON><INTEGER>
}
void FileName():
{}
{
  <STRING>[<DOT><STRING>]
}
void FileSize():
{}
{
  <INTEGER>(<DOT><INTEGER>)*[<BYTES>]
}
void ListLine():
{}
{
  Date() Time() (<DIR>|FileSize()) [(<DOT>|<DOTDOT>|FileName())] 
}

Source code is:

10.10.10  12:00   <DIR>   DIRECTORY_1/            
10.09.27  14:35   <DIR>   DIRECTORY_2/           
99.11.27  01:00   423k    FILE.DOC  
98.12.25  07:00   783k    FILE_2.PDF  
02.03.14  02:59   3k      README

and result in HTML language should be:

<HTML> 
<PRE>
<A HREF="DIRECTORY_1/">DIRECTORY_1/</A>         10.10.10  12:00   -
<A HREF="DIRECTORY_2/">DIRECTORY_2/</A>         10.09.27  14:35   -
<A HREF="FILE.DOC">FILE.DOC</A>        99.11.27  01:00   423k
<A HREF="FILE_2.PDF">FILE_2.PDF</A>       98.12.25  07:00   783k
<A HREF="README">README</A>               02.03.14  02:59   3k开发者_StackOverflow
</PRE>
</HTML>

How could I parse one code to another? And save html code to file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜