Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Lean/Parser/Term.lean
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ namespace Term
def byTactic' := leading_parser
"by " >> Tactic.tacticSeqIndentGt

/-- `termBeforeBy` is defined as `withForbidden("by", term)`, which will parse a term but
disallows `by` outside of a bracketing construct. This is used for parsers like `show p by ...`
or `suffices p by ...`, where we do not want `p by ...` to be parsed as an application of `p` to a
`by` block, which would otherwise be allowed. -/
def termBeforeBy := withForbidden "by" termParser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, since this is not used anywhere yet, you'll have to tag it with @[run_builtin_parser_attribute_hooks] to make the alias work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do need to use it in this file, but I had originally left this for the follow-up PR. I've now added the two uses in this PR.


-- TODO: rename to e.g. `afterSemicolonOrLinebreak`
def optSemicolon (p : Parser) : Parser :=
ppDedent $ semicolonOrLinebreak >> ppLine >> p
Expand Down Expand Up @@ -214,10 +220,10 @@ def showRhs := fromTerm <|> byTactic'
/-- A `sufficesDecl` represents everything that comes after the `suffices` keyword:
an optional `x :`, then a term `ty`, then `from val` or `by tac`. -/
@[builtin_doc] def sufficesDecl := leading_parser
(atomic (group (binderIdent >> " : ")) <|> hygieneInfo) >> termParser >> ppSpace >> showRhs
(atomic (group (binderIdent >> " : ")) <|> hygieneInfo) >> termBeforeBy >> ppSpace >> showRhs
@[builtin_term_parser] def «suffices» := leading_parser:leadPrec
withPosition ("suffices " >> sufficesDecl) >> optSemicolon termParser
@[builtin_term_parser] def «show» := leading_parser:leadPrec "show " >> termParser >> ppSpace >> showRhs
@[builtin_term_parser] def «show» := leading_parser:leadPrec "show " >> termBeforeBy >> ppSpace >> showRhs
/--
`@x` disables automatic insertion of implicit parameters of the constant `x`.
`@e` for any term `e` also disables the insertion of implicit lambdas at this position.
Expand Down Expand Up @@ -444,7 +450,7 @@ def letEqnsDecl := leading_parser (withAnonymousAntiquot := false)
-- Remark: we disable anonymous antiquotations here to make sure
-- anonymous antiquotations (e.g., `$x`) are not `letDecl`
notFollowedBy (nonReservedSymbol "rec") "rec" >>
(letPatDecl true <|> letIdDecl <|> letPatDecl <|> letEqnsDecl)
withoutForbidden (letPatDecl true <|> letIdDecl <|> letPatDecl <|> letEqnsDecl)
/--
`+nondep` elaborates as a nondependent `let`, a `have` expression.
-/
Expand Down Expand Up @@ -1036,6 +1042,7 @@ builtin_initialize
register_parser_alias attrKind
register_parser_alias optSemicolon
register_parser_alias structInstFields
register_parser_alias termBeforeBy

end Parser
end Lean
2 changes: 2 additions & 0 deletions src/stdlib_flags.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "util/options.h"

// please update stage0

namespace lean {
options get_default_options() {
options opts;
Expand Down
Loading