Added support for enumerations
This commit is contained in:
parent
01fafec1c0
commit
2cd9b04b85
8 changed files with 57 additions and 35 deletions
|
@ -8,38 +8,45 @@ import Control.Monad ((<$!>))
|
|||
|
||||
import Text.Parsec (choice, ParsecT, many)
|
||||
|
||||
import Ubc.Parse.Syntax.Data.Struct ( Struct )
|
||||
import Ubc.Parse.Syntax.Struct ( Struct )
|
||||
import Ubc.Parse.Syntax.Function (Function)
|
||||
import Ubc.Parse.Syntax.Statement (Statement)
|
||||
import Ubc.Parse.Syntax.Enumeration (Enumeration)
|
||||
|
||||
import qualified Ubc.Parse.Syntax.Struct as Struct
|
||||
import qualified Ubc.Parse.Syntax.Function as Function
|
||||
import qualified Ubc.Parse.Syntax.Statement as Statement
|
||||
import qualified Ubc.Parse.Syntax.Enumeration as Enumeration
|
||||
|
||||
data File = File
|
||||
{ name :: String
|
||||
, structs :: [Struct]
|
||||
, functions :: [Function]
|
||||
, statements :: [Statement]
|
||||
, enumerations :: [Enumeration]
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
data FileMember = FileFunction Function
|
||||
| FileStruct Struct
|
||||
| FileEnumeration Enumeration
|
||||
| FileStatement Statement
|
||||
|
||||
accumulateFile :: File -> FileMember -> File
|
||||
accumulateFile (File name_ struct_ functions_ statements_) (FileFunction f) = File name_ struct_ (f:functions_) statements_
|
||||
accumulateFile (File name_ struct_ functions_ statements_) (FileStatement s) = File name_ struct_ functions_ (s:statements_)
|
||||
accumulateFile (File name_ struct_ functions_ statements_) (FileStruct s) = File name_ (s:struct_) functions_ statements_
|
||||
accumulateFile (File name_ sss fs sts es) (FileStruct s) = File name_ (s:sss) fs sts es
|
||||
accumulateFile (File name_ sss fs sts es) (FileFunction f) = File name_ sss (f:fs) sts es
|
||||
accumulateFile (File name_ sss fs sts es) (FileStatement s) = File name_ sss fs (s:sts) es
|
||||
accumulateFile (File name_ sss fs sts es) (FileEnumeration e) = File name_ sss fs sts (e:es)
|
||||
|
||||
parse :: Monad m => ParsecT String u m File
|
||||
parse = foldl accumulateFile (File "" [] [] []) <$!> many fileMember
|
||||
parse = foldr (flip accumulateFile) (File "" [] [] [] []) <$!> many fileMember
|
||||
|
||||
fileMember :: Monad m => ParsecT String u m FileMember
|
||||
fileMember = choice
|
||||
[ FileStruct <$!> Struct.parse
|
||||
, FileFunction <$!> Function.parse
|
||||
, FileStatement <$!> Statement.parse
|
||||
, FileEnumeration <$!> Enumeration.parse
|
||||
]
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue