Rain: added parsing support for function declarations
This commit is contained in:
parent
a14c33bc27
commit
989bb1c757
|
@ -38,7 +38,8 @@ $hexDigit = [0-9 a-f A-F]
|
|||
| ">=" | "<="
|
||||
| "<" | ">"
|
||||
| ".."
|
||||
| "process" | "pareach" | "seqeach" | "par" | "seq"
|
||||
| "process" | "function"
|
||||
| "pareach" | "seqeach" | "par" | "seq"
|
||||
| "run"
|
||||
| "if" | "while" | "else"
|
||||
| "sint8" | "sint16" | "sint32" | "sint64"
|
||||
|
|
|
@ -82,6 +82,7 @@ sIf = reserved "if"
|
|||
sElse = reserved "else"
|
||||
sWhile = reserved "while"
|
||||
sProcess = reserved "process"
|
||||
sFunction = reserved "function"
|
||||
sRun = reserved "run"
|
||||
--}}}
|
||||
|
||||
|
@ -345,8 +346,14 @@ processDecl = do {m <- sProcess ; procName <- name ; params <- tupleDef ; body <
|
|||
(A.Specification m procName (A.Proc m A.PlainSpec (formaliseTuple params) body))
|
||||
terminator}
|
||||
|
||||
functionDecl :: RainParser A.Structured
|
||||
functionDecl = do {m <- sFunction ; retType <- dataType ; sColon ; funcName <- name ; params <- tupleDef ; body <- block ;
|
||||
return $ A.Spec m
|
||||
(A.Specification m funcName (A.Function m A.PlainSpec [retType] (formaliseTuple params) (A.OnlyP (findMeta body) body)))
|
||||
terminator}
|
||||
|
||||
topLevelDecl :: RainParser A.Structured
|
||||
topLevelDecl = do decls <- many processDecl
|
||||
topLevelDecl = do decls <- many (processDecl <|> functionDecl <?> "process or function declaration")
|
||||
eof
|
||||
return $ A.Several emptyMeta decls
|
||||
|
||||
|
|
|
@ -413,6 +413,25 @@ testTopLevelDecl =
|
|||
, fail ("process foo (int: x)", RP.topLevelDecl)
|
||||
, fail ("process foo (int x) {}", RP.topLevelDecl)
|
||||
|
||||
|
||||
,pass ("function uint8: cons() {}", RP.topLevelDecl,
|
||||
assertPatternMatch "testTopLevelDecl 100" $ tag2 A.Several DontCare [tag3 A.Spec DontCare
|
||||
(tag3 A.Specification DontCare (simpleNamePattern "cons") $
|
||||
tag5 A.Function DontCare A.PlainSpec [A.Byte] ([] :: [A.Formal]) $
|
||||
(tag2 A.OnlyP DontCare $ tag2 A.Seq DontCare $ tag2 A.Several DontCare ([] :: [A.Structured]))
|
||||
) (tag2 A.OnlyP DontCare $ tag1 A.Main DontCare)
|
||||
]
|
||||
)
|
||||
|
||||
,pass ("function uint8: f(uint8: x) {}", RP.topLevelDecl,
|
||||
assertPatternMatch "testTopLevelDecl 101" $ tag2 A.Several DontCare [tag3 A.Spec DontCare
|
||||
(tag3 A.Specification DontCare (simpleNamePattern "f") $
|
||||
tag5 A.Function DontCare A.PlainSpec [A.Byte] [tag3 A.Formal A.ValAbbrev A.Byte (simpleNamePattern "x")] $
|
||||
(tag2 A.OnlyP DontCare $ tag2 A.Seq DontCare $ tag2 A.Several DontCare ([] :: [A.Structured]))
|
||||
) (tag2 A.OnlyP DontCare $ tag1 A.Main DontCare)
|
||||
]
|
||||
)
|
||||
|
||||
]
|
||||
|
||||
nonShared :: A.ChanAttributes
|
||||
|
|
Loading…
Reference in New Issue
Block a user