diff --git a/modcc/lexer.cpp b/modcc/lexer.cpp index dc5851ecdbd3c39d6ce978c7c3086500f97570b6..086a5a80e923e69667e807d391643fdb907138d0 100644 --- a/modcc/lexer.cpp +++ b/modcc/lexer.cpp @@ -20,7 +20,7 @@ inline bool is_alphanumeric(char c) { return (is_numeric(c) || is_alpha(c) ); } inline bool is_whitespace(char c) { - return (c==' ' || c=='\t' || c=='\v' || c=='\f'); + return (c==' ' || c=='\t' || c=='\v' || c=='\f' || c=='\n' || c=='\r'); } inline bool is_eof(char c) { return (c==0); @@ -97,14 +97,23 @@ Token Lexer::parse() { // identifier or keyword case 'a' ... 'z': case 'A' ... 'Z': - case '_': + case '_': { // get std::string of the identifier - t.spelling = identifier(); - t.type - = status_==lexerStatus::error - ? tok::reserved - : get_identifier_type(t.spelling); + auto id = identifier(); + if (id == "UNITSON" || id == "UNITSOFF") continue; + if (id == "COMMENT") { + while (!is_eof(*current_)) { + while (is_whitespace(*current_) || !is_alpha(*current_)) current_++; + if (identifier() == "ENDCOMMENT") break; + } + continue; + } + t.spelling = id; + t.type = status_ == lexerStatus::error + ? tok::reserved + : get_identifier_type(t.spelling); return t; + } case '(': t.type = tok::lparen; t.spelling += character(); diff --git a/modcc/parser.cpp b/modcc/parser.cpp index 3cacb0f1057ee33f5a8762ce9e8cd352f7afd90f..efeb1cac10905c4a883f0b8c6b056293dc1c9ee9 100644 --- a/modcc/parser.cpp +++ b/modcc/parser.cpp @@ -35,15 +35,6 @@ bool Parser::expect(tok tok, std::string const& str) { return false; } -void Parser::parse_unit() { - if(token_.type == tok::lparen) { - while (token_.type != tok::rparen) { - get_token(); - } - get_token(); // consume ')' - } -} - void Parser::error(std::string msg) { std::string location_info = pprintf( "%:% ", module_ ? module_->source_name() : "", token_.location); @@ -138,12 +129,6 @@ bool Parser::parse() { module_->add_callable(std::move(f)); } break; - case tok::unitson : - get_token(); - break; - case tok::unitsoff : - get_token(); - break; default : error(pprintf("expected block type, found '%'", token_.spelling)); break; @@ -835,8 +820,6 @@ expression_ptr Parser::parse_prototype(std::string name=std::string()) { get_token(); // consume the identifier - parse_unit(); // consume the unit if provided - // look for a comma if(!(token_.type == tok::comma || token_.type==tok::rparen)) { error( "expected a comma or closing parenthesis, found '" @@ -967,8 +950,6 @@ symbol_ptr Parser::parse_function() { auto p = parse_prototype(); if(p==nullptr) return nullptr; - parse_unit(); - // check for opening left brace { if(!expect(tok::lbrace)) return nullptr; diff --git a/modcc/parser.hpp b/modcc/parser.hpp index 09130e9a83b33f0707aede7ea0906915d47864c3..49512f7ef5053926438494f9544afacca09f8237 100644 --- a/modcc/parser.hpp +++ b/modcc/parser.hpp @@ -81,7 +81,6 @@ private: Parser(); Parser(Parser const &); - void parse_unit(); bool expect(tok, const char *str=""); bool expect(tok, std::string const& str); };