OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
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$
6 */
7
8#include <iostream>
9
10#include "antlr/CharScanner.hpp"
11#include "antlr/CommonToken.hpp"
12
13#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
14namespace antlr {
15#endif
16ANTLR_C_USING(exit)
17
18CharScanner::CharScanner(InputBuffer& cb, bool case_sensitive )
19 : saveConsumedInput(true) //, caseSensitiveLiterals(true)
20 , caseSensitive(case_sensitive)
21 , literals(CharScannerLiteralsLess(this))
22 , inputState(new LexerInputState(cb))
23 , commitToPath(false)
24 , tabsize(8)
25 , traceDepth(0)
26{
27 setTokenObjectFactory(&CommonToken::factory);
28}
29
30CharScanner::CharScanner(InputBuffer* cb, bool case_sensitive )
31 : saveConsumedInput(true) //, caseSensitiveLiterals(true)
32 , caseSensitive(case_sensitive)
33 , literals(CharScannerLiteralsLess(this))
34 , inputState(new LexerInputState(cb))
35 , commitToPath(false)
36 , tabsize(8)
37 , traceDepth(0)
38{
39 setTokenObjectFactory(&CommonToken::factory);
40}
41
42CharScanner::CharScanner( const LexerSharedInputState& state, bool case_sensitive )
43 : saveConsumedInput(true) //, caseSensitiveLiterals(true)
44 , caseSensitive(case_sensitive)
45 , literals(CharScannerLiteralsLess(this))
46 , inputState(state)
47 , commitToPath(false)
48 , tabsize(8)
49 , traceDepth(0)
50{
51 setTokenObjectFactory(&CommonToken::factory);
52}
53
54/** Report exception errors caught in nextToken() */
55void CharScanner::reportError(const RecognitionException& ex)
56{
57 ANTLR_USE_NAMESPACE(std)cerr << ex.toString().c_str() << ANTLR_USE_NAMESPACE(std)endl;
58}
59
60/** Parser error-reporting function can be overridden in subclass */
61void CharScanner::reportError(const ANTLR_USE_NAMESPACE(std)string& s)
62{
63 if (getFilename() == "")
64 ANTLR_USE_NAMESPACE(std)cerr << "error: " << s.c_str() << ANTLR_USE_NAMESPACE(std)endl;
65 else
66 ANTLR_USE_NAMESPACE(std)cerr << getFilename().c_str() << ": error: " << s.c_str() << ANTLR_USE_NAMESPACE(std)endl;
67}
68
69/** Parser warning-reporting function can be overridden in subclass */
70void CharScanner::reportWarning(const ANTLR_USE_NAMESPACE(std)string& s)
71{
72 if (getFilename() == "")
73 ANTLR_USE_NAMESPACE(std)cerr << "warning: " << s.c_str() << ANTLR_USE_NAMESPACE(std)endl;
74 else
75 ANTLR_USE_NAMESPACE(std)cerr << getFilename().c_str() << ": warning: " << s.c_str() << ANTLR_USE_NAMESPACE(std)endl;
76}
77
78void CharScanner::traceIndent()
79{
80 for( int i = 0; i < traceDepth; i++ )
81 ANTLR_USE_NAMESPACE(std)cout << " ";
82}
83
84void CharScanner::traceIn(const char* rname)
85{
86 traceDepth++;
87 traceIndent();
88 ANTLR_USE_NAMESPACE(std)cout << "> lexer " << rname
89 << "; c==" << LA(1) << ANTLR_USE_NAMESPACE(std)endl;
90}
91
92void CharScanner::traceOut(const char* rname)
93{
94 traceIndent();
95 ANTLR_USE_NAMESPACE(std)cout << "< lexer " << rname
96 << "; c==" << LA(1) << ANTLR_USE_NAMESPACE(std)endl;
97 traceDepth--;
98}
99
100#ifndef NO_STATIC_CONSTS
101const int CharScanner::NO_CHAR;
102const int CharScanner::EOF_CHAR;
103#endif
104
105#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
106}
107#endif
108
virtual std::string toString() const
Return complete error message with line/column number info (if present)