Source Code Cross Referenced for MismatchedCharException.java in  » IDE-Netbeans » cnd » 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 » IDE Netbeans » cnd » antlr 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package antlr;
002:
003:        /* ANTLR Translator Generator
004:         * Project led by Terence Parr at http://www.cs.usfca.edu
005:         * Software rights: http://www.antlr.org/license.html
006:         */
007:
008:        import antlr.collections.impl.BitSet;
009:
010:        public class MismatchedCharException extends RecognitionException {
011:            // Types of chars
012:            public static final int CHAR = 1;
013:            public static final int NOT_CHAR = 2;
014:            public static final int RANGE = 3;
015:            public static final int NOT_RANGE = 4;
016:            public static final int SET = 5;
017:            public static final int NOT_SET = 6;
018:
019:            // One of the above
020:            public int mismatchType;
021:
022:            // what was found on the input stream
023:            public int foundChar;
024:
025:            // For CHAR/NOT_CHAR and RANGE/NOT_RANGE
026:            public int expecting;
027:
028:            // For RANGE/NOT_RANGE (expecting is lower bound of range)
029:            public int upper;
030:
031:            // For SET/NOT_SET
032:            public BitSet set;
033:
034:            // who knows...they may want to ask scanner questions
035:            public CharScanner scanner;
036:
037:            /**
038:             * MismatchedCharException constructor comment.
039:             */
040:            public MismatchedCharException() {
041:                super ("Mismatched char");
042:            }
043:
044:            // Expected range / not range
045:            public MismatchedCharException(char c, char lower, char upper_,
046:                    boolean matchNot, CharScanner scanner_) {
047:                super ("Mismatched char", scanner_.getFilename(), scanner_
048:                        .getLine(), scanner_.getColumn());
049:                mismatchType = matchNot ? NOT_RANGE : RANGE;
050:                foundChar = c;
051:                expecting = lower;
052:                upper = upper_;
053:                scanner = scanner_;
054:            }
055:
056:            // Expected token / not token
057:            public MismatchedCharException(char c, char expecting_,
058:                    boolean matchNot, CharScanner scanner_) {
059:                super ("Mismatched char", scanner_.getFilename(), scanner_
060:                        .getLine(), scanner_.getColumn());
061:                mismatchType = matchNot ? NOT_CHAR : CHAR;
062:                foundChar = c;
063:                expecting = expecting_;
064:                scanner = scanner_;
065:            }
066:
067:            // Expected BitSet / not BitSet
068:            public MismatchedCharException(char c, BitSet set_,
069:                    boolean matchNot, CharScanner scanner_) {
070:                super ("Mismatched char", scanner_.getFilename(), scanner_
071:                        .getLine(), scanner_.getColumn());
072:                mismatchType = matchNot ? NOT_SET : SET;
073:                foundChar = c;
074:                set = set_;
075:                scanner = scanner_;
076:            }
077:
078:            /**
079:             * Returns a clean error message (no line number/column information)
080:             */
081:            public String getMessage() {
082:                StringBuffer sb = new StringBuffer();
083:
084:                switch (mismatchType) {
085:                case CHAR:
086:                    sb.append("expecting ");
087:                    appendCharName(sb, expecting);
088:                    sb.append(", found ");
089:                    appendCharName(sb, foundChar);
090:                    break;
091:                case NOT_CHAR:
092:                    sb.append("expecting anything but '");
093:                    appendCharName(sb, expecting);
094:                    sb.append("'; got it anyway");
095:                    break;
096:                case RANGE:
097:                case NOT_RANGE:
098:                    sb.append("expecting token ");
099:                    if (mismatchType == NOT_RANGE)
100:                        sb.append("NOT ");
101:                    sb.append("in range: ");
102:                    appendCharName(sb, expecting);
103:                    sb.append("..");
104:                    appendCharName(sb, upper);
105:                    sb.append(", found ");
106:                    appendCharName(sb, foundChar);
107:                    break;
108:                case SET:
109:                case NOT_SET:
110:                    sb.append("expecting "
111:                            + (mismatchType == NOT_SET ? "NOT " : "")
112:                            + "one of (");
113:                    int[] elems = set.toArray();
114:                    for (int i = 0; i < elems.length; i++) {
115:                        appendCharName(sb, elems[i]);
116:                    }
117:                    sb.append("), found ");
118:                    appendCharName(sb, foundChar);
119:                    break;
120:                default:
121:                    sb.append(super .getMessage());
122:                    break;
123:                }
124:
125:                return sb.toString();
126:            }
127:
128:            /** Append a char to the msg buffer.  If special,
129:             *  then show escaped version
130:             */
131:            private void appendCharName(StringBuffer sb, int c) {
132:                switch (c) {
133:                case 65535:
134:                    // 65535 = (char) -1 = EOF
135:                    sb.append("'<EOF>'");
136:                    break;
137:                case '\n':
138:                    sb.append("'\\n'");
139:                    break;
140:                case '\r':
141:                    sb.append("'\\r'");
142:                    break;
143:                case '\t':
144:                    sb.append("'\\t'");
145:                    break;
146:                default:
147:                    sb.append('\'');
148:                    sb.append((char) c);
149:                    sb.append('\'');
150:                    break;
151:                }
152:            }
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.