Add the ability to lex primitives and lambdas.

This commit is contained in:
2011-02-03 21:31:14 -05:00
parent fafc51da1c
commit 566560edb4
3 changed files with 7 additions and 3 deletions

View File

@@ -40,7 +40,9 @@ $escape_char = [abfnrtv'\"\\]
-- Identifier -- Identifier
$typestart $identrest* { emitS TokTypeIdent } $typestart $identrest* { emitS TokTypeIdent }
"prim%" $typestart $identrest* { emitS TokTypeIdent }
$valstart $identrest* { emitS TokValIdent } $valstart $identrest* { emitS TokValIdent }
"prim%" $valstart $identrest* { emitS TokValIdent }
$opident+ { emitS TokOpIdent } $opident+ { emitS TokOpIdent }
":"+ { emitS TokOpIdent } ":"+ { emitS TokOpIdent }
@@ -60,6 +62,7 @@ $escape_char = [abfnrtv'\"\\]
";" { emitT Semi } ";" { emitT Semi }
"," { emitT Comma } "," { emitT Comma }
"`" { emitT BTick } "`" { emitT BTick }
[\\] { emitT LLambda }
{ {

View File

@@ -38,7 +38,7 @@ import qualified Codec.Binary.UTF8.Generic as UTF8
'->' { Lexeme $$ (TokOpIdent "->") } '->' { Lexeme $$ (TokOpIdent "->") }
'@' { Lexeme $$ (TokOpIdent "@") } '@' { Lexeme $$ (TokOpIdent "@") }
'::' { Lexeme $$ (TokOpIdent "::") } '::' { Lexeme $$ (TokOpIdent "::") }
'\\' { Lexeme $$ (TokOpIdent "\\") } '\\' { Lexeme $$ LLambda }
'(' { Lexeme $$ LParen } '(' { Lexeme $$ LParen }
')' { Lexeme $$ RParen } ')' { Lexeme $$ RParen }
'[' { Lexeme $$ LSquare } '[' { Lexeme $$ LSquare }

View File

@@ -6,6 +6,7 @@ module Syntax.ParserCore where
import Control.Applicative(Applicative) import Control.Applicative(Applicative)
import qualified Data.ByteString as S import qualified Data.ByteString as S
import MonadLib import MonadLib
import System.IO
-- -------------------------------------------------------------------------- -- --------------------------------------------------------------------------
-- Positions -- Positions
@@ -37,7 +38,7 @@ pprtPosition p = posFile p ++ ":" ++ show (posLine p) ++ ":" ++ show (posCol p)
data Token = LParen | RParen data Token = LParen | RParen
| LSquare | RSquare | LSquare | RSquare
| LBrace | RBrace | LBrace | RBrace
| Bar | Semi | Comma | BTick | Bar | Semi | Comma | BTick | LLambda
| TokTypeIdent String | TokTypeIdent String
| TokValIdent String | TokValIdent String
| TokOpIdent String | TokOpIdent String
@@ -74,7 +75,7 @@ data Error = Error ErrorType String Position
deriving (Show) deriving (Show)
printError :: Error -> IO () printError :: Error -> IO ()
printError (Error etype str pos) = putStrLn errstr printError (Error etype str pos) = hPutStrLn stderr errstr
where where
errstr = pprtPosition pos ++ ":" ++ etypeStr ++ ": " ++ str errstr = pprtPosition pos ++ ":" ++ etypeStr ++ ": " ++ str
etypeStr = case etype of etypeStr = case etype of