From 90b8a837789eb99c44bcea9abee53012f2df71a4 Mon Sep 17 00:00:00 2001 From: Shagun Agrawal Date: Sun, 15 Dec 2024 10:26:36 +0530 Subject: Add lexer for unsigned int / long --- src/cljcc/util.clj | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/cljcc/util.clj') diff --git a/src/cljcc/util.clj b/src/cljcc/util.clj index d851a62..f75dd5f 100644 --- a/src/cljcc/util.clj +++ b/src/cljcc/util.clj @@ -91,13 +91,19 @@ (catch Exception _e false))) +(defn- matches-regex [re s] + (not (nil? (re-matches re s)))) + (defn read-number - "Returns number and number type tuple. + "Returns number in string form. Checks whether number is valid long. If no, checks if it valid int. Otherwise error." [s line col] - (if-let [s (valid-long? s)] + (if-let [_ (or (matches-regex #"[0-9]+" s) + (matches-regex #"[0-9]+[lL]" s) + (matches-regex #"[0-9]+[uU]" s) + (matches-regex #"[0-9]+([lL][uU]|[uU][lL])" s))] s (exc/lex-error {:line line :col col}))) -- cgit v1.2.3