source: trunk/yao/share/antlr-2.7.7/lib/csharp/antlr.runtime/antlr/NoViableAltForCharException.cs @ 1

Last change on this file since 1 was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

File size: 1.6 KB
Line 
1using System;
2using StringBuilder                             = System.Text.StringBuilder;
3
4namespace antlr
5{
6        /*ANTLR Translator Generator
7        * Project led by Terence Parr at http://www.jGuru.com
8        * Software rights: http://www.antlr.org/license.html
9        *
10        * $Id:$
11        */
12
13        //
14        // ANTLR C# Code Generator by Micheal Jordan
15        //                            Kunle Odutola       : kunle UNDERSCORE odutola AT hotmail DOT com
16        //                            Anthony Oguntimehin
17        //
18        // With many thanks to Eric V. Smith from the ANTLR list.
19        //
20       
21        [Serializable]
22        public class NoViableAltForCharException : RecognitionException
23        {
24                public char foundChar;
25               
26                public NoViableAltForCharException(char c, CharScanner scanner) :
27                                        base("NoViableAlt", scanner.getFilename(), scanner.getLine(), scanner.getColumn())
28                {
29                        foundChar = c;
30                }
31               
32                public NoViableAltForCharException(char c, string fileName, int line, int column) : 
33                                        base("NoViableAlt", fileName, line, column)
34                {
35                        foundChar = c;
36                }
37               
38                /*
39                * Returns a clean error message (no line number/column information)
40                */
41                override public string Message
42                {
43                        get
44                        {
45                                StringBuilder mesg = new StringBuilder("unexpected char: ");
46                       
47                                // I'm trying to mirror a change in the C++ stuff.
48                                // But java seems to lack something isprint-ish..
49                                // so we do it manually. This is probably too restrictive.
50                       
51                                if ((foundChar >= ' ') && (foundChar <= '~'))
52                                {
53                                        mesg.Append('\'');
54                                        mesg.Append(foundChar);
55                                        mesg.Append('\'');
56                                }
57                                else
58                                {
59                                        mesg.Append("0x");
60                                        mesg.Append(((int)foundChar).ToString("X"));
61                                }
62                                return mesg.ToString();
63                        }
64                }
65        }
66}
Note: See TracBrowser for help on using the repository browser.