Refactor identChar into the identLexer to have that definition in one place
Unified · Split
| @@ -56,11 +56,6 @@ showSep sep [] = "" · 55 unmodified lines | |||
| 56 | showSep sep [x] = x | 56 | showSep sep [x] = x |
| 57 | showSep sep (x :: xs) = x ++ sep ++ showSep sep xs | 57 | showSep sep (x :: xs) = x ++ sep ++ showSep sep xs |
| 58 | 58 | ||
| 59 | ||| Check whether a given character is a valid identifier character | ||
| 60 | export | ||
| 61 | identChar : Char -> Bool | ||
| 62 | identChar x = isAlphaNum x || x == '_' || x == '\'' || x > chr 127 | ||
| 63 | |||
| 64 | export Show Name where | 59 | export Show Name where |
| 65 | show (NS ns n@(RF _)) = showSep "." (reverse ns) ++ ".(" ++ show n ++ ")" | 60 | show (NS ns n@(RF _)) = showSep "." (reverse ns) ++ ".(" ++ show n ++ ")" |
| 66 | show (NS ns n) = showSep "." (reverse ns) ++ "." ++ show n | 61 | show (NS ns n) = showSep "." (reverse ns) ++ "." ++ show n |
| @@ -6,6 +6,7 @@ import Core.Metadata · 5 unmodified lines | |||
| 6 | import Core.TT | 6 | import Core.TT |
| 7 | import Core.Value | 7 | import Core.Value |
| 8 | 8 | ||
| 9 | import Parser.Lexer | ||
| 9 | import Parser.Unlit | 10 | import Parser.Unlit |
| 10 | 11 | ||
| 11 | import TTImp.Interactive.CaseSplit | 12 | import TTImp.Interactive.CaseSplit |
| @@ -154,10 +155,9 @@ updateCase splits line col · 142 unmodified lines | |||
| 154 | 155 | ||
| 155 | fnName : Bool -> Name -> String | 156 | fnName : Bool -> Name -> String |
| 156 | fnName lhs (UN n) | 157 | fnName lhs (UN n) |
| 157 | = if any (not . identChar) (unpack n) | 158 | = if isIdentNormal n then n |
| 158 | then if lhs then "(" ++ n ++ ")" | 159 | else if lhs then "(" ++ n ++ ")" |
| 159 | else "op" | 160 | else "op" |
| 160 | else n | ||
| 161 | fnName lhs (NS _ n) = fnName lhs n | 161 | fnName lhs (NS _ n) = fnName lhs n |
| 162 | fnName lhs (DN s _) = s | 162 | fnName lhs (DN s _) = s |
| 163 | fnName lhs n = show n | 163 | fnName lhs n = show n |
| @@ -115,24 +115,33 @@ docComment = is '|' <+> is '|' <+> is '|' <+> many (isNot '\n') · 114 unmodified lines | |||
| 115 | 115 | ||
| 116 | data Flavour = Capitalised | AllowDashes | Normal | 116 | data Flavour = Capitalised | AllowDashes | Normal |
| 117 | 117 | ||
| 118 | startIdent : Flavour -> Char -> Bool | 118 | isIdentStart : Flavour -> Char -> Bool |
| 119 | startIdent Capitalised x = isUpper x | 119 | isIdentStart _ '_' = True |
| 120 | startIdent _ '_' = True | 120 | isIdentStart Capitalised x = isUpper x || x > chr 160 |
| 121 | startIdent _ x = isAlpha x || x > chr 127 | 121 | isIdentStart _ x = isAlpha x || x > chr 160 |
| 122 | |||
| 123 | isIdentTrailing : Flavour -> Char -> Bool | ||
| 124 | isIdentTrailing AllowDashes '-' = True | ||
| 125 | isIdentTrailing _ '\'' = True | ||
| 126 | isIdentTrailing _ '_' = True | ||
| 127 | isIdentTrailing _ x = isAlphaNum x || x > chr 160 | ||
| 122 | 128 | ||
| 123 | %inline | 129 | %inline |
| 124 | validIdent' : Flavour -> Char -> Bool | 130 | isIdent : Flavour -> String -> Bool |
| 125 | validIdent' _ '_' = True | 131 | isIdent flavour string = |
| 126 | validIdent' AllowDashes '-' = True | 132 | case unpack string of |
| 127 | validIdent' _ '-' = False | 133 | [] => False |
| 128 | validIdent' _ '\'' = True | 134 | (x::xs) => isIdentStart flavour x && all (isIdentTrailing flavour) xs |
| 129 | validIdent' _ x = isAlphaNum x || x > chr 127 | ||
| 130 | 135 | ||
| 131 | %inline | 136 | %inline |
| 132 | ident : Flavour -> Lexer | 137 | ident : Flavour -> Lexer |
| 133 | ident flavour = | 138 | ident flavour = |
| 134 | (pred $ startIdent flavour) <+> | 139 | (pred $ isIdentStart flavour) <+> |
| 135 | (many . pred $ validIdent' flavour) | 140 | (many . pred $ isIdentTrailing flavour) |
| 141 | |||
| 142 | export | ||
| 143 | isIdentNormal : String -> Bool | ||
| 144 | isIdentNormal = isIdent Normal | ||
| 136 | 145 | ||
| 137 | export | 146 | export |
| 138 | identNormal : Lexer | 147 | identNormal : Lexer |
| @@ -10,6 +10,8 @@ import Core.TT · 9 unmodified lines | |||
| 10 | import Core.Unify | 10 | import Core.Unify |
| 11 | import Core.Value | 11 | import Core.Value |
| 12 | 12 | ||
| 13 | import Parser.Lexer | ||
| 14 | |||
| 13 | import TTImp.Elab | 15 | import TTImp.Elab |
| 14 | import TTImp.Elab.Check | 16 | import TTImp.Elab.Check |
| 15 | import TTImp.Interactive.CaseSplit | 17 | import TTImp.Interactive.CaseSplit |
| @@ -24,10 +26,9 @@ import TTImp.Utils · 8 unmodified lines | |||
| 24 | 26 | ||
| 25 | fnName : Bool -> Name -> String | 27 | fnName : Bool -> Name -> String |
| 26 | fnName lhs (UN n) | 28 | fnName lhs (UN n) |
| 27 | = if any (not . identChar) (unpack n) | 29 | = if isIdentNormal n then n |
| 28 | then if lhs then "(" ++ n ++ ")" | 30 | else if lhs then "(" ++ n ++ ")" |
| 29 | else "op" | 31 | else "op" |
| 30 | else n | ||
| 31 | fnName lhs (NS _ n) = fnName lhs n | 32 | fnName lhs (NS _ n) = fnName lhs n |
| 32 | fnName lhs (DN s _) = s | 33 | fnName lhs (DN s _) = s |
| 33 | fnName lhs n = show n | 34 | fnName lhs n = show n |