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
56showSep sep [x] = x56showSep sep [x] = x
57showSep sep (x :: xs) = x ++ sep ++ showSep sep xs57showSep sep (x :: xs) = x ++ sep ++ showSep sep xs
58 58
59||| Check whether a given character is a valid identifier character
60export
61identChar : Char -> Bool
62identChar x = isAlphaNum x || x == '_' || x == '\'' || x > chr 127
63
64export Show Name where59export 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 n61 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
6import Core.TT6import Core.TT
7import Core.Value7import Core.Value
8 8
9import Parser.Lexer
9import Parser.Unlit10import Parser.Unlit
10 11
11import TTImp.Interactive.CaseSplit12import TTImp.Interactive.CaseSplit
@@ -154,10 +155,9 @@ updateCase splits line col · 142 unmodified lines
154 155
155fnName : Bool -> Name -> String156fnName : Bool -> Name -> String
156fnName lhs (UN n)157fnName 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
161fnName lhs (NS _ n) = fnName lhs n161fnName lhs (NS _ n) = fnName lhs n
162fnName lhs (DN s _) = s162fnName lhs (DN s _) = s
163fnName lhs n = show n163fnName lhs n = show n
src/Parser/Lexer.idr+21−12
@@ -115,24 +115,33 @@ docComment = is '|' <+> is '|' <+> is '|' <+> many (isNot '\n') · 114 unmodified lines
115 115
116data Flavour = Capitalised | AllowDashes | Normal116data Flavour = Capitalised | AllowDashes | Normal
117 117
118startIdent : Flavour -> Char -> Bool118isIdentStart : Flavour -> Char -> Bool
119startIdent Capitalised x = isUpper x119isIdentStart _ '_' = True
120startIdent _ '_' = True120isIdentStart Capitalised x = isUpper x || x > chr 160
121startIdent _ x = isAlpha x || x > chr 127121isIdentStart _ x = isAlpha x || x > chr 160
122
123isIdentTrailing : Flavour -> Char -> Bool
124isIdentTrailing AllowDashes '-' = True
125isIdentTrailing _ '\'' = True
126isIdentTrailing _ '_' = True
127isIdentTrailing _ x = isAlphaNum x || x > chr 160
122 128
123%inline129%inline
124validIdent' : Flavour -> Char -> Bool130isIdent : Flavour -> String -> Bool
125validIdent' _ '_' = True131isIdent flavour string =
126validIdent' AllowDashes '-' = True132 case unpack string of
127validIdent' _ '-' = False133 [] => False
128validIdent' _ '\'' = True134 (x::xs) => isIdentStart flavour x && all (isIdentTrailing flavour) xs
129validIdent' _ x = isAlphaNum x || x > chr 127
130 135
131%inline136%inline
132ident : Flavour -> Lexer137ident : Flavour -> Lexer
133ident flavour =138ident flavour =
134 (pred $ startIdent flavour) <+>139 (pred $ isIdentStart flavour) <+>
135 (many . pred $ validIdent' flavour)140 (many . pred $ isIdentTrailing flavour)
141
142export
143isIdentNormal : String -> Bool
144isIdentNormal = isIdent Normal
136 145
137export146export
138identNormal : Lexer147identNormal : Lexer
src/TTImp/Interactive/GenerateDef.idr+5−4
@@ -10,6 +10,8 @@ import Core.TT · 9 unmodified lines
10import Core.Unify10import Core.Unify
11import Core.Value11import Core.Value
12 12
13import Parser.Lexer
14
13import TTImp.Elab15import TTImp.Elab
14import TTImp.Elab.Check16import TTImp.Elab.Check
15import TTImp.Interactive.CaseSplit17import TTImp.Interactive.CaseSplit
@@ -24,10 +26,9 @@ import TTImp.Utils · 8 unmodified lines
24 26
25fnName : Bool -> Name -> String27fnName : Bool -> Name -> String
26fnName lhs (UN n)28fnName 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
31fnName lhs (NS _ n) = fnName lhs n32fnName lhs (NS _ n) = fnName lhs n
32fnName lhs (DN s _) = s33fnName lhs (DN s _) = s
33fnName lhs n = show n34fnName 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