aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc/util.clj
diff options
context:
space:
mode:
authorShagun Agrawal <agrawalshagun07@gmail.com>2024-12-30 21:06:27 +0530
committerShagun Agrawal <agrawalshagun07@gmail.com>2024-12-30 21:06:27 +0530
commit99aa43a28e527ac89eef26f5aba5b0989ab5da35 (patch)
tree17a44a21a5129c13abb3868fb49670f1a052faa4 /src/cljcc/util.clj
parent6a94b6abab645269c596154ce6812cbeb3811ec5 (diff)
Fix lexer bug, pass parsing stage
Diffstat (limited to 'src/cljcc/util.clj')
-rw-r--r--src/cljcc/util.clj17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/cljcc/util.clj b/src/cljcc/util.clj
index 7f59407..351b11f 100644
--- a/src/cljcc/util.clj
+++ b/src/cljcc/util.clj
@@ -87,19 +87,32 @@
(defn matches-regex [re s]
(not (nil? (re-matches re s))))
+(def unsigned-long-re-without-wordbreak #"[0-9]+([lL][uU]|[uU][lL])")
+(def signed-long-re-without-wordbreak #"[0-9]+[lL]")
+(def unsigned-int-re-without-wordbreak #"[0-9]+[uU]")
+(def signed-int-re-without-wordbreak #"[0-9]+")
+(def floating-point-constant-without-wordbreak #"([0-9]*\.[0-9]+|[0-9]+\.?)[Ee][+-]?[0-9]+|[0-9]*\.[0-9]+|[0-9]+\.")
+
(def unsigned-long-re #"([0-9]+([lL][uU]|[uU][lL]))[^\w.]")
(def signed-long-re #"([0-9]+[lL])[^\w.]")
(def unsigned-int-re #"([0-9]+[uU])[^\w.]")
(def signed-int-re #"([0-9]+)[^\w.]")
(def floating-point-constant #"(([0-9]*\.[0-9]+|[0-9]+\.?)[Ee][+-]?[0-9]+|[0-9]*\.[0-9]+|[0-9]+\.)[^\w.]")
+(defn- re-find-indexed [re s]
+ (let [matcher (re-matcher re s)]
+ (when (.find matcher)
+ [(.group matcher 1)
+ (.start matcher 1)
+ (.end matcher 1)])))
+
(defn match-regex
"Returns matched string and remaining string tuple, otherwise returns nil.
The first match by re-finds must be the starting subsequence, otherwise false."
[re s]
- (when-let [matched (second (re-find re s))]
- (when (str/starts-with? s matched)
+ (when-let [[matched start-index _] (re-find-indexed re s)]
+ (when (and (= 0 start-index) (str/starts-with? s matched))
[matched (str/replace-first s matched "")])))
(defn read-number