]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/antlr2/src/CharScanner.cpp
Security-59754.80.3.tar.gz
[apple/security.git] / OSX / libsecurity_codesigning / antlr2 / src / CharScanner.cpp
1 /* ANTLR Translator Generator
2 * Project led by Terence Parr at http://www.jGuru.com
3 * Software rights: http://www.antlr.org/license.html
4 *
5 * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/src/CharScanner.cpp#2 $
6 */
7
8 #include <stdio.h>
9 #include <string>
10
11 #include "antlr/CharScanner.hpp"
12 #include "antlr/CommonToken.hpp"
13
14 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
15 namespace antlr {
16 #endif
17 ANTLR_C_USING(exit)
18
19 CharScanner::CharScanner(InputBuffer& cb, bool case_sensitive )
20 : saveConsumedInput(true) //, caseSensitiveLiterals(true)
21 , caseSensitive(case_sensitive)
22 , literals(CharScannerLiteralsLess(this))
23 , inputState(new LexerInputState(cb))
24 , commitToPath(false)
25 , tabsize(8)
26 , traceDepth(0)
27 {
28 setTokenObjectFactory(&CommonToken::factory);
29 }
30
31 CharScanner::CharScanner(InputBuffer* cb, bool case_sensitive )
32 : saveConsumedInput(true) //, caseSensitiveLiterals(true)
33 , caseSensitive(case_sensitive)
34 , literals(CharScannerLiteralsLess(this))
35 , inputState(new LexerInputState(cb))
36 , commitToPath(false)
37 , tabsize(8)
38 , traceDepth(0)
39 {
40 setTokenObjectFactory(&CommonToken::factory);
41 }
42
43 CharScanner::CharScanner( const LexerSharedInputState& state, bool case_sensitive )
44 : saveConsumedInput(true) //, caseSensitiveLiterals(true)
45 , caseSensitive(case_sensitive)
46 , literals(CharScannerLiteralsLess(this))
47 , inputState(state)
48 , commitToPath(false)
49 , tabsize(8)
50 , traceDepth(0)
51 {
52 setTokenObjectFactory(&CommonToken::factory);
53 }
54
55 /** Report exception errors caught in nextToken() */
56 void CharScanner::reportError(const RecognitionException& ex)
57 {
58 fprintf(stderr, "%s", (ex.toString() + "\n").c_str());
59 }
60
61 /** Parser error-reporting function can be overridden in subclass */
62 void CharScanner::reportError(const ANTLR_USE_NAMESPACE(std)string& s)
63 {
64 if ( getFilename()=="" )
65 fprintf(stderr, "%s", ("error: " + s + "\n").c_str());
66 else
67 fprintf(stderr, "%s", (getFilename() + ": error: " + s + "\n").c_str());
68 }
69
70 /** Parser warning-reporting function can be overridden in subclass */
71 void CharScanner::reportWarning(const ANTLR_USE_NAMESPACE(std)string& s)
72 {
73 if ( getFilename()=="" )
74 fprintf(stderr, "%s", ("warning: " + s + "\n").c_str());
75 else
76 fprintf(stderr, "%s", (getFilename() + ": warning: " + s + "\n").c_str());
77 }
78
79 void CharScanner::traceIndent()
80 {
81 for( int i = 0; i < traceDepth; i++ )
82 printf(" ");
83 }
84
85 void CharScanner::traceIn(const char* rname)
86 {
87 traceDepth++;
88 traceIndent();
89 printf("> lexer %s; c==%d\n", rname, LA(1));
90 }
91
92 void CharScanner::traceOut(const char* rname)
93 {
94 traceIndent();
95 printf("< lexer %s; c==%d\n", rname, LA(1));
96 traceDepth--;
97 }
98
99 #ifndef NO_STATIC_CONSTS
100 const int CharScanner::NO_CHAR;
101 const int CharScanner::EOF_CHAR;
102 #endif
103
104 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
105 }
106 #endif
107