Simple parse-dump main function, also fixed about everything
This commit is contained in:
parent
f35ca83d7a
commit
01fafec1c0
18 changed files with 179 additions and 214 deletions
|
@ -1,5 +1,45 @@
|
|||
module Ubc.Parse.Syntax.File
|
||||
(
|
||||
( File(..)
|
||||
, parse
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Monad ((<$!>))
|
||||
|
||||
import Text.Parsec (choice, ParsecT, many)
|
||||
|
||||
import Ubc.Parse.Syntax.Data.Struct ( Struct )
|
||||
import Ubc.Parse.Syntax.Function (Function)
|
||||
import Ubc.Parse.Syntax.Statement (Statement)
|
||||
import qualified Ubc.Parse.Syntax.Struct as Struct
|
||||
import qualified Ubc.Parse.Syntax.Function as Function
|
||||
import qualified Ubc.Parse.Syntax.Statement as Statement
|
||||
|
||||
data File = File
|
||||
{ name :: String
|
||||
, structs :: [Struct]
|
||||
, functions :: [Function]
|
||||
, statements :: [Statement]
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
data FileMember = FileFunction Function
|
||||
| FileStruct Struct
|
||||
| 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_
|
||||
|
||||
parse :: Monad m => ParsecT String u m File
|
||||
parse = foldl accumulateFile (File "" [] [] []) <$!> many fileMember
|
||||
|
||||
fileMember :: Monad m => ParsecT String u m FileMember
|
||||
fileMember = choice
|
||||
[ FileStruct <$!> Struct.parse
|
||||
, FileFunction <$!> Function.parse
|
||||
, FileStatement <$!> Statement.parse
|
||||
]
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue