@@ -40,6 +40,10 @@ export
4040Show (TokenData Token ) where
4141 show t = show (line t, col t, tok t)
4242
43+ --
44+ -- Comment Lexers
45+ --
46+
4347comment : Lexer
4448comment = is ' -' <+> is ' -' <+> many (isNot ' \n ' )
4549
@@ -61,21 +65,50 @@ blockComment = is '{' <+> is '-' <+> toEndComment 1
6165docComment : Lexer
6266docComment = is ' |' <+> is ' |' <+> is ' |' <+> many (isNot ' \n ' )
6367
68+ --
69+ -- Symbols
70+ --
71+
72+ export
73+ isOpChar : Char -> Bool
74+ isOpChar c = inLatin || inArrows || inMathematicalOperators
75+ where
76+ inRange : (Int, Int) -> Lazy Bool
77+ inRange (lowerBound, upperBound) = (c >= chr lowerBound && c <= chr upperBound)
78+ inLatin = c `elem` (unpack " :!#$%&*+./<=>?@\\ ^|-~" )
79+ inArrows = inRange (8592 , 8703 )
80+ inMathematicalOperators = inRange (8704 , 8959 )
81+
82+ validSymbol : Lexer
83+ validSymbol = some (pred isOpChar)
84+
85+ ||| Special symbols - things which can't be a prefix of another symbol, and
86+ ||| don't match 'validSymbol'
87+ export
88+ symbols : List String
89+ symbols
90+ = [" .(" , -- for things such as Foo.Bar.(+)
91+ " @{" ,
92+ " [|" , " |]" ,
93+ " (" , " )" , " {" , " }" , " [" , " ]" , " ," , " ;" , " _" ,
94+ " `(" , " `" ]
95+
96+ --
6497-- Identifier Lexer
6598--
6699-- There are two variants, a strict ident and a relaxed ident.
67100-- Prime definitions recieve a boolean determining if it is relaxed.
68101
69102startIdent : Char -> Bool
70103startIdent ' _' = True
71- startIdent x = isAlpha x || x > chr 127
104+ startIdent c = isAlpha c || ((c > chr 127 ) && not (isOpChar c))
72105
73106%inline
74107validIdent' : Bool -> Char -> Bool
75108validIdent' _ ' _' = True
76109validIdent' r ' -' = r
77110validIdent' _ ' \' ' = True
78- validIdent' _ x = isAlphaNum x || x > chr 127
111+ validIdent' _ c = isAlphaNum c || ((c > chr 127 ) && not (isOpChar c))
79112
80113%inline
81114ident' : Bool -> Lexer
@@ -95,6 +128,10 @@ identRelaxed = ident' True
95128holeIdent : Lexer
96129holeIdent = is ' ?' <+> identStrict
97130
131+ --
132+ -- Literal Lexers
133+ --
134+
98135doubleLit : Lexer
99136doubleLit
100137 = digits <+> is ' .' <+> digits <+> opt
@@ -129,32 +166,13 @@ keywords = ["data", "module", "where", "let", "in", "do", "record",
129166special : List String
130167special = [" %lam" , " %pi" , " %imppi" , " %let" ]
131168
132- -- Special symbols - things which can't be a prefix of another symbol, and
133- -- don't match 'validSymbol'
134- export
135- symbols : List String
136- symbols
137- = [" .(" , -- for things such as Foo.Bar.(+)
138- " @{" ,
139- " [|" , " |]" ,
140- " (" , " )" , " {" , " }" , " [" , " ]" , " ," , " ;" , " _" ,
141- " `(" , " `" ]
142-
143-
144- export
145- isOpChar : Char -> Bool
146- isOpChar c = c `elem` (unpack " :!#$%&*+./<=>?@\\ ^|-~" )
147-
148- validSymbol : Lexer
149- validSymbol = some (pred isOpChar)
150-
151169-- Valid symbols which have a special meaning so can't be operators
152170export
153171reservedSymbols : List String
154172reservedSymbols
155173 = symbols ++
156- [" %" , " \\ " , " :" , " =" , " |" , " |||" , " <- " , " -> " , " => " , " ? " , " ! " ,
157- " & " , " ** " , " .. " ]
174+ [" %" , " \\ " , " :" , " =" , " |" , " |||" , " ? " , " ! " , " & " , " ** " ,
175+ " .. " , " <- " , " -> " , " => " , " ← " , " → " , " ⇒ " ]
158176
159177fromHexLit : String -> Integer
160178fromHexLit str
0 commit comments