Add the ability to lex primitives and lambdas.
This commit is contained in:
@@ -40,7 +40,9 @@ $escape_char = [abfnrtv'\"\\]
|
||||
|
||||
-- Identifier
|
||||
$typestart $identrest* { emitS TokTypeIdent }
|
||||
"prim%" $typestart $identrest* { emitS TokTypeIdent }
|
||||
$valstart $identrest* { emitS TokValIdent }
|
||||
"prim%" $valstart $identrest* { emitS TokValIdent }
|
||||
$opident+ { emitS TokOpIdent }
|
||||
":"+ { emitS TokOpIdent }
|
||||
|
||||
@@ -60,6 +62,7 @@ $escape_char = [abfnrtv'\"\\]
|
||||
";" { emitT Semi }
|
||||
"," { emitT Comma }
|
||||
"`" { emitT BTick }
|
||||
[\\] { emitT LLambda }
|
||||
|
||||
{
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import qualified Codec.Binary.UTF8.Generic as UTF8
|
||||
'->' { Lexeme $$ (TokOpIdent "->") }
|
||||
'@' { Lexeme $$ (TokOpIdent "@") }
|
||||
'::' { Lexeme $$ (TokOpIdent "::") }
|
||||
'\\' { Lexeme $$ (TokOpIdent "\\") }
|
||||
'\\' { Lexeme $$ LLambda }
|
||||
'(' { Lexeme $$ LParen }
|
||||
')' { Lexeme $$ RParen }
|
||||
'[' { Lexeme $$ LSquare }
|
||||
|
||||
@@ -6,6 +6,7 @@ module Syntax.ParserCore where
|
||||
import Control.Applicative(Applicative)
|
||||
import qualified Data.ByteString as S
|
||||
import MonadLib
|
||||
import System.IO
|
||||
|
||||
-- --------------------------------------------------------------------------
|
||||
-- Positions
|
||||
@@ -37,7 +38,7 @@ pprtPosition p = posFile p ++ ":" ++ show (posLine p) ++ ":" ++ show (posCol p)
|
||||
data Token = LParen | RParen
|
||||
| LSquare | RSquare
|
||||
| LBrace | RBrace
|
||||
| Bar | Semi | Comma | BTick
|
||||
| Bar | Semi | Comma | BTick | LLambda
|
||||
| TokTypeIdent String
|
||||
| TokValIdent String
|
||||
| TokOpIdent String
|
||||
@@ -74,7 +75,7 @@ data Error = Error ErrorType String Position
|
||||
deriving (Show)
|
||||
|
||||
printError :: Error -> IO ()
|
||||
printError (Error etype str pos) = putStrLn errstr
|
||||
printError (Error etype str pos) = hPutStrLn stderr errstr
|
||||
where
|
||||
errstr = pprtPosition pos ++ ":" ++ etypeStr ++ ": " ++ str
|
||||
etypeStr = case etype of
|
||||
|
||||
Reference in New Issue
Block a user