@@ -110,21 +110,54 @@ blockComment = is '{' <+> is '-' <+> toEndComment 1
110110docComment : Lexer
111111docComment = is ' |' <+> is ' |' <+> is ' |' <+> many (isNot ' \n ' )
112112
113+ --
114+ -- Symbols
115+ --
116+
117+ export
118+ isOpChar : Char -> Bool
119+ isOpChar c = inLatin || inArrows || inMathematicalOperators
120+ where
121+ inRange : (Int, Int) -> Lazy Bool
122+ inRange (lowerBound, upperBound) = (c >= chr lowerBound && c <= chr upperBound)
123+ inLatin = c `elem` (unpack " :!#$%&*+./<=>?@\\ ^|-~" )
124+ inArrows = inRange (8592 , 8703 )
125+ inMathematicalOperators = inRange (8704 , 8959 )
126+
127+ nonOpCharUnicode : Char -> Bool
128+ nonOpCharUnicode c = (c > chr 160 ) && not (isOpChar c)
129+
130+
131+ validSymbol : Lexer
132+ validSymbol = some (pred isOpChar)
133+
134+ ||| Special symbols - things which can't be a prefix of another symbol, and
135+ ||| don't match 'validSymbol'
136+ export
137+ symbols : List String
138+ symbols
139+ = [" .(" , -- for things such as Foo.Bar.(+)
140+ " @{" ,
141+ " [|" , " |]" ,
142+ " (" , " )" , " {" , " }" , " [" , " ]" , " ," , " ;" , " _" ,
143+ " `(" , " `" ]
144+
145+ --
113146-- Identifier Lexer
114147-- There are multiple variants.
115148
116149data Flavour = Capitalised | AllowDashes | Normal
117150
118151isIdentStart : Flavour -> Char -> Bool
119152isIdentStart _ ' _' = True
120- isIdentStart Capitalised x = isUpper x || x > chr 160
121- isIdentStart _ x = isAlpha x || x > chr 160
153+ isIdentStart Capitalised c = isUpper c || nonOpCharUnicode c
154+ isIdentStart _ c = isAlpha c || nonOpCharUnicode c
122155
123156isIdentTrailing : Flavour -> Char -> Bool
124157isIdentTrailing AllowDashes ' -' = True
125158isIdentTrailing _ ' \' ' = True
126159isIdentTrailing _ ' _' = True
127- isIdentTrailing _ x = isAlphaNum x || x > chr 160
160+ isIdentTrailing _ c = isAlphaNum c || nonOpCharUnicode c
128161
129162%inline
130163isIdent : Flavour -> String -> Bool
@@ -163,6 +196,10 @@ recField = is '.' <+> ident Normal
163196pragma : Lexer
164197pragma = is ' %' <+> ident Normal
165198
199+ --
200+ -- Literal Lexers
201+ --
202+
166203doubleLit : Lexer
167204doubleLit
168205 = digits <+> is ' .' <+> digits <+> opt
@@ -197,32 +234,13 @@ keywords = ["data", "module", "where", "let", "in", "do", "record",
197234special : List String
198235special = [" %lam" , " %pi" , " %imppi" , " %let" ]
199236
200- -- Special symbols - things which can't be a prefix of another symbol, and
201- -- don't match 'validSymbol'
202- export
203- symbols : List String
204- symbols
205- = [" .(" , -- for things such as Foo.Bar.(+)
206- " @{" ,
207- " [|" , " |]" ,
208- " (" , " )" , " {" , " }" , " [" , " ]" , " ," , " ;" , " _" ,
209- " `(" , " `" ]
210-
211-
212- export
213- isOpChar : Char -> Bool
214- isOpChar c = c `elem` (unpack " :!#$%&*+./<=>?@\\ ^|-~" )
215-
216- validSymbol : Lexer
217- validSymbol = some (pred isOpChar)
218-
219237-- Valid symbols which have a special meaning so can't be operators
220238export
221239reservedSymbols : List String
222240reservedSymbols
223241 = symbols ++
224- [" %" , " \\ " , " :" , " =" , " |" , " |||" , " <- " , " -> " , " => " , " ? " , " ! " ,
225- " & " , " ** " , " .. " ]
242+ [" %" , " \\ " , " :" , " =" , " |" , " |||" , " ? " , " ! " , " & " , " ** " ,
243+ " .. " , " <- " , " -> " , " => " , " ← " , " → " , " ⇒ " ]
226244
227245fromHexLit : String -> Integer
228246fromHexLit str
0 commit comments