summaryrefslogtreecommitdiff
path: root/cpp.fun
diff options
context:
space:
mode:
authorVladimir Azarov <avm@intermediate-node.net>2025-04-06 23:22:30 +0200
committerVladimir Azarov <avm@intermediate-node.net>2025-04-06 23:22:30 +0200
commit8e2dc7712de206b87e1c46df9383c3fa1e18a43a (patch)
treeee2f199b35eb4374e5638f1c8506d5a6c9a88d4e /cpp.fun
parent9d724f17e813fa344d485329d33b5f5ecf8197a3 (diff)
Debug print preprocessor function
Diffstat (limited to 'cpp.fun')
-rw-r--r--cpp.fun31
1 files changed, 30 insertions, 1 deletions
diff --git a/cpp.fun b/cpp.fun
index 424d3ca..f9d16e5 100644
--- a/cpp.fun
+++ b/cpp.fun
@@ -91,7 +91,36 @@ functor Cpp(T: TOKENIZER): CPP = struct
fun debugPrint fname =
let
val stream = create fname
+ val cache = T.S.pposCacheInit $ hd $ #fileInfo stream
+
+ fun print' cache stream first =
+ let
+ val (tk, stream) = getToken stream
+ val ` = Int.toString
+ in
+ case tk of
+ T.NewLine => print' cache stream first
+ | T.EOS => ()
+ | tk =>
+ let
+ val ((line, col), cache') = T.S.pposCacheAdvance
+ (getLastPos stream) cache
+ fun printTk () =
+ print $ `col ^ ":" ^ T.token2str tk ^ " "
+ in
+ if T.S.pposCacheGetLine cache = line andalso not first then
+ printTk ()
+ else
+ (if not first then print "\n" else ();
+ printLn $ T.S.pposCacheGetFname cache' ^ ":" ^ `line;
+ print "\t";
+ printTk ());
+ print' cache' stream false
+ end
+ end
in
- ()
+ print' cache stream true;
+ print "\n"
end
+
end