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