Skip to content

Commit

Permalink
Break lines exceeding 80 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
br4sco committed Feb 5, 2024
1 parent 5165995 commit 9020cde
Showing 1 changed file with 124 additions and 43 deletions.
167 changes: 124 additions & 43 deletions stdlib/mexpr/boot-parser.mc
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ use BootParserTest in
-- Tests where strings of MExpr text is parsed and then pretty printed again.
-- All terms are tested in this way.
let norm : String -> String = lam str.
filter (lam x. not (or (or (eqChar x ' ') (eqChar x '\n')) (eqChar x '\t'))) str in
filter (lam x. not (or (or (eqChar x ' ') (eqChar x '\n')) (eqChar x '\t'))) str
in

-- Test the combination of parsing and pretty printing
let parse = lam ks. lam s. expr2str (parseMExprStringKeywordsExn ks s) in
Expand All @@ -453,7 +454,8 @@ let l_info : [String] -> String -> Info = lam ks. lam s.
infoTm (parseMExprStringKeywordsExn ks s) in
let l_infoClosed = l_info [] in
let r_info : Int -> Int -> Int -> Int -> Info = lam r1. lam c1. lam r2. lam c2.
Info {filename = "internal", row1 = r1, col1 = c1, row2 = r2, col2 = c2} in
Info {filename = "internal", row1 = r1, col1 = c1, row2 = r2, col2 = c2}
in

-- TmVar
let s = "_asdXA123" in
Expand All @@ -477,7 +479,9 @@ utest l_info ["_aas_12"] " _aas_12 " with r_info 1 2 1 9 in
let s = "let y = lam x.x in y" in
utest lsideClosed s with rside s in
utest l_infoClosed " \n lam x.x" with r_info 2 1 2 8 in
utest match parseMExprStringKeywordsExn [] s with TmLet r then infoTm r.body else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet r
then infoTm r.body else NoInfo ()
with r_info 1 8 1 15 in
utest l_info ["y"] " let x = 4 in y " with r_info 1 2 1 14 in
let s = "(printLn x); 10" in
Expand Down Expand Up @@ -540,12 +544,14 @@ utest l_infoClosed " {foo = 123} " with r_info 1 1 1 12 in
let s = "{a with foo = 5}" in
utest lside ["a"] s with rside s in
let s = "{{bar='a', foo=7} with bar = 'b'}" in
let t = recordupdate_ (urecord_ [("bar", char_ 'a'), ("foo", int_ 7)]) "bar" (char_ 'b') in
let t =
recordupdate_
(urecord_ [("bar", char_ 'a'), ("foo", int_ 7)]) "bar" (char_ 'b') in
utest parseMExprStringKeywordsExn [] s with t using eqExpr in
utest l_info ["foo"] " {foo with a = 18 } " with r_info 1 1 1 19 in

