diff options
author | Vladimir Azarov <avm@intermediate-node.net> | 2025-05-14 03:19:35 +0200 |
---|---|---|
committer | Vladimir Azarov <avm@intermediate-node.net> | 2025-05-14 03:19:35 +0200 |
commit | 3d568063a49204193009ad6a2637176b38902525 (patch) | |
tree | a29e144f61133c7cd505f3657ae4abf27b12f19f /tokenizer.fun | |
parent | 52a6f8656e8a600a2c59fa2802fb46fafb30de45 (diff) |
Printf
Diffstat (limited to 'tokenizer.fun')
-rw-r--r-- | tokenizer.fun | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/tokenizer.fun b/tokenizer.fun index 5162308..12b3257 100644 --- a/tokenizer.fun +++ b/tokenizer.fun @@ -17,7 +17,7 @@ struct EOS | NewLine | MacroStart of string | - MacroEnd | + MacroEnd of string | Num of numConst | @@ -152,7 +152,6 @@ struct [ (NewLine, "@NewLine"), (EOS, "@EOS"), - (MacroEnd, "@Mend"), (kwBreak, &"break"), (kwCase, &"case"), @@ -284,6 +283,7 @@ struct val token2str = fn Id s => s | MacroStart macro => "m(" ^ macro ^ ")" + | MacroEnd macro => "mend(" ^ macro ^ ")" | Num (IntConst (it, str, sfx)) => let val intType = @@ -304,7 +304,7 @@ struct SOME (_, repr) => repr | NONE => raise TokenWithoutRepr - fun printToken tk = print $ token2str tk + fun printToken tk = printf A1 token2str tk % fun isIdStart c = Char.isAlpha c orelse c = #"_" fun isIdBody c = Char.isAlphaNum c orelse c = #"_" @@ -395,8 +395,8 @@ struct List.app (fn (v, p) => fsmInsert' T 0 v $ explode p) tokenRepr; if !nextState <> maxStates then - printLn $ "note: Fsm table size can be smaller: " - ^ Int.toString (!nextState) ^ " is enough" + printf `"note: Fsm table size can be smaller: " + I (!nextState) `" is enough" % else (); T end @@ -406,7 +406,7 @@ struct let fun printRow i row = if i = length row then - print "\n" + output "\n" else let val state = sub (row, i) @@ -414,7 +414,7 @@ struct if state = ~1 then () else - print ((str (chr i)) ^ ": " ^ (Int.toString state) ^ ", "); + printf C (chr i) `": " I state `", " %; printRow (i + 1) row end @@ -425,14 +425,14 @@ struct let val (tk, row) = sub (buf, rowNum) in - print ((token2string tk) ^ ": "); + printf A1 token2string tk `": " %; printRow 0 row; print' (rowNum + 1) buf end in - print ("NextState: " ^ Int.toString (!nextState) ^ "\n"); + printf `"NextState: " I (!nextState) `"\n" %; print' 0 buf; - print "\n" + output "\n" end *) @@ -509,7 +509,7 @@ struct fun keywordHashtableGen () = let - val table = H.create 128 + val table = H.createLog 7 val () = List.app (fn (tk, repr) => @@ -983,19 +983,17 @@ struct fun print' line _ ((NewLine, _) :: tks) = print' (line + 1) true tks | print' line firstOnLine ((tk, _) :: tks) = ( - if firstOnLine then ( - print "\n"; - printLn $ fname ^ ":" ^ Int.toString line; - print "\t") + if firstOnLine then + printf `"\n" `fname `":" I line `"\t" % else (); printToken tk; - print " "; + output " "; print' line false tks ) | print' _ _ [] = () in print' 1 true tkl; - print "\n" + output "\n" end end |