oh my god
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
{-# LANGUAGE ViewPatterns, LambdaCase #-}
|
||||
{-# LANGUAGE ViewPatterns #-}
|
||||
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Rlp.Lex
|
||||
@@ -39,20 +39,10 @@ $nl = [\n\r]
|
||||
$white_no_nl = $white # $nl
|
||||
|
||||
$namechar = [$alpha $digit \' \#]
|
||||
$reservedsym = [\(\)\,\;\[\]\`\{\}]
|
||||
$asciisym = [\!\#\$\%\&\*\+\.\/\<\=\>\?\@\\\^\|\-\~\:]
|
||||
$namesym = $asciisym # \;
|
||||
|
||||
@reservedop =
|
||||
"=" | \\ | "->" | "::" | "|"
|
||||
@varname = $lower $namechar*
|
||||
|
||||
@varname = $lower $namechar*
|
||||
@conname = $upper $namechar*
|
||||
@varsym = $namesym+
|
||||
@consym = \: $namesym*
|
||||
|
||||
|
||||
@decimal = $digit+
|
||||
@digits = $digit+
|
||||
|
||||
rlp :-
|
||||
|
||||
@@ -65,8 +55,8 @@ rlp :-
|
||||
{
|
||||
\n { beginPush bol }
|
||||
@varname { tokenWith TokenVarName }
|
||||
@decimal { tokenWith (TokenLitInt . readInt) }
|
||||
@reservedop { tokenWith readReservedOp }
|
||||
@digits { tokenWith (TokenLitInt . readInt) }
|
||||
"=" { constToken TokenEquals }
|
||||
}
|
||||
|
||||
-- control characters
|
||||
@@ -96,14 +86,6 @@ rlp :-
|
||||
|
||||
{
|
||||
|
||||
readReservedOp :: Text -> RlpToken
|
||||
readReservedOp = \case
|
||||
"=" -> TokenEquals
|
||||
"\\" -> TokenLambda
|
||||
"->" -> TokenArrow
|
||||
"::" -> TokenHasType
|
||||
s -> error (show s)
|
||||
|
||||
-- | @andBegin@, with the subtle difference that the start code is set
|
||||
-- /after/ the action
|
||||
thenBegin :: LexerAction a -> Int -> LexerAction a
|
||||
@@ -145,12 +127,6 @@ alexGetByte inp = case inp ^. aiBytes of
|
||||
getInput :: P AlexInput
|
||||
getInput = use psInput
|
||||
|
||||
takeInput :: Int -> AlexInput -> Text
|
||||
takeInput n inp = T.cons c cs
|
||||
where
|
||||
c = inp ^. aiPrevChar
|
||||
cs = T.take (max 0 (n-1)) $ inp ^. aiSource
|
||||
|
||||
getLexState :: P Int
|
||||
getLexState = use (psLexState . singular _head)
|
||||
|
||||
@@ -172,8 +148,8 @@ constToken t inp l = do
|
||||
tokenWith :: (Text -> RlpToken) -> LexerAction (Located RlpToken)
|
||||
tokenWith tf inp l = do
|
||||
pos <- getPos
|
||||
let t = takeInput l inp
|
||||
pure (Located (pos,l) (tf t))
|
||||
let t = tf (T.take l $ inp ^. aiSource)
|
||||
pure (Located (pos,l) t)
|
||||
|
||||
getPos :: P Position
|
||||
getPos = use (psInput . aiPos)
|
||||
@@ -200,10 +176,10 @@ initParseState s = ParseState
|
||||
}
|
||||
|
||||
initAlexInput :: Text -> AlexInput
|
||||
initAlexInput t = AlexInput
|
||||
{ _aiPrevChar = c
|
||||
initAlexInput s = AlexInput
|
||||
{ _aiPrevChar = '\0'
|
||||
, _aiSource = s
|
||||
, _aiBytes = b
|
||||
, _aiBytes = []
|
||||
, _aiPos = (1,1)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user