Checkpoint
This commit is contained in:
@@ -39,6 +39,7 @@ executable bang
|
|||||||
Bang.Syntax.Lexer,
|
Bang.Syntax.Lexer,
|
||||||
Bang.Syntax.Location,
|
Bang.Syntax.Location,
|
||||||
Bang.Syntax.Name,
|
Bang.Syntax.Name,
|
||||||
|
Bang.Syntax.Parser,
|
||||||
Bang.Syntax.Token,
|
Bang.Syntax.Token,
|
||||||
Paths_bang
|
Paths_bang
|
||||||
|
|
||||||
|
|||||||
76
src/Bang/Syntax/Parser.y
Normal file
76
src/Bang/Syntax/Parser.y
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
{
|
||||||
|
{-# OPTION_GHC -w #-}
|
||||||
|
{-# LANGUAGE DeriveFunctor #-}
|
||||||
|
{-# LANGAUGE OverloadedStrings #-}
|
||||||
|
module Bang.Syntax.Parser(
|
||||||
|
parseModule
|
||||||
|
, parseExpression
|
||||||
|
, lexWithLayout
|
||||||
|
)
|
||||||
|
where
|
||||||
|
|
||||||
|
import Bang.Syntax.Lexer
|
||||||
|
import Bang.Syntax.Location
|
||||||
|
import Bang.Syntax.Token
|
||||||
|
import MonadLib
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
%tokentype { Located Token }
|
||||||
|
|
||||||
|
%token
|
||||||
|
'::' { Located $$ (OpIdent "::") }
|
||||||
|
|
||||||
|
%monad { Parser }
|
||||||
|
%error { parseError }
|
||||||
|
|
||||||
|
%name top_module
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
top_module :: { () }
|
||||||
|
: '::' { () }
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
newtype Parser a = Parser {
|
||||||
|
unParser :: StateT ParserState (ExceptionT Error Id) a
|
||||||
|
}
|
||||||
|
deriving (Functor, Applicative, Monad)
|
||||||
|
|
||||||
|
data ParserState = ParserState {
|
||||||
|
psPrecTable :: Map Text Word
|
||||||
|
, psPosition :: Location
|
||||||
|
}
|
||||||
|
|
||||||
|
instance StateM Parser ParserState where
|
||||||
|
get = Parser get
|
||||||
|
set = Parser . set
|
||||||
|
|
||||||
|
instance ExceptionM Parser Error where
|
||||||
|
raise = Parser . raise
|
||||||
|
|
||||||
|
instance RunExceptionM Parser Error where
|
||||||
|
try m = Parser (try (unParser m))
|
||||||
|
|
||||||
|
lexWithLayout :: Source -> Position -> L.Text -> [Located Token]
|
||||||
|
lexWithLayout = undefined
|
||||||
|
|
||||||
|
parseModule :: Source -> L.Text -> Parser Module
|
||||||
|
parseModule = undefined
|
||||||
|
|
||||||
|
parseExpression :: Source -> L.Text -> Parser Module
|
||||||
|
parseModule = undefined
|
||||||
|
|
||||||
|
parseError :: [Located Token] -> Parser a
|
||||||
|
parseError toks =
|
||||||
|
case toks of
|
||||||
|
[] ->
|
||||||
|
raise (Error
|
||||||
|
addError Nothing ErrParser "Unexpected end of file."
|
||||||
|
(Located p (ErrorTok _) : _) ->
|
||||||
|
addError (Just p) ErrLexer "Lexer error"
|
||||||
|
(Located p _ : _) ->
|
||||||
|
addError (Just p) ErrParser "Parser error"
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import Bang.CommandLine
|
import Bang.CommandLine
|
||||||
import Bang.Syntax.Lexer
|
import Bang.Syntax.Lexer
|
||||||
import Bang.Syntax.Location
|
import Bang.Syntax.Location
|
||||||
|
import Bang.Syntax.Parser
|
||||||
import Control.Exception(tryJust)
|
import Control.Exception(tryJust)
|
||||||
import Control.Monad(guard)
|
import Control.Monad(guard)
|
||||||
import qualified Data.Text.Lazy.IO as T
|
import qualified Data.Text.Lazy.IO as T
|
||||||
@@ -24,3 +25,5 @@ runLexer _cmd opts =
|
|||||||
Right txt ->
|
Right txt ->
|
||||||
do let tokens = lexer (File path) (Just initialPosition) txt
|
do let tokens = lexer (File path) (Just initialPosition) txt
|
||||||
mapM_ (putStrLn . show) tokens
|
mapM_ (putStrLn . show) tokens
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user