Add compatibility with the original record update syntax.

This commit is contained in:
Matus Tejiscak 2020-04-27 18:02:25 +02:00
parent e9c4a5a99d
commit 82a23afae7
4 changed files with 14 additions and 1 deletions

View File

@ -178,8 +178,12 @@ Finally, the examples:
-- prints 3.0 -- prints 3.0
printLn $ (record { topLeft.x = 3 } rect).topLeft.x printLn $ (record { topLeft.x = 3 } rect).topLeft.x
-- but for compatibility, we support the old syntax, too
printLn $ (record { topLeft->x = 3 } rect).topLeft.x
-- prints 2.1 -- prints 2.1
printLn $ (record { topLeft.x $= (+1) } rect).topLeft.x printLn $ (record { topLeft.x $= (+1) } rect).topLeft.x
printLn $ (record { topLeft->x $= (+1) } rect).topLeft.x
Parses but does not typecheck: Parses but does not typecheck:

View File

@ -651,7 +651,7 @@ mutual
field : FileName -> IndentInfo -> Rule PFieldUpdate field : FileName -> IndentInfo -> Rule PFieldUpdate
field fname indents field fname indents
= do path <- map fieldName <$> [| name :: many recField |] = do path <- map fieldName <$> [| name :: many recFieldCompat |]
upd <- (do symbol "="; pure PSetField) upd <- (do symbol "="; pure PSetField)
<|> <|>
(do symbol "$="; pure PSetFieldApp) (do symbol "$="; pure PSetFieldApp)
@ -663,6 +663,11 @@ mutual
fieldName (RF s) = s fieldName (RF s) = s
fieldName _ = "_impossible" fieldName _ = "_impossible"
-- this allows the dotted syntax .field
-- but also the arrowed syntax ->field for compatibility with Idris 1
recFieldCompat : Rule Name
recFieldCompat = recField <|> (symbol "->" *> name)
rewrite_ : FileName -> IndentInfo -> Rule PTerm rewrite_ : FileName -> IndentInfo -> Rule PTerm
rewrite_ fname indents rewrite_ fname indents
= do start <- location = do start <- location

View File

@ -23,4 +23,6 @@ Main> 4.2
Main> 4.2 Main> 4.2
Main> 3 Main> 3
Main> 2.1 Main> 2.1
Main> 3
Main> 2.1
Main> Bye for now! Main> Bye for now!

View File

@ -18,4 +18,6 @@ Point.x pt
x pt x pt
(record { topLeft.x = 3 } rect).topLeft.x (record { topLeft.x = 3 } rect).topLeft.x
(record { topLeft.x $= (+1) } rect).topLeft.x (record { topLeft.x $= (+1) } rect).topLeft.x
(record { topLeft->x = 3 } rect).topLeft.x
(record { topLeft->x $= (+1) } rect).topLeft.x
:q :q