Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ari Angga Nugraha
ariangganugraha-funpro2020-lambda
Commits
dbc536ac
Commit
dbc536ac
authored
Dec 31, 2016
by
Sean Gillespie
Browse files
Update System F parser
Add type application
parent
3e8c332e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/Language/SystemF/Parser.hs
View file @
dbc536ac
...
...
@@ -19,16 +19,19 @@ parseType = parse (whitespace *> ty <* eof) ""
-- Parse expressions
expr
::
Parser
(
SystemFExpr
String
String
)
expr
=
try
app
<|>
term
expr
=
try
tyapp
<|>
try
app
<|>
term
app
::
Parser
(
SystemFExpr
String
String
)
app
=
chainl1
term
(
return
App
)
tyapp
::
Parser
(
SystemFExpr
String
String
)
tyapp
=
TyApp
<$>
term
<*>
ty'
where
ty'
=
symbol
'['
*>
ty
<*
symbol
']'
term
::
Parser
(
SystemFExpr
String
String
)
term
=
try
abs
<|>
tyabs
<|>
var
<|>
parens
expr
term
=
try
abs
<|>
tyabs
<|>
var
<|>
parens
expr
var
::
Parser
(
SystemFExpr
String
String
)
var
=
Var
<$>
exprId
...
...
test/Language/SystemF/ParserSpec.hs
View file @
dbc536ac
...
...
@@ -22,6 +22,9 @@ spec = do
it
"parses simple type abstractions"
$
parseExpr
"
\\
X. x"
`
shouldBe
`
Right
(
TyAbs
"X"
(
Var
"x"
))
it
"parses simple type applications"
$
parseExpr
"x [T]"
`
shouldBe
`
Right
(
TyApp
(
Var
"x"
)
(
TyVar
"T"
))
it
"parses nested abstractions"
$
parseExpr
"
\\
a:A b:B. b"
`
shouldBe
`
Right
(
Abs
"a"
(
TyVar
"A"
)
(
Abs
"b"
(
TyVar
"B"
)
(
Var
"b"
)))
...
...
@@ -42,7 +45,8 @@ spec = do
"(
\\
p:(X->Y->Z) x:X y:Y. y) (
\\
p:(A->B->C) x:B y:C. x)"
,
"f (
\\
x:T. x)"
,
"(
\\
x:X . f x) g y"
,
"(
\\
f:(X->Y) . (
\\
x:X y:Y. f x y) f x y) w x y"
"(
\\
f:(X->Y) . (
\\
x:X y:Y. f x y) f x y) w x y"
,
"(
\\
x:T. x) [U]"
]
mapM_
(
flip
shouldSatisfy
isRight
.
parseExpr
)
exprs
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment