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,32 +1,35 @@
|
|||
module Ubc.Parse.Syntax.Statement
|
||||
( Statement(..)
|
||||
, parseStatement)
|
||||
, parse
|
||||
, blockExpression
|
||||
)
|
||||
where
|
||||
|
||||
import Ubc.Parse.Syntax.VariableType (VariableType)
|
||||
import Ubc.Parse.Syntax.Expression (Expression, expressionParser)
|
||||
import {-# SOURCE #-} Ubc.Parse.Syntax.Expression (expressionParser, Expression (Block))
|
||||
import Ubc.Parse.Syntax.TypeExpression (TypeExpression)
|
||||
import Text.Parsec (choice, ParsecT, try)
|
||||
import Text.Parsec (choice, ParsecT, try, many)
|
||||
import qualified Ubc.Parse.Syntax.Language as UbcLanguage
|
||||
import qualified Ubc.Parse.Syntax.VariableType as VariableType
|
||||
import qualified Ubc.Parse.Syntax.TypeExpression as TypeExpression
|
||||
import Ubc.Parse.Syntax.ParserState (ParserState)
|
||||
import Control.Monad ((<$!>))
|
||||
import Data.Functor ((<&>))
|
||||
|
||||
type VariableName = String
|
||||
type TypeName = String
|
||||
|
||||
data Statement = VariableDefinition VariableType VariableName Expression
|
||||
| TypeDefinition TypeName TypeExpression
|
||||
| ExpressionStatement Expression
|
||||
deriving (Show)
|
||||
|
||||
parseStatement :: Monad m => ParsecT String ParserState m Statement
|
||||
parseStatement = choice [ variableDefinition
|
||||
|
||||
parse :: Monad m => ParsecT String u m Statement
|
||||
parse = choice [ variableDefinition
|
||||
, typeDefinition
|
||||
, ExpressionStatement <$!> expressionParser
|
||||
]
|
||||
|
||||
typeDefinition :: Monad m => ParsecT String ParserState m Statement
|
||||
typeDefinition :: Monad m => ParsecT String u m Statement
|
||||
typeDefinition = do
|
||||
UbcLanguage.reserved "type"
|
||||
|
||||
|
@ -47,3 +50,5 @@ variableDefinition = do
|
|||
|
||||
VariableDefinition variableType variableName <$> expressionParser
|
||||
|
||||
blockExpression :: Monad m => ParsecT String u m Expression
|
||||
blockExpression = UbcLanguage.braces (many parse) <&> Block
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue