Rework module system
Don't require/allow naming a module, instead require that the importer names it. Allow importing into the local scope with the name !Local. Simplify namespacing logic. Updates all tests to reflect these changes.
This commit is contained in:
@ -73,8 +73,6 @@ parseSingle input =
|
||||
|
||||
parseProgramM :: ParserM [TricuAST]
|
||||
parseProgramM = do
|
||||
skipMany topLevelNewline
|
||||
moduleNode <- optional parseModuleM
|
||||
skipMany topLevelNewline
|
||||
importNodes <- many (do
|
||||
node <- parseImportM
|
||||
@ -83,16 +81,7 @@ parseProgramM = do
|
||||
skipMany topLevelNewline
|
||||
exprs <- sepEndBy parseOneExpression (some topLevelNewline)
|
||||
skipMany topLevelNewline
|
||||
return (maybe [] (: []) moduleNode ++ importNodes ++ exprs)
|
||||
|
||||
|
||||
parseModuleM :: ParserM TricuAST
|
||||
parseModuleM = do
|
||||
LModule moduleName <- satisfyM isModule
|
||||
pure (SModule moduleName)
|
||||
where
|
||||
isModule (LModule _) = True
|
||||
isModule _ = False
|
||||
return (importNodes ++ exprs)
|
||||
|
||||
parseImportM :: ParserM TricuAST
|
||||
parseImportM = do
|
||||
@ -266,12 +255,19 @@ parseSingleItemM = do
|
||||
|
||||
parseVarM :: ParserM TricuAST
|
||||
parseVarM = do
|
||||
satisfyM (\case LIdentifier _ -> True; _ -> False) >>= \case
|
||||
token <- satisfyM (\case
|
||||
LNamespace _ -> True
|
||||
LIdentifier _ -> True
|
||||
_ -> False)
|
||||
case token of
|
||||
LNamespace ns -> do
|
||||
_ <- satisfyM (== LDot)
|
||||
LIdentifier name <- satisfyM (\case LIdentifier _ -> True; _ -> False)
|
||||
pure $ SVar (ns ++ "." ++ name)
|
||||
LIdentifier name
|
||||
| name == "t" || name == "!result" ->
|
||||
fail ("Reserved keyword: " ++ name ++ " cannot be assigned.")
|
||||
| otherwise ->
|
||||
pure (SVar name)
|
||||
| otherwise -> pure (SVar name)
|
||||
_ -> fail "Unexpected token while parsing variable"
|
||||
|
||||
parseIntLiteralM :: ParserM TricuAST
|
||||
|
Reference in New Issue
Block a user