summaryrefslogtreecommitdiff
path: root/vhdlparser/TokenMgrError.cc
blob: 3560805b1b47a97644b0e317743c822d58dd7436 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.cc Version 7.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
#include "TokenMgrError.h"

namespace vhdl {
namespace parser {

  /**
   * Returns a detailed message for the Error when it is thrown by the
   * token manager to indicate a lexical error.
   * Parameters :
   *    EOFSeen     : indicates if EOF caused the lexical error
   *    curLexState : lexical state in which this error occurred
   *    errorLine   : line number when the error occurred
   *    errorColumn : column number when the error occurred
   *    errorAfter  : prefix that was seen before this error occurred
   *    curJJChar     : the offending character
   * Note: You can customize the lexical error message by modifying this method.
   */
    JJString TokenMgrError::LexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, const JJString& errorAfter, JJChar curChar) {
#if 0
    JJString s;
    stringstream<JJString> ss;
    ss << "Lexical error at line " << errorLine << " column " << errorColumn
       << ".  Encountered: " << curChar << "(" << (int)curChar
       << ") after : \"" << errorAfter.c_str() << "\"";
    return (JJString)ss.rdbuf()->str();
#endif
    return EMPTY;
  }

  /**
   * You can also modify the body of this method to customize your error messages.
   * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
   * of end-users concern, so you can return something like :
   *
   *     "Internal Error : Please file a bug report .... "
   *
   * from this method for such cases in the release version of your parser.
   */
  JJString TokenMgrError::getMessage() {
    return message;
  }

  /*
   * Constructors of various flavors follow.
   */

  /** No arg constructor. */
  TokenMgrError::TokenMgrError() {
  }

  /** Constructor with message and reason. */
  TokenMgrError::TokenMgrError(const JJString& message, int reason) {
    errorCode = reason;
  }

  /** Full Constructor. */
  TokenMgrError::TokenMgrError(bool EOFSeen, int lexState, int errorLine, int errorColumn, const JJString& errorAfter, JJChar curChar, int reason) {
    message = LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar);
   errorCode = reason;
  }

// i < 16 - guaranteed
char hexChar(int i) {
  if (i < 10) {
    return i - '0';
  }
  return 'a' + (i - 10);
}

/**
 * Replaces unprintable characters by their escaped (or unicode escaped)
 * equivalents in the given string
 */
JJSimpleString addUnicodeEscapes(const JJString& str) {
  JJSimpleString retval;
  for (size_t i = 0; i < str.size(); i++) {
    JJChar ch = str[i];
    switch (ch)
    {
      case '\b':
        retval.append("\\b");
        continue;
      case '\t':
        retval.append("\\t");
        continue;
      case '\n':
        retval.append("\\n");
        continue;
      case '\f':
        retval.append("\\f");
        continue;
      case '\r':
        retval.append("\\r");
        continue;
      case '\\':
        retval.append("\\\\");
        continue;
      default:
        if (ch < 0xff) {
          retval += ch;
          continue;
        }
        retval.append("\\u");
        retval += (hexChar(ch >> 12));
        retval += (hexChar((ch & 0x0f00) >> 8));
        retval += (hexChar((ch & 0x00f0) >> 4));
        retval += (hexChar(ch & 0x000f));
        continue;
    }
  }
  return retval;
}

}
}
/* JavaCC - OriginalChecksum=ed66d80b94c73435ce2644e44f7b4d49 (do not edit this line) */