diff --git a/include/xo/tokenizer/tokenizer.hpp b/include/xo/tokenizer/tokenizer.hpp index 8c1b131a..258d4900 100644 --- a/include/xo/tokenizer/tokenizer.hpp +++ b/include/xo/tokenizer/tokenizer.hpp @@ -211,7 +211,11 @@ namespace xo { /* can't be 1char punctuation -- can begin assignment token */ return false; case '=': - return true; + /* can't be 1char punctuation -- can begin comparison token '==' */ + return false; + case '!': + /* can't be 1char punctuation -- can begin comparison token '!=' */ + return false; case '-': /* can't be punctuation * - can appear inside f64 token: e.g. 1.23e-9. @@ -246,6 +250,12 @@ namespace xo { case ':': /* can begin := */ return true; + case '=': + /* can begin == */ + return true; + case '!': + /* can begin != */ + return true; } return false; @@ -446,6 +456,30 @@ namespace xo { ++ix; } break; + case '=': + log && log("singleassign or cmpeq token"); + + if (*(ix + 1) == '=') { + tk_type = tokentype::tk_cmpeq; + ++ix; + ++ix; + } else { + /* standalone '=' */ + tk_type = tokentype::tk_singleassign; + ++ix; + } + break; + case '!': + if (*(ix + 1) == '=') { + tk_type = tokentype::tk_cmpne; + ++ix; + ++ix; + } else { + /* standlone '!' */ + + // TODO + } + break; case '"': { log && log("recognize string-token"); @@ -638,10 +672,6 @@ namespace xo { } break; } - case '=': - tk_type = tokentype::tk_singleassign; - ++ix; - break; default: break; } diff --git a/include/xo/tokenizer/tokentype.hpp b/include/xo/tokenizer/tokentype.hpp index 81a852fa..92d9bf60 100644 --- a/include/xo/tokenizer/tokentype.hpp +++ b/include/xo/tokenizer/tokentype.hpp @@ -126,6 +126,11 @@ namespace xo { /** operator @c '/' **/ tk_slash, + /** operator @c '==' **/ + tk_cmpeq, + /** operator @c '!=' **/ + tk_cmpne, + /** keyword @c 'type' **/ tk_type, diff --git a/src/tokenizer/tokentype.cpp b/src/tokenizer/tokentype.cpp index c19d023b..745651a7 100644 --- a/src/tokenizer/tokentype.cpp +++ b/src/tokenizer/tokentype.cpp @@ -43,6 +43,9 @@ namespace xo { CASE(tk_star); CASE(tk_slash); + CASE(tk_cmpeq); + CASE(tk_cmpne); + CASE(tk_type); CASE(tk_def); CASE(tk_lambda);