summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/Scanner.l
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Slice/Scanner.l')
-rw-r--r--cpp/src/Slice/Scanner.l440
1 files changed, 217 insertions, 223 deletions
diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l
index 9821508df30..0e7eef5a7fe 100644
--- a/cpp/src/Slice/Scanner.l
+++ b/cpp/src/Slice/Scanner.l
@@ -9,7 +9,7 @@
//
// **********************************************************************
-#include <Slice/GrammarUtil.h> // Before Grammer.h, so that YYSTYPE is defined
+#include <Slice/GrammarUtil.h> // Before Grammer.h, so that YYSTYPE is defined
#include <Slice/Grammar.h>
#include <IceUtil/InputUtil.h>
@@ -50,7 +50,7 @@
# define slice_wrap() 1
# endif
# ifdef ICE_64
-# pragma error_messages(off,truncwarn)
+# pragma error_messages(off,truncwarn)
# endif
#endif
@@ -63,7 +63,7 @@ namespace Slice
//
// Definitions for the case-insensitive keyword-token map.
//
-typedef std::map<std::string, int, Slice::CICompare> StringTokenMap;
+typedef std::map<std::string, int> StringTokenMap;
static StringTokenMap keywordMap;
void initScanner();
@@ -71,7 +71,7 @@ int checkKeyword(string&);
}
-#define YY_USER_INIT initScanner();
+#define YY_USER_INIT initScanner();
%}
@@ -80,11 +80,11 @@ int checkKeyword(string&);
%option prefix="slice_"
%option outfile="lex.yy.c"
-identifier \\?[[:alpha:]_][[:alnum:]_]*
-integer_constant (\+|-)?((0[0-7]+)|(0x[[:xdigit:]]+)|([[:digit:]]+))
-fractional_constant (\+|-)?(([[:digit:]]*\.[[:digit:]]+)|([[:digit:]]+\.))
-exponent_part (e|E)(\+|-)?[[:digit:]]+
-floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{exponent_part}))[fF]?
+identifier \\?[[:alpha:]_][[:alnum:]_]*
+integer_constant (\+|-)?((0[0-7]+)|(0x[[:xdigit:]]+)|([[:digit:]]+))
+fractional_constant (\+|-)?(([[:digit:]]*\.[[:digit:]]+)|([[:digit:]]+\.))
+exponent_part (e|E)(\+|-)?[[:digit:]]+
+floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{exponent_part}))[fF]?
%s BOMSCAN
%s MAINSCAN
@@ -125,11 +125,11 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e
int c;
do
{
- c = yyinput();
- if(c == '\n')
- {
- unit->nextLine();
- }
+ c = yyinput();
+ if(c == '\n')
+ {
+ unit->nextLine();
+ }
}
while(c != '\n' && c != EOF);
}
@@ -140,38 +140,38 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e
string comment = yytext + 2;
while(true)
{
- int c = yyinput();
- if(c == '\n')
- {
- comment += static_cast<char>(c);
- unit->nextLine();
- }
- else if(c == '*')
- {
- int next = yyinput();
- if(next == '/')
- {
- break;
- }
- else
- {
- comment += static_cast<char>(c);
- unput(next);
- }
- }
- else if(c == EOF)
- {
- unit->warning("EOF in comment");
- break;
- }
- else
- {
- comment += static_cast<char>(c);
- }
+ int c = yyinput();
+ if(c == '\n')
+ {
+ comment += static_cast<char>(c);
+ unit->nextLine();
+ }
+ else if(c == '*')
+ {
+ int next = yyinput();
+ if(next == '/')
+ {
+ break;
+ }
+ else
+ {
+ comment += static_cast<char>(c);
+ unput(next);
+ }
+ }
+ else if(c == EOF)
+ {
+ unit->warning("EOF in comment");
+ break;
+ }
+ else
+ {
+ comment += static_cast<char>(c);
+ }
}
if(!comment.empty() && comment[0] == '*')
{
- unit->setComment(comment);
+ unit->setComment(comment);
}
}
@@ -239,156 +239,149 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e
str->literal = "\"";
while(true)
{
- char c = static_cast<char>(yyinput());
+ char c = static_cast<char>(yyinput());
str->literal += c;
- if(c == '"')
- {
- break;
- }
- else if(c == EOF)
- {
- unit->error("EOF in string");
- break;
- }
- else if(c == '\n')
- {
- unit->error("newline in string");
- }
- else if(c == '\\')
- {
- char next = static_cast<char>(yyinput());
+ if(c == '"')
+ {
+ break;
+ }
+ else if(c == EOF)
+ {
+ unit->error("EOF in string");
+ break;
+ }
+ else if(c == '\n')
+ {
+ unit->error("newline in string");
+ }
+ else if(c == '\\')
+ {
+ char next = static_cast<char>(yyinput());
str->literal += next;
- switch(next)
- {
- case '\\':
- case '"':
- case '\'':
- {
- str->v += next;
- break;
- }
-
- case 'n':
- {
- str->v += '\n';
- break;
- }
-
- case 'r':
- {
- str->v += '\r';
- break;
- }
-
- case 't':
- {
- str->v += '\t';
- break;
- }
-
- case 'v':
- {
- str->v += '\v';
- break;
- }
-
- case 'f':
- {
- str->v += '\f';
- break;
- }
-
- case 'a':
- {
- str->v += '\a';
- break;
- }
-
- case 'b':
- {
- str->v += '\b';
- break;
- }
-
- case '?':
- {
- str->v += '\?';
- break;
- }
-
- case '0':
- case '1':
- case '2':
- case '3':
- {
- static string octalDigits = "01234567";
- unsigned short us = next - '0';
- if(octalDigits.find_first_of(next = static_cast<char>(yyinput())) != string::npos)
- {
+ switch(next)
+ {
+ case '\\':
+ case '"':
+ case '\'':
+ {
+ str->v += next;
+ break;
+ }
+ case 'n':
+ {
+ str->v += '\n';
+ break;
+ }
+ case 'r':
+ {
+ str->v += '\r';
+ break;
+ }
+ case 't':
+ {
+ str->v += '\t';
+ break;
+ }
+ case 'v':
+ {
+ str->v += '\v';
+ break;
+ }
+ case 'f':
+ {
+ str->v += '\f';
+ break;
+ }
+
+ case 'a':
+ {
+ str->v += '\a';
+ break;
+ }
+
+ case 'b':
+ {
+ str->v += '\b';
+ break;
+ }
+
+ case '?':
+ {
+ str->v += '\?';
+ break;
+ }
+
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ {
+ static string octalDigits = "01234567";
+ unsigned short us = next - '0';
+ if(octalDigits.find_first_of(next = static_cast<char>(yyinput())) != string::npos)
+ {
str->literal += next;
- us = us * 8 + next - '0';
- if(octalDigits.find_first_of(next = static_cast<char>(yyinput())) != string::npos)
- {
- us = us * 8 + next - '0';
- }
- else
- {
- unput(next);
- }
- }
- else
- {
- unput(next);
- }
- if(us == 0)
- {
- unit->error("illegal NUL character in string constant");
- }
- str->v += static_cast<char>(us);
- break;
- }
- case 'x':
- {
- IceUtil::Int64 ull = 0;
- while(isxdigit(static_cast<unsigned char>(next = static_cast<char>(yyinput()))))
- {
+ us = us * 8 + next - '0';
+ if(octalDigits.find_first_of(next = static_cast<char>(yyinput())) != string::npos)
+ {
+ us = us * 8 + next - '0';
+ }
+ else
+ {
+ unput(next);
+ }
+ }
+ else
+ {
+ unput(next);
+ }
+ if(us == 0)
+ {
+ unit->error("illegal NUL character in string constant");
+ }
+ str->v += static_cast<char>(us);
+ break;
+ }
+ case 'x':
+ {
+ IceUtil::Int64 ull = 0;
+ while(isxdigit(static_cast<unsigned char>(next = static_cast<char>(yyinput()))))
+ {
str->literal += next;
- ull *= 16;
- if(isdigit(static_cast<unsigned char>(next)))
- {
- ull += next - '0';
- }
- else if(islower(static_cast<unsigned char>(next)))
- {
- ull += next - 'a' + 10;
- }
- else
- {
- ull += next - 'A' + 10;
- }
- }
- unput(next);
- if(ull == 0)
- {
- unit->error("illegal NUL character in string constant");
- }
- str->v += static_cast<char>(ull);
- break;
- }
-
- // TODO: add universal character names
-
- default:
- {
- str->v += c;
- unput(next);
- }
- }
- }
- else
- {
- str->v += c;
- }
+ ull *= 16;
+ if(isdigit(static_cast<unsigned char>(next)))
+ {
+ ull += next - '0';
+ }
+ else if(islower(static_cast<unsigned char>(next)))
+ {
+ ull += next - 'a' + 10;
+ }
+ else
+ {
+ ull += next - 'A' + 10;
+ }
+ }
+ unput(next);
+ if(ull == 0)
+ {
+ unit->error("illegal NUL character in string constant");
+ }
+ str->v += static_cast<char>(ull);
+ break;
+ }
+ // TODO: add universal character names
+ default:
+ {
+ str->v += c;
+ unput(next);
+ }
+ }
+ }
+ else
+ {
+ str->v += c;
+ }
}
*yylvalp = str;
return ICE_STRING_LITERAL;
@@ -401,11 +394,11 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e
*yylvalp = itp;
if(!IceUtilInternal::stringToInt64(string(yytext), itp->v))
{
- assert(itp->v != 0);
- string msg = "integer constant `";
- msg += yytext;
- msg += "' out of range";
- unit->error(msg);
+ assert(itp->v != 0);
+ string msg = "integer constant `";
+ msg += yytext;
+ msg += "' out of range";
+ unit->error(msg);
}
return ICE_INTEGER_LITERAL;
}
@@ -420,42 +413,42 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e
char lastChar = literal[literal.size() - 1];
if(lastChar == 'f' || lastChar == 'F')
{
- literal = literal.substr(0, literal.size() - 1); // Clobber trailing 'f' or 'F' suffix
+ literal = literal.substr(0, literal.size() - 1); // Clobber trailing 'f' or 'F' suffix
}
ftp->v = strtod(literal.c_str(), 0);
if((ftp->v == HUGE_VAL || ftp->v == -HUGE_VAL) && errno == ERANGE)
{
- string msg = "floating-point constant `";
- msg += yytext;
- msg += "' too large (overflow)";
- unit->error(msg);
+ string msg = "floating-point constant `";
+ msg += yytext;
+ msg += "' too large (overflow)";
+ unit->error(msg);
}
else if(ftp->v == 0 && errno == ERANGE)
{
- string msg = "floating-point constant `";
- msg += yytext;
- msg += "' too small (underflow)";
- unit->error(msg);
+ string msg = "floating-point constant `";
+ msg += yytext;
+ msg += "' too small (underflow)";
+ unit->error(msg);
}
return ICE_FLOATING_POINT_LITERAL;
}
[[:space:]] {
// Ignore white-space
-
+
if(unit->currentLine() != 0)
{
BEGIN(MAINSCAN);
}
if(yytext[0] == '\n')
{
- unit->nextLine();
+ unit->nextLine();
}
}
<BOMSCAN>^"\357\273\277" {
// Ignore UTF-8 BOM, rule only active when parsing start of file.
-
+
BEGIN(MAINSCAN);
}
@@ -463,14 +456,14 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e
BEGIN(MAINSCAN);
if(yytext[0] < 32 || yytext[0] > 126)
{
- stringstream s;
- s << "illegal input character: '\\";
- s.width(3);
- s.fill('0');
- s << oct << static_cast<int>(static_cast<unsigned char>(yytext[0]));
- s << "'";
- unit->error(s.str());
- return BAD_CHAR;
+ stringstream s;
+ s << "illegal input character: '\\";
+ s.width(3);
+ s.fill('0');
+ s << oct << static_cast<int>(static_cast<unsigned char>(yytext[0]));
+ s << "'";
+ unit->error(s.str());
+ return BAD_CHAR;
}
return yytext[0];
}
@@ -515,6 +508,7 @@ initScanner()
keywordMap["true"] = ICE_TRUE;
keywordMap["idempotent"] = ICE_IDEMPOTENT;
keywordMap["optional"] = ICE_OPTIONAL;
+ keywordMap["Value"] = ICE_VALUE;
}
//
@@ -530,15 +524,15 @@ checkKeyword(string& id)
StringTokenMap::const_iterator pos = keywordMap.find(id);
if(pos != keywordMap.end())
{
- if(pos->first != id)
- {
- string msg;
- msg = "illegal identifier: `" + id + "' differs from keyword `";
- msg += pos->first + "' only in capitalization";
- unit->error(msg);
- id = pos->first;
- }
- return pos->second;
+ if(pos->first != id)
+ {
+ string msg;
+ msg = "illegal identifier: `" + id + "' differs from keyword `";
+ msg += pos->first + "' only in capitalization";
+ unit->error(msg);
+ id = pos->first;
+ }
+ return pos->second;
}
return ICE_IDENTIFIER;
}