Parsing updates for unicode
- Allow unicode characters in indents and operators - Show lexing errors
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
module Lib.Parser.Impl
|
||||
|
||||
import Lib.Token
|
||||
import Lib.Common
|
||||
import Data.String
|
||||
import Data.Nat
|
||||
|
||||
@@ -8,54 +9,6 @@ public export
|
||||
TokenList : Type
|
||||
TokenList = List BTok
|
||||
|
||||
public export
|
||||
data Fixity = InfixL | InfixR | Infix
|
||||
|
||||
export
|
||||
Show Fixity where
|
||||
show InfixL = "infixl"
|
||||
show InfixR = "infixr"
|
||||
show Infix = "infix"
|
||||
|
||||
-- I was going to use a record, but we're peeling this off of bounds at the moment.
|
||||
public export
|
||||
FC : Type
|
||||
FC = (Int,Int)
|
||||
|
||||
public export
|
||||
interface HasFC a where
|
||||
getFC : a -> FC
|
||||
|
||||
%name FC fc
|
||||
|
||||
export
|
||||
emptyFC : FC
|
||||
emptyFC = (0,0)
|
||||
|
||||
-- Error of a parse
|
||||
public export
|
||||
data Error = E FC String
|
||||
%name Error err
|
||||
|
||||
public export
|
||||
showError : String -> Error -> String
|
||||
showError src (E (line, col) msg) = "ERROR at \{show (line,col)}: \{msg}\n" ++ go 0 (lines src)
|
||||
where
|
||||
go : Int -> List String -> String
|
||||
go l [] = ""
|
||||
go l (x :: xs) =
|
||||
if l == line then
|
||||
" \{x}\n \{replicate (cast col) ' '}^\n"
|
||||
else if line - 3 < l then " " ++ x ++ "\n" ++ go (l + 1) xs
|
||||
else go (l + 1) xs
|
||||
|
||||
public export
|
||||
record OpDef where
|
||||
constructor MkOp
|
||||
name : String
|
||||
prec : Int
|
||||
fix : Fixity
|
||||
|
||||
-- Result of a parse
|
||||
public export
|
||||
data Result : Type -> Type where
|
||||
|
||||
Reference in New Issue
Block a user