KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > LazyParser


1 /*****************************************************************************
2  * Copyright (C) Zephyr Business Solutions Corp. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 /*
9  * Created on 2004-11-14
10  *
11  * Author Ben Yu
12  */

13 package jfun.parsec;
14
15 /**
16  * @author Ben Yu
17  *
18  * 2004-11-14
19  */

20 final class LazyParser<T> extends Parser {
21   boolean apply(ParseContext ctxt) {
22     return eval.eval().apply(ctxt);
23   }
24   boolean apply(ParseContext ctxt, int look_ahead){
25     return eval.eval().apply(ctxt, look_ahead);
26   }
27   private final ParserEval<T> eval;
28   
29   /**
30    * @param eval
31    */

32   private LazyParser(final String JavaDoc name, final ParserEval eval) {
33     super(name);
34     this.eval = eval;
35   }
36   static <R> Parser<R> instance(final String JavaDoc name, final ParserEval<R> e){
37     return new LazyParser<R>(name, e);
38   }
39 }
40
Popular Tags