From 8e2dc7712de206b87e1c46df9383c3fa1e18a43a Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Sun, 6 Apr 2025 23:22:30 +0200 Subject: Debug print preprocessor function --- cpp.fun | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'cpp.fun') 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 -- cgit v1.2.3