diff options
Diffstat (limited to 'src/Parser/Expr.hs')
| -rw-r--r-- | src/Parser/Expr.hs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Parser/Expr.hs b/src/Parser/Expr.hs index b9b5f01..585f727 100644 --- a/src/Parser/Expr.hs +++ b/src/Parser/Expr.hs @@ -5,11 +5,13 @@ module Parser.Expr ( varName, newVarName, addVarName, + constrName, someExpr, typedExpr, literal, variable, + constructor, stringExpansion, @@ -83,6 +85,13 @@ addVarName off (TypedVarName name) = do Nothing -> return () modify $ \s -> s { testVars = ( name, ( LocalVarName name, ExprTypePrim @a Proxy )) : testVars s } +constrName :: TestParser VarName +constrName = label "contructor name" $ do + lexeme $ try $ do + lead <- upperChar + rest <- takeWhileP Nothing (\x -> isAlphaNum x || x == '_') + return $ VarName $ TL.toStrict $ TL.fromChunks $ T.singleton lead : TL.toChunks rest + someExpansion :: TestParser SomeExpr someExpansion = do void $ char '$' @@ -370,10 +379,17 @@ variable = label "variable" $ do e <- lookupVarExpr off sline name recordSelector e <|> return e +constructor :: TestParser SomeExpr +constructor = label "constructor" $ do + off <- stateOffset <$> getParserState + sline <- getSourceLine + name <- constrName + lookupVarExpr off sline name + functionCall :: TestParser SomeExpr functionCall = do sline <- getSourceLine - variable >>= \case + (variable <|> constructor) >>= \case SomeExpr e'@(FunVariable argTypes _ _) -> do let check = checkFunctionArguments argTypes args <- functionArguments check someExpr literal (\poff -> lookupVarExpr poff sline . VarName) |