KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > ScannerState


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 Dec 17, 2004
10  *
11  * Author Ben Yu
12  */

13 package jfun.parsec;
14
15
16
17 /**
18  * @author Ben Yu
19  *
20  * Dec 17, 2004
21  */

22 final class ScannerState extends ParseContext {
23   private final CharSequence JavaDoc src;
24   private final int len;
25   ScannerState(final CharSequence JavaDoc src,
26       int a, final String JavaDoc module, final PositionMap pmap,
27       final Object JavaDoc ustate){
28     super(ustate, a, module, pmap);
29     this.src = src;
30     this.len = src.length();
31   }
32   ScannerState(final CharSequence JavaDoc src, int a,
33       final String JavaDoc module, final PositionMap pmap,
34       int l, final Object JavaDoc ustate){
35     super(ustate, a, module, pmap);
36     this.src = src;
37     this.len = l;
38   }
39   ScannerState(final CharSequence JavaDoc src, int a,
40       final String JavaDoc module, final PositionMap pmap,
41       int l, final Object JavaDoc r,
42       final Object JavaDoc ustate){
43     super(r, ustate, a, module, pmap);
44     this.src = src;
45     this.len = l;
46   }
47   char peekChar(){
48     return src.charAt(at);
49   }
50   boolean isEof(){
51     return len == at;
52   }
53   CharSequence JavaDoc getSource(){
54     return src;
55   }
56   int length(){return len;}
57
58   /*
59    * @see jfun.parsec.ParseContext#getIndex()
60    */

61   int getIndex() {
62     return at;
63   }
64
65   /*
66    * @see jfun.parsec.ParseContext#getToken()
67    */

68   Tok getToken() {
69     throw new IllegalStateException JavaDoc("Parser not on token level");
70   }
71
72
73
74   /*
75    * @see jfun.parsec.ParseContext#getSysUnexpected()
76    */

77   ParsecError getSysUnexpected() {
78     final String JavaDoc msg = (len==at)?"EOF":(""+src.charAt(at));
79     return ParsecError.raiseSysUnexpected(getIndex(), msg);
80   }
81 }
82
Popular Tags