aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc/util.clj
diff options
context:
space:
mode:
authorShagun Agrawal <agrawalshagun07@gmail.com>2024-12-15 10:26:36 +0530
committerShagun Agrawal <agrawalshagun07@gmail.com>2024-12-15 10:26:36 +0530
commit90b8a837789eb99c44bcea9abee53012f2df71a4 (patch)
treec50de54dca98789070bfc3f46887f066b4095ccb /src/cljcc/util.clj
parent3d60213c01955e54e8e33b88108b4251197fde86 (diff)
Add lexer for unsigned int / long
Diffstat (limited to 'src/cljcc/util.clj')
-rw-r--r--src/cljcc/util.clj10
1 files changed, 8 insertions, 2 deletions
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})))