-- NOTE(caylak, 2021-03-17): Commented out because test fails since parsing of TyVariant is not supported yet
-- TmType
-- NOTE(caylak, 2021-03-17): Commented out because test fails since parsing of
-- TyVariant is not supported yet TmType
let s = "type Foo=<> in x" in
--utest lsideClosed s with rside s in
utest l_infoClosed " type Bar in () " with r_info 1 2 1 13 in
Expand All @@ -569,78 +575,108 @@ let s = "match foo with _ then 7 else 2" in
utest lside ["foo"] s with rside s in
utest l_infoClosed "match [4] with x then x else [] " with r_info 1 0 1 31 in
let s = " match bar with Foo {a = x} then x else 2" in
utest match parseMExprStringKeywordsExn ["Foo", "bar"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["Foo", "bar"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 16 1 27 in

-- TmMatch, PatSeqTot, PatSeqEdge
let s = "match x with \"\" then x else 2" in
utest lside ["x"] s with rside s in
let s = "match x with [x,y,z] then x else 2" in
utest lside ["x"] s with rside s in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 13 1 20 in
let s = " match x with [a] ++ v ++ [x,y,z] then x else 2" in
utest lside ["x"] s with rside s in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 14 1 33 in
let s = "match x with \"\" ++ x ++ [y] then x else x" in
utest lside ["x"] s with rside s in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 13 1 27 in
let s = "match x with [z] ++ x ++ \"\" then z else 2" in
utest lside ["x"] s with rside s in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 13 1 27 in

--TmMatch, PatRecord
let s = "match x with {} then x else 2" in
utest lside ["x"] s with rside s in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 13 1 15 in
let s = "match x with {bar=_, foo=x} then x else 2" in
let t = match_ (var_ "x")
(prec_ [("bar", pvarw_), ("foo", pvar_ "x")])
(var_ "x") (int_ 2) in
utest parseMExprStringKeywordsExn ["x"] s with t using eqExpr in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 13 1 27 in

--TmMatch, PatCon
let s = "match x with Foo {foo = x} then x else 100" in
utest lside ["x", "Foo"] s with rside s in
utest match parseMExprStringKeywordsExn ["x", "Foo"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x", "Foo"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 13 1 26 in

--TmMatch, PatInt, PatBool, PatChar
let s = "match x with [1,2,12] then x else x" in
utest lside ["x"] s with rside s in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 13 1 21 in
let s = "match x with 'A' then x else x" in
utest lside ["x"] s with rside s in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 13 1 16 in
let s = "match x with [true,false] then x else x" in
utest lside ["x"] s with rside s in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 13 1 25 in

-- TmMatch, PatAnd, PatOr, PatNot
let s = "match x with 1 & x then x else x" in
utest lside ["x"] s with rside s in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 13 1 18 in
let s = "match x with 1 | x then x else x" in
utest lside ["x"] s with rside s in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 13 1 18 in
let s = "match x with !y then x else x" in
utest lside ["x"] s with rside s in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 13 1 15 in
let s = "match 1 with (a & b) | (!c) then x else x" in
utest lside ["x"] s with rside s in
utest match parseMExprStringKeywordsExn ["x"] s with TmMatch r then infoPat r.pat else NoInfo ()
utest
match parseMExprStringKeywordsExn ["x"] s with TmMatch r
then infoPat r.pat else NoInfo ()
with r_info 1 14 1 26 in

-- TmUtest
Expand All @@ -665,51 +701,70 @@ utest l_infoClosed " \n external y! : Int in 1" with r_info 2 2 2 24 in
-- TyUnknown
let s = "let y:Unknown = lam x.x in y" in
utest lsideClosed s with rside "let y = lam x.x in y" in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 13 in
let s = "lam x:Int. lam y:Char. x" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] " \n lam x:Int. lam y:Char. x" with TmLam l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] " \n lam x:Int. lam y:Char. x"
with TmLam l
then infoTy l.tyAnnot else NoInfo ()
with r_info 2 7 2 10 in

-- TyInt
let s = "let y:Int = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 9 in

-- TyFloat
let s = "let y:Float = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 11 in

-- TyChar
let s = "let y:Char = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 10 in

-- TyArrow
let s = "let y:Int->Int = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 14 in

-- Nested TyArrow
let s = "let y:[Float]->Int = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 18 in

-- TySeq
let s = "let y:[Int] = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 11 in

-- Nested TySeq
let s = "let y:[{a:{a_1:Int,a_2:Float},b:{b_1:[Char],b_2:Float}}]= lam x.x in y" in
let s =
"let y:[{a:{a_1:Int,a_2:Float},b:{b_1:[Char],b_2:Float}}]= lam x.x in y"
in
let recTy = tyseq_ (tyrecord_ [
("a", tyrecord_ [
("a_1", tyint_),
Expand All @@ -721,13 +776,17 @@ let typedLet = lam letTy.
bind_ (let_ "y" letTy (ulam_ "x" (var_ "x")))
(var_ "y") in
utest parseMExprStringKeywordsExn [] s with typedLet recTy using eqExpr in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 56 in

-- TyTensor
let s = "let y:Tensor[Int] = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 17 in

-- Nested TyTensor
Expand All @@ -741,18 +800,24 @@ let typedLet = lam letTy.
bind_ (let_ "y" letTy (ulam_ "x" (var_ "x")))
(var_ "y") in
utest parseMExprStringKeywordsExn [] s with typedLet recTy using eqExpr in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 30 in

-- TyRecord
let s = "let y:{a:Int,b:[Char]} = lam x.x in y" in
let recTy = tyrecord_ [("a", tyint_), ("b", tystr_)] in
utest parseMExprStringKeywordsExn [] s with typedLet recTy using eqExpr in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 22 in

-- Nested TyRecord
let s = "let y:{a:{a_1:Int,a_2:Float},b:{b_1:[Char],b_2:Float}} = lam x.x in y" in
let s =
"let y:{a:{a_1:Int,a_2:Float},b:{b_1:[Char],b_2:Float}} = lam x.x in y"
in
let recTy = tyrecord_ [
("a", tyrecord_ [
("a_1", tyint_),
Expand All @@ -761,50 +826,66 @@ let recTy = tyrecord_ [
("b_1", tystr_),
("b_2", tyfloat_)])] in
utest parseMExprStringKeywordsExn [] s with typedLet recTy using eqExpr in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 54 in

-- TyVariant
let s = "let y:<> = lam x.x in y" in
-- NOTE(caylak,2021-03-17): Parsing of TyVariant is not supported yet
--utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 8 in

-- TyVar
let s = "let y:_asd = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 10 in

-- TyAll
let s = "let y:all x.x = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 13 in

-- Nested TyAll
let s = "let y:all x.(all y.all z.z)->all w.w = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 36 in

-- TyCon
let s = "let y:Foo = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 6 1 9 in

-- TyApp
let s = "let y:(Int->Int)Int = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 7 1 19 in

-- Nested TyApp
let s = "let y:((Int->Int)Int->Int)Int = lam x.x in y" in
utest lsideClosed s with rside s in
utest match parseMExprStringKeywordsExn [] s with TmLet l then infoTy l.tyAnnot else NoInfo ()
utest
match parseMExprStringKeywordsExn [] s with TmLet l
then infoTy l.tyAnnot else NoInfo ()
with r_info 1 8 1 29 in

-- Allow free variables
Expand Down

0 comments on commit 9020cde

Please sign in to comment.