on master help sign in
Simplified some lookaheads and grammar rules for

lambda expressions and other internal expressions. Names do not expect lchar '.' but '.' for simplfied naming.

commit08fbb4efbb274b3aab6840291e7e87ab83b0e6f8 authorAhmad Salim Al-Sibahi <asal@itu.dk> dateFri 11 Apr 2014, 12:33 (13 years ago) parent78c27e9
3 files changed+28−25
src/Idris/ParseExpr.hs+27−22 src/Idris/ParseHelpers.hs+1−1 src/Idris/Parser.hs−2
src/Idris/ParseExpr.hs+27−22
@@ -209,9 +209,9 @@ internalExpr :: SyntaxInfo -> IdrisParser PTerm
209209internalExpr syn =
210210 try (app syn)
211211 <|> try (matchApp syn)
212− <|> try (unifyLog syn)
212+ <|> unifyLog syn
213213 <|> try (disamb syn)
214− <|> try (noImplicits syn)
214+ <|> noImplicits syn
215215 <|> recordType syn
216216 <|> lambda syn
217217 <|> quoteGoal syn
@@ -289,7 +289,7 @@ SimpleExpr ::=
289289 | Comprehension
290290 | Alt
291291 | Idiom
292− | '(' Bracketed
292+ | Bracketed
293293 | Constant
294294 | Type
295295 | '_|_'
@@ -328,8 +328,7 @@ simpleExpr syn =
328328 s <- simpleExpr syn
329329 fc <- getFC
330330 return (PAppBind fc s [])
331− <|> do lchar '('
332− bracketed (disallowImp syn)
331+ <|> bracketed (disallowImp syn)
333332 <|> do symbol "_|_"
334333 fc <- getFC
335334 return (PFalse fc)
@@ -337,10 +336,16 @@ simpleExpr syn =
337336 <|> simpleExternalExpr syn
338337 <?> "expression"
339338
340−
339+{- |Parses an expression in braces
340+@
341+Bracketed ::= '(' Bracketed'
342+ -}
343+bracketed :: SyntaxInfo -> IdrisParser PTerm
344+bracketed syn = do lchar '(' <?> "parenthesized expression"
345+ bracketed' syn
341346{- |Parses the rest of an expression in braces
342347@
343−Bracketed ::=
348+Bracketed' ::=
344349 ')'
345350 | Expr ')'
346351 | ExprList ')'
@@ -351,8 +356,8 @@ Bracketed ::=
351356 ;
352357@
353358-}
354−bracketed :: SyntaxInfo -> IdrisParser PTerm
355−bracketed syn =
359+bracketed' :: SyntaxInfo -> IdrisParser PTerm
360+bracketed' syn =
356361 do lchar ')'
357362 fc <- getFC
358363 return $ PTrue fc TypeOrTerm
@@ -502,7 +507,7 @@ UnifyLog ::=
502507 ;
503508-}
504509unifyLog :: SyntaxInfo -> IdrisParser PTerm
505−unifyLog syn = do lchar '%'; reserved "unifyLog";
510+unifyLog syn = do try (lchar '%' *> reserved "unifyLog")
506511 tm <- simpleExpr syn
507512 return (PUnifyLog tm)
508513 <?> "unification log expression"
@@ -528,7 +533,7 @@ NoImplicits ::=
528533@
529534-}
530535noImplicits :: SyntaxInfo -> IdrisParser PTerm
531−noImplicits syn = do lchar '%'; reserved "noImplicits";
536+noImplicits syn = do try (lchar '%' *> reserved "noImplicits")
532537 tm <- simpleExpr syn
533538 return (PNoImplicits tm)
534539 <?> "no implicits expression"
@@ -700,17 +705,17 @@ SimpleExprList ::=
700705@
701706-}
702707lambda :: SyntaxInfo -> IdrisParser PTerm
703−lambda syn = do lchar '\\'
704− try (do xt <- tyOptDeclList syn
705− symbol "=>"
706− sc <- expr syn
707− return (bindList PLam xt sc)
708− <|> (do ps <- sepBy (do fc <- getFC
709− e <- simpleExpr syn
710− return (fc, e)) (lchar ',')
711− symbol "=>"
712− sc <- expr syn
713− return (pmList (zip [0..] ps) sc)))
708+lambda syn = do lchar '\\' <?> "lambda expression"
709+ (do xt <- try $ tyOptDeclList syn
710+ symbol "=>"
711+ sc <- expr syn
712+ return (bindList PLam xt sc)) <|> do
713+ ps <- sepBy (do fc <- getFC
714+ e <- simpleExpr syn
715+ return (fc, e)) (lchar ',')
716+ symbol "=>"
717+ sc <- expr syn
718+ return (pmList (zip [0..] ps) sc)
714719 <?> "lambda expression"
715720 where pmList :: [(Int, (FC, PTerm))] -> PTerm -> PTerm
716721 pmList [] sc = sc
src/Idris/ParseHelpers.hs+1−1
@@ -214,7 +214,7 @@ idrisStyle :: MonadicParsing m => IdentifierStyle m
214214idrisStyle = IdentifierStyle _styleName _styleStart _styleLetter _styleReserved Hi.Identifier Hi.ReservedIdentifier
215215 where _styleName = "Idris"
216216 _styleStart = satisfy isAlpha
217− _styleLetter = satisfy isAlphaNum <|> oneOf "_'" <|> (lchar '.')
217+ _styleLetter = satisfy isAlphaNum <|> oneOf "_'."
218218 _styleReserved = HS.fromList ["let", "in", "data", "codata", "record", "Type",
219219 "do", "dsl", "import", "impossible",
220220 "case", "of", "total", "partial", "mutual",
src/Idris/Parser.hs−2
@@ -831,7 +831,6 @@ clause syn
831831 return $ PClause fc n capp wargs rs wheres) <|> (do
832832 popIndent
833833 reserved "with"
834− lchar '(' <?> "parenthesized expression"
835834 wval <- bracketed syn
836835 openBlock
837836 ds <- some $ fnDecl syn
@@ -865,7 +864,6 @@ clause syn
865864 reserved "with"
866865 ist <- get
867866 put (ist { lastParse = Just n })
868− lchar '(' <?> "parenthesized expression"
869867 wval <- bracketed syn
870868 openBlock
871869 ds <- some $ fnDecl syn