From 0ee88ddc6cfc1b2a73692b40db72215884a3f535 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 27 Jul 2025 18:19:54 -0400 Subject: [PATCH] xo-expression: less-than-or-equal --- include/xo/tokenizer/tokenizer.hpp | 52 ++++++++++++++++++++++-------- include/xo/tokenizer/tokentype.hpp | 6 ++++ src/tokenizer/tokentype.cpp | 2 ++ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/include/xo/tokenizer/tokenizer.hpp b/include/xo/tokenizer/tokenizer.hpp index ab4a9d6d..7984126c 100644 --- a/include/xo/tokenizer/tokenizer.hpp +++ b/include/xo/tokenizer/tokenizer.hpp @@ -186,13 +186,6 @@ namespace xo { bool tokenizer::is_1char_punctuation(CharT ch) const { switch(ch) { - case '<': - return true; - case '>': - /* can't be punctuation - * - appears in tk_yields token: -> - */ - return false; case '(': return true; case ')': @@ -205,6 +198,14 @@ namespace xo { return true; case '}': return true; + case '<': + /* can't be 1char punctuation -- can begin lessequal token */ + return false; + case '>': + /* can't be 1char punctuation -- can begin greatequal token, + * and appears in tk_yields token + */ + return false; case ',': return true; case ';': @@ -249,6 +250,12 @@ namespace xo { */ switch(ch) { + case '<': + /* can begin <= */ + return true; + case '>': + /* can begin >= */ + return true; case ':': /* can begin := */ return true; @@ -621,13 +628,33 @@ namespace xo { break; } case '<': - tk_type = tokentype::tk_leftangle; - ++ix; + { + log && log("leftangle or lessequal token"); + + if (*(ix + 1) == '=') { + tk_type = tokentype::tk_lessequal; + ++ix; + ++ix; + } else { + tk_type = tokentype::tk_leftangle; + ++ix; + } break; + } case '>': - tk_type = tokentype::tk_rightangle; - ++ix; + { + log && log("rightangle or greatequal token"); + + if (*(ix + 1) == '=') { + tk_type = tokentype::tk_greatequal; + ++ix; + ++ix; + } else { + tk_type = tokentype::tk_rightangle; + ++ix; + } break; + } case '(': tk_type = tokentype::tk_leftparen; ++ix; @@ -683,9 +710,6 @@ namespace xo { (error_type(__FUNCTION__ /*src_function*/, "illegal input character", input_state_, - //current_line_, - //current_pos_, - //initial_whitespace, (ix - tk_start))); } diff --git a/include/xo/tokenizer/tokentype.hpp b/include/xo/tokenizer/tokentype.hpp index 92d9bf60..eeeb7dd0 100644 --- a/include/xo/tokenizer/tokentype.hpp +++ b/include/xo/tokenizer/tokentype.hpp @@ -88,6 +88,12 @@ namespace xo { /** right-hand angle bracket @c '>' **/ tk_rightangle, + /** less-equal @c '<=' **/ + tk_lessequal, + + /** great-equal @c '>=' **/ + tk_greatequal, + /** dot @c '.' **/ tk_dot, diff --git a/src/tokenizer/tokentype.cpp b/src/tokenizer/tokentype.cpp index 745651a7..33d683de 100644 --- a/src/tokenizer/tokentype.cpp +++ b/src/tokenizer/tokentype.cpp @@ -28,6 +28,8 @@ namespace xo { CASE(tk_leftangle); CASE(tk_rightangle); + CASE(tk_lessequal); + CASE(tk_greatequal); CASE(tk_dot); CASE(tk_comma); CASE(tk_colon);