History

Merge pull request #329 from LibreCybernetics/refactor-identifier-lexer

Refactor identChar into the identLexer to have that definition in one place

Edwin Brady committed 6 years ago

Commit afa93522 parents 7e06798 20ed4a34 files · +30 −25Browse files

Unified · Split

4 files
  1. src/Core/Name.idr +0 −5
  2. src/Idris/IDEMode/CaseSplit.idr +4 −4
  3. src/Parser/Lexer.idr +21 −12
  4. src/TTImp/Interactive/GenerateDef.idr +5 −4
src/Core/Name.idr+0−5
@@ -56,11 +56,6 @@ showSep sep [] = "" · 55 unmodified lines
5656 showSep sep [x] = x
5757 showSep sep (x :: xs) = x ++ sep ++ showSep sep xs
5858
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−
6459 export Show Name where
6560 show (NS ns n@(RF _)) = showSep "." (reverse ns) ++ ".(" ++ show n ++ ")"
6661 show (NS ns n) = showSep "." (reverse ns) ++ "." ++ show n
src/Idris/IDEMode/CaseSplit.idr+4−4
@@ -6,6 +6,7 @@ import Core.Metadata · 5 unmodified lines
66 import Core.TT
77 import Core.Value
88
9+import Parser.Lexer
910 import Parser.Unlit
1011
1112 import TTImp.Interactive.CaseSplit
@@ -154,10 +155,9 @@ updateCase splits line col · 142 unmodified lines
154155
155156 fnName : Bool -> Name -> String
156157 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"
161161 fnName lhs (NS _ n) = fnName lhs n
162162 fnName lhs (DN s _) = s
163163 fnName lhs n = show n
src/Parser/Lexer.idr+21−12
@@ -115,24 +115,33 @@ docComment = is '|' <+> is '|' <+> is '|' <+> many (isNot '\n') · 114 unmodified lines
115115
116116 data Flavour = Capitalised | AllowDashes | Normal
117117
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
122128
123129 %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
130135
131136 %inline
132137 ident : Flavour -> Lexer
133138 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
136145
137146 export
138147 identNormal : Lexer
src/TTImp/Interactive/GenerateDef.idr+5−4
@@ -10,6 +10,8 @@ import Core.TT · 9 unmodified lines
1010 import Core.Unify
1111 import Core.Value
1212
13+import Parser.Lexer
14+
1315 import TTImp.Elab
1416 import TTImp.Elab.Check
1517 import TTImp.Interactive.CaseSplit
@@ -24,10 +26,9 @@ import TTImp.Utils · 8 unmodified lines
2426
2527 fnName : Bool -> Name -> String
2628 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"
3132 fnName lhs (NS _ n) = fnName lhs n
3233 fnName lhs (DN s _) = s
3334 fnName lhs n = show n

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t