Source Code Cross Referenced for InputBuffer.java in  » Database-ORM » toplink » persistence » antlr » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » toplink » persistence.antlr 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package persistence.antlr;
002:
003:        /* ANTLR Translator Generator
004:         * Project led by Terence Parr at http://www.jGuru.com
005:         * Software rights: http://www.antlr.org/license.html
006:         *
007:         */
008:
009:        // SAS: Added this class to genericise the input buffers for scanners
010:        //      This allows a scanner to use a binary (FileInputStream) or
011:        //      text (FileReader) stream of data; the generated scanner
012:        //      subclass will define the input stream
013:        //      There are two subclasses to this: CharBuffer and ByteBuffer
014:        import java.io.IOException;
015:
016:        /**A Stream of characters fed to the lexer from a InputStream that can
017:         * be rewound via mark()/rewind() methods.
018:         * <p>
019:         * A dynamic array is used to buffer up all the input characters.  Normally,
020:         * "k" characters are stored in the buffer.  More characters may be stored during
021:         * guess mode (testing syntactic predicate), or when LT(i>k) is referenced.
022:         * Consumption of characters is deferred.  In other words, reading the next
023:         * character is not done by conume(), but deferred until needed by LA or LT.
024:         * <p>
025:         *
026:         * @see persistence.antlr.CharQueue
027:         */
028:        public abstract class InputBuffer {
029:            // Number of active markers
030:            protected int nMarkers = 0;
031:
032:            // Additional offset used when markers are active
033:            protected int markerOffset = 0;
034:
035:            // Number of calls to consume() since last LA() or LT() call
036:            protected int numToConsume = 0;
037:
038:            // Circular queue
039:            protected CharQueue queue;
040:
041:            /** Create an input buffer */
042:            public InputBuffer() {
043:                queue = new CharQueue(1);
044:            }
045:
046:            /** This method updates the state of the input buffer so that
047:             *  the text matched since the most recent mark() is no longer
048:             *  held by the buffer.  So, you either do a mark/rewind for
049:             *  failed predicate or mark/commit to keep on parsing without
050:             *  rewinding the input.
051:             */
052:            public void commit() {
053:                nMarkers--;
054:            }
055:
056:            /** Mark another character for deferred consumption */
057:            public void consume() {
058:                numToConsume++;
059:            }
060:
061:            /** Ensure that the input buffer is sufficiently full */
062:            public abstract void fill(int amount) throws CharStreamException;
063:
064:            public String getLAChars() {
065:                StringBuffer la = new StringBuffer();
066:                for (int i = markerOffset; i < queue.nbrEntries; i++)
067:                    la.append(queue.elementAt(i));
068:                return la.toString();
069:            }
070:
071:            public String getMarkedChars() {
072:                StringBuffer marked = new StringBuffer();
073:                for (int i = 0; i < markerOffset; i++)
074:                    marked.append(queue.elementAt(i));
075:                return marked.toString();
076:            }
077:
078:            public boolean isMarked() {
079:                return (nMarkers != 0);
080:            }
081:
082:            /** Get a lookahead character */
083:            public char LA(int i) throws CharStreamException {
084:                fill(i);
085:                return queue.elementAt(markerOffset + i - 1);
086:            }
087:
088:            /**Return an integer marker that can be used to rewind the buffer to
089:             * its current state.
090:             */
091:            public int mark() {
092:                syncConsume();
093:                nMarkers++;
094:                return markerOffset;
095:            }
096:
097:            /**Rewind the character buffer to a marker.
098:             * @param mark Marker returned previously from mark()
099:             */
100:            public void rewind(int mark) {
101:                syncConsume();
102:                markerOffset = mark;
103:                nMarkers--;
104:            }
105:
106:            /** Reset the input buffer
107:             */
108:            public void reset() {
109:                nMarkers = 0;
110:                markerOffset = 0;
111:                numToConsume = 0;
112:                queue.reset();
113:            }
114:
115:            /** Sync up deferred consumption */
116:            protected void syncConsume() {
117:                while (numToConsume > 0) {
118:                    if (nMarkers > 0) {
119:                        // guess mode -- leave leading characters and bump offset.
120:                        markerOffset++;
121:                    } else {
122:                        // normal mode -- remove first character
123:                        queue.removeFirst();
124:                    }
125:                    numToConsume--;
126:                }
127:            }
128:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.