char class stuff
This commit is contained in:
parent
123e4b6ab4
commit
c743a99356
5 changed files with 97 additions and 8 deletions
|
@ -96,17 +96,13 @@ genCat ch = assert_total $
|
|||
"Cn" => Other NotAssigned
|
||||
|
||||
|
||||
export
|
||||
isPrintable : Char -> Bool
|
||||
isPrintable ch = case genCat ch of Other _ => False; _ => True
|
||||
|
||||
export
|
||||
isIdStart : Char -> Bool
|
||||
isIdStart ch =
|
||||
case genCat ch of
|
||||
Letter _ => True
|
||||
Punctuation Connector => True -- _, tie bars, etc
|
||||
_ => False
|
||||
Letter _ => True
|
||||
Number _ => not ('0' <= ch && ch <= '9')
|
||||
_ => False
|
||||
|
||||
export
|
||||
isIdCont : Char -> Bool
|
||||
|
@ -117,14 +113,23 @@ isIdCont ch =
|
|||
Number _ => True
|
||||
_ => False
|
||||
|
||||
export
|
||||
isIdConnector : Char -> Bool
|
||||
isIdConnector ch =
|
||||
case genCat ch of Punctuation Connector => True; _ => False
|
||||
|
||||
|
||||
export
|
||||
isSymChar : Char -> Bool
|
||||
isSymChar ch =
|
||||
case genCat ch of
|
||||
Symbol _ => True
|
||||
Punctuation Dash => True
|
||||
Punctuation Other => True
|
||||
_ => False
|
||||
|
||||
export
|
||||
isWhitespace : Char -> Bool
|
||||
isWhitespace ch = case genCat ch of Separator _ => True; _ => False
|
||||
isWhitespace ch =
|
||||
ch == '\t' || ch == '\r' || ch == '\n' ||
|
||||
case genCat ch of Separator _ => True; _ => False
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
module Quox.NatExtra
|
||||
|
||||
import public Data.Nat
|
||||
import Data.Nat.Division
|
||||
import Data.SnocList
|
||||
import Data.Vect
|
||||
|
||||
%default total
|
||||
|
||||
|
@ -30,3 +33,25 @@ public export
|
|||
toLte : {n : Nat} -> m `LTE'` n -> m `LTE` n
|
||||
toLte LTERefl = reflexive
|
||||
toLte (LTESuccR p) = lteSuccRight (toLte p)
|
||||
|
||||
|
||||
private
|
||||
0 baseNZ : n `GTE` 2 => NonZero n
|
||||
baseNZ @{LTESucc _} = SIsNonZero
|
||||
|
||||
parameters {base : Nat} {auto 0 _ : base `GTE` 2} (chars : Vect base Char)
|
||||
private
|
||||
showAtBase' : List Char -> Nat -> List Char
|
||||
showAtBase' acc 0 = acc
|
||||
showAtBase' acc k =
|
||||
let dig = natToFinLT (modNatNZ k base baseNZ) @{boundModNatNZ {}} in
|
||||
showAtBase' (index dig chars :: acc)
|
||||
(assert_smaller k $ divNatNZ k base baseNZ)
|
||||
|
||||
export
|
||||
showAtBase : Nat -> String
|
||||
showAtBase = pack . showAtBase' []
|
||||
|
||||
export
|
||||
showHex : Nat -> String
|
||||
showHex = showAtBase $ fromList $ unpack "0123456789ABCDEF"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue