summaryrefslogtreecommitdiff
path: root/src/Language/Fiddle/Parser.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language/Fiddle/Parser.hs')
-rw-r--r--src/Language/Fiddle/Parser.hs35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/Language/Fiddle/Parser.hs b/src/Language/Fiddle/Parser.hs
index f3ad744..b44a9a1 100644
--- a/src/Language/Fiddle/Parser.hs
+++ b/src/Language/Fiddle/Parser.hs
@@ -10,6 +10,7 @@ where
import Control.Monad (void)
import Data.Functor.Identity
import Data.Kind (Type)
+import Data.List.NonEmpty (NonEmpty (..))
import Data.Text (Text)
import qualified Data.Text
import Debug.Trace
@@ -107,19 +108,24 @@ fiddleUnit = do
<* many comment
stringToken :: P Text
-stringToken = token (\case
- (TokString str) -> Just str
- _ -> Nothing)
+stringToken =
+ token
+ ( \case
+ (TokString str) -> Just str
+ _ -> Nothing
+ )
importList :: PaS ImportList
importList = withMeta $ do
tok TokLParen
- ImportList <$> many (ident <* (tok TokComma <|> lookAhead (tok TokRParen)))
- <* tok TokRParen
+ ImportList
+ <$> many (ident <* (tok TokComma <|> lookAhead (tok TokRParen)))
+ <* tok TokRParen
importStatement :: PaS ImportStatement
-importStatement = withMeta $
- ImportStatement <$> stringToken <*> optionMaybe importList
+importStatement =
+ withMeta $
+ ImportStatement <$> stringToken <*> optionMaybe importList
fiddleDecl :: Pa FiddleDecl
fiddleDecl = do
@@ -129,8 +135,9 @@ fiddleDecl = do
KWOption -> OptionDecl <$> nextText <*> nextText
KWPackage ->
PackageDecl
- <$> ident
+ <$> name
<*> defer body packageBody
+ KWUsing -> UsingDecl <$> name
KWLocation -> LocationDecl <$> ident <*> (tok TokEq >> expression)
KWBits -> BitsDecl <$> ident <*> (tok TokColon >> bitType)
KWImport -> ImportDecl <$> importStatement
@@ -185,7 +192,7 @@ objType = do
baseObj :: P (A -> ObjType Stage1 F A)
baseObj =
- (ReferencedObjType <$> ident)
+ (ReferencedObjType <$> name)
<|> ( do
t <- bodyType
AnonymousObjType <$> defer body (objTypeBody t)
@@ -285,7 +292,7 @@ registerBitsTypeRef = do
withMeta $
(RegisterBitsJustBits <$> exprInParen)
<|> (RegisterBitsAnonymousType <$> anonymousBitsType)
- <|> (RegisterBitsReference <$> ident)
+ <|> (RegisterBitsReference <$> name)
anonymousBitsType :: Pa AnonymousBitsType
anonymousBitsType = withMeta $ do
@@ -390,6 +397,14 @@ ident =
(TokIdent id) -> Just (Identifier id)
_ -> Nothing
+name :: PaS Name
+name = withMeta $ do
+ i <- ident
+ is <- many $ do
+ tok TokDot
+ ident
+ return $ Name (i :| is)
+
-- Takes a some parsable thing p and automatically parses the comments before
-- and after and sets the positions and adds it to the annotation.
withMeta :: P (Commented SourceSpan -> b) -> P b