|
|
@ -3,7 +3,6 @@ |
|
|
|
module Frontend.Autogen.Parser where |
|
|
|
|
|
|
|
import qualified Data.Text as T |
|
|
|
import Data.Text (Text) |
|
|
|
|
|
|
|
import Frontend.Lexer.Tokens |
|
|
|
import Frontend.Parser.Posn |
|
|
@ -29,8 +28,11 @@ import Debug.Trace |
|
|
|
%error { parseError } |
|
|
|
|
|
|
|
%token |
|
|
|
VAR { Token (TokVar _) _ _ } |
|
|
|
CON { Token (TokCon _) _ _ } |
|
|
|
VAR { Token (TokUnqual VarId _) _ _ } |
|
|
|
CON { Token (TokUnqual ConId _) _ _ } |
|
|
|
|
|
|
|
QVAR { Token (TokQual VarId _ _) _ _ } |
|
|
|
QCON { Token (TokQual ConId _ _) _ _ } |
|
|
|
STRING { Token (TokString _) _ _ } |
|
|
|
'eof' { Token TokEof _ _ } |
|
|
|
|
|
|
@ -89,8 +91,8 @@ FuncExp :: { Exp } |
|
|
|
| Aexp { $1 } |
|
|
|
|
|
|
|
Aexp :: { Exp } |
|
|
|
: qvar { span $1 $1 $ Ref (getVar $1) } |
|
|
|
| qcon { span $1 $1 $ Con (getVar $1) } |
|
|
|
: qvar { span $1 $1 $ Ref $1 } |
|
|
|
| qcon { span $1 $1 $ Con $1 } |
|
|
|
| '(' CommaList(Exp) ')' { span $1 $3 $ makeTuple $2 } |
|
|
|
| STRING { span $1 $1 $ Literal (LitString (getString $1)) } |
|
|
|
|
|
|
@ -103,10 +105,9 @@ Btype :: { Type } |
|
|
|
| Atype { $1 } |
|
|
|
|
|
|
|
Atype :: { Type } |
|
|
|
: qvar { span $1 $1 $ Tyvar (getVar $1) } |
|
|
|
| qcon { span $1 $1 $ Tycon (getVar $1) } |
|
|
|
: qvar { span $1 $1 $ Tyvar $1 } |
|
|
|
| qcon { span $1 $1 $ Tycon $1 } |
|
|
|
| '(' CommaList(Type) ')' { span $1 $3 $ makeTupleType $2 } |
|
|
|
|
|
|
|
|
|
|
|
Pat :: { Pat } |
|
|
|
: Lpat { $1 } |
|
|
@ -120,9 +121,9 @@ Apat :: { Pat } |
|
|
|
| '(' CommaList(Pat) ')' { span $1 $3 $ makeTuplePattern $2 } |
|
|
|
|
|
|
|
Decl :: { Decl } |
|
|
|
: VAR '::' Type { TySig (getVar $1) $3 } |
|
|
|
| VAR Apat List(Apat) Rhs { FunDecl (getVar $1) ($2:$3) $4 } |
|
|
|
| Pat Rhs { PatDecl $1 $2 } |
|
|
|
: CommaList1(VAR) '::' Type { TySig (getVar `fmap` $1) $3 } |
|
|
|
| VAR Apat List(Apat) Rhs { FunDecl (getVar $1) ($2:$3) $4 } |
|
|
|
| Pat Rhs { PatDecl $1 $2 } |
|
|
|
|
|
|
|
Rhs :: { Rhs } |
|
|
|
: '=' Exp { BareRhs $2 [] } |
|
|
@ -139,16 +140,16 @@ LOLContents(p, End) |
|
|
|
|
|
|
|
Module :: { Module } |
|
|
|
: 'module' CON ImportExportList 'where' LaidOutList(ModItem) |
|
|
|
{ Module { moduleName = getVar $2 |
|
|
|
{ Module { moduleName = toModId (getVar $2) |
|
|
|
, moduleExports = $3 |
|
|
|
, moduleItems = thd $5 } |
|
|
|
} |
|
|
|
|
|
|
|
ImportExportList :: { Maybe [NamespacedItem Text] } |
|
|
|
ImportExportList :: { Maybe [NamespacedItem ParsedVar] } |
|
|
|
: {-empty-} { Nothing } |
|
|
|
| '(' CommaList(NSItem) ')' { Just $2 } |
|
|
|
|
|
|
|
NSItem :: { NamespacedItem Text } |
|
|
|
NSItem :: { NamespacedItem ParsedVar } |
|
|
|
: VAR { IEVar (getVar $1) } |
|
|
|
| CON { IECon (getVar $1) } |
|
|
|
| 'module' CON { IEModule (getVar $2) } |
|
|
@ -157,18 +158,18 @@ ModItem :: { Item } |
|
|
|
: Decl { ModDecl $1 } |
|
|
|
| Import { ModImport $1 } |
|
|
|
|
|
|
|
Import |
|
|
|
: 'import' qcon ImportExportList |
|
|
|
{ Import (getVar $2) $3 False Nothing } |
|
|
|
Import :: { ModuleImport ParsedVar } |
|
|
|
: 'import' modid ImportExportList |
|
|
|
{ Import $2 $3 False Nothing } |
|
|
|
|
|
|
|
| 'import' qcon ImportExportList 'as' CON |
|
|
|
{ Import (getVar $2) $3 False (Just (getVar $5)) } |
|
|
|
| 'import' modid ImportExportList 'as' CON |
|
|
|
{ Import $2 $3 False (Just (getVar $5)) } |
|
|
|
|
|
|
|
| 'import' 'qualified' qcon ImportExportList |
|
|
|
{ Import (getVar $3) $4 True Nothing } |
|
|
|
| 'import' 'qualified' modid ImportExportList |
|
|
|
{ Import $3 $4 True Nothing } |
|
|
|
|
|
|
|
| 'import' 'qualified' qcon ImportExportList 'as' CON |
|
|
|
{ Import (getVar $3) $4 True (Just (getVar $6)) } |
|
|
|
| 'import' 'qualified' modid ImportExportList 'as' CON |
|
|
|
{ Import $3 $4 True (Just (getVar $6)) } |
|
|
|
|
|
|
|
Opt(p) |
|
|
|
: { () } |
|
|
@ -179,8 +180,14 @@ Semis |
|
|
|
| ';' { () } |
|
|
|
|
|
|
|
-- TODO: qualified names |
|
|
|
qvar : VAR { $1 } |
|
|
|
qcon : CON { $1 } |
|
|
|
qvar :: { ParsedVar } |
|
|
|
qvar : VAR { getVar $1 } |
|
|
|
| QVAR { getVar $1 } |
|
|
|
|
|
|
|
qcon : CON { getVar $1 } |
|
|
|
| QCON { getVar $1 } |
|
|
|
|
|
|
|
modid : qcon { toModId $1 } |
|
|
|
|
|
|
|
List(p) |
|
|
|
: {-empty-} { [] } |
|
|
@ -191,19 +198,23 @@ CommaList(p) |
|
|
|
| p { [$1] } |
|
|
|
| p ',' CommaList(p) { $1:$3 } |
|
|
|
|
|
|
|
CommaList1(p) |
|
|
|
: p { [$1] } |
|
|
|
| p ',' CommaList(p) { $1:$3 } |
|
|
|
|
|
|
|
Block(p) |
|
|
|
: START p END { (startPosn $1, endPosn $3, $2) } |
|
|
|
| '{' p '}' { (startPosn $1, endPosn $3, $2) } |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
type Exp = FeExpr Text |
|
|
|
type Pat = FePat Text |
|
|
|
type Decl = FeDecl Text |
|
|
|
type Type = FeType Text |
|
|
|
type Rhs = FeRhs Text |
|
|
|
type Module = FeModule Text |
|
|
|
type Item = ModuleItem Text |
|
|
|
type Exp = FeExpr ParsedVar |
|
|
|
type Pat = FePat ParsedVar |
|
|
|
type Decl = FeDecl ParsedVar |
|
|
|
type Type = FeType ParsedVar |
|
|
|
type Rhs = FeRhs ParsedVar |
|
|
|
type Module = FeModule ParsedVar |
|
|
|
type Item = ModuleItem ParsedVar |
|
|
|
|
|
|
|
lexer cont = alexMonadScan >>= cont |
|
|
|
|
|
|
@ -211,8 +222,9 @@ parseError x = alexError (show x) |
|
|
|
|
|
|
|
makeLams xs b = foldr Lam b xs |
|
|
|
|
|
|
|
getVar (Token (TokVar s) _ _) = s |
|
|
|
getVar (Token (TokCon s) _ _) = s |
|
|
|
getVar :: Token -> ParsedVar |
|
|
|
getVar tok@(Token (TokQual _ p s) _ _) = QualVar { varId = s, varPrefix = p, varBegin = startPosn tok, varEnd = endPosn tok } |
|
|
|
getVar tok@(Token (TokUnqual _ s) _ _) = UnqualVar { varId = s, varBegin = startPosn tok, varEnd = endPosn tok } |
|
|
|
getVar _ = error "getVar non-var" |
|
|
|
|
|
|
|
getString (Token (TokString s) _ _) = s |
|
|
|