This is the BeanShell parser. It is used internally by the Interpreter class (which is probably what you are looking for). The parser knows only how to parse the structure of the language, it does not understand names, commands, etc. You can use the Parser from the command line to do basi
| 30 | </pre></code> |
| 31 | */ |
| 32 | public class Parser/*@bgen(jjtree)*/implements ParserTreeConstants, ParserConstants {/*@bgen(jjtree)*/ |
| 33 | protected JJTParserState jjtree = new JJTParserState();boolean retainComments = false; |
| 34 | |
| 35 | public void setRetainComments( boolean b ) { |
| 36 | retainComments = b; |
| 37 | } |
| 38 | |
| 39 | void jjtreeOpenNodeScope(Node n) { |
| 40 | ((SimpleNode)n).firstToken = getToken(1); |
| 41 | } |
| 42 | |
| 43 | void jjtreeCloseNodeScope(Node n) { |
| 44 | ((SimpleNode)n).lastToken = getToken(0); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | Re-initialize the input stream and token source. |
| 49 | */ |
| 50 | void reInitInput( Reader in ) { |
| 51 | ReInit(in); |
| 52 | } |
| 53 | |
| 54 | public SimpleNode popNode() |
| 55 | { |
| 56 | if ( jjtree.nodeArity() > 0) // number of child nodes |
| 57 | return (SimpleNode)jjtree.popNode(); |
| 58 | else |
| 59 | return null; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | Explicitly re-initialize just the token reader. |
| 64 | This seems to be necessary to avoid certain looping errors when |
| 65 | reading bogus input. See Interpreter. |
| 66 | */ |
| 67 | void reInitTokenInput( Reader in ) { |
| 68 | jj_input_stream.ReInit( in, |
| 69 | jj_input_stream.getEndLine(), |
| 70 | jj_input_stream.getEndColumn() ); |
| 71 | } |
| 72 | |
| 73 | public static void main( String [] args ) |
| 74 | throws IOException, ParseException |
| 75 | { |
| 76 | boolean print = false; |
| 77 | int i=0; |
| 78 | if ( args[0].equals("-p") ) { |
| 79 | i++; |
| 80 | print=true; |
| 81 | } |
| 82 | for(; i< args.length; i++) { |
| 83 | Reader in = new FileReader(args[i]); |
| 84 | Parser parser = new Parser(in); |
| 85 | parser.setRetainComments(true); |
| 86 | while( !parser.Line()/*eof*/ ) |
| 87 | if ( print ) |
| 88 | System.out.println( parser.popNode() ); |
| 89 | } |