diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/parse/lex.cpp | 29 | ||||
-rw-r--r-- | src/parse/parseerror.cpp | 4 | ||||
-rw-r--r-- | src/parse/parseerror.hpp | 2 |
3 files changed, 31 insertions, 4 deletions
diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp index 5289dd31..32ed8829 100644 --- a/src/parse/lex.cpp +++ b/src/parse/lex.cpp @@ -36,6 +36,7 @@ Lexer::Lexer(::std::string filename): #define BLOCKCOMMENT -2 #define SINGLEQUOTE -3 #define DOUBLEQUOTE -4 +#define SHEBANG -5 // NOTE: This array must be kept sorted, or symbols are will be skipped #define TOKENT(str, sym) {sizeof(str)-1, str, sym} @@ -48,6 +49,7 @@ static const struct { TOKENT("!=", TOK_EXCLAM_EQUAL), TOKENT("\"", DOUBLEQUOTE), TOKENT("#", 0), + TOKENT("#!", SHEBANG), TOKENT("#![",TOK_CATTR_OPEN), TOKENT("#[", TOK_ATTR_OPEN), TOKENT("$", TOK_DOLLAR), @@ -251,6 +253,31 @@ Token Lexer::getTokenInt() try { char ch = this->getc(); + + if( ch == '#' && m_line == 1 && m_line_ofs == 1 ) { + switch(ch = this->getc()) + { + case '!': + switch(ch = this->getc()) + { + case '/': + // SHEBANG! + while( ch != '\n' ) + ch = this->getc(); + return Token(TOK_NEWLINE); + case '[': + return Token(TOK_CATTR_OPEN); + default: + throw ParseError::BadChar(*this, ch); + } + case '[': + return Token(TOK_ATTR_OPEN); + default: + this->ungetc(); + //return Token(TOK_HASH); + throw ParseError::BadChar(*this, ch); + } + } if( ch == '\n' ) return Token(TOK_NEWLINE); @@ -484,7 +511,7 @@ Token Lexer::getTokenInt() } else { - throw ParseError::BadChar(ch); + throw ParseError::BadChar(*this, ch); } } else if( sym > 0 ) diff --git a/src/parse/parseerror.cpp b/src/parse/parseerror.cpp index bd9d5a7c..e05ecb05 100644 --- a/src/parse/parseerror.cpp +++ b/src/parse/parseerror.cpp @@ -47,10 +47,10 @@ CompileError::Todo::~Todo() throw() {
}
-ParseError::BadChar::BadChar(char character):
+ParseError::BadChar::BadChar(const TokenStream& lex, char character):
m_char(character)
{
- ::std::cout << "BadChar(" << character << ")" << ::std::endl;
+ ::std::cout << lex.getPosition() << ": BadChar(" << character << ")" << ::std::endl;
}
ParseError::BadChar::~BadChar() throw()
{
diff --git a/src/parse/parseerror.hpp b/src/parse/parseerror.hpp index 1888a105..751af585 100644 --- a/src/parse/parseerror.hpp +++ b/src/parse/parseerror.hpp @@ -15,7 +15,7 @@ class BadChar: {
char m_char;
public:
- BadChar(char character);
+ BadChar(const TokenStream& lex, char character);
virtual ~BadChar() throw ();
};
|