Skip to content

Commit

Permalink
[add] except keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
AD1024 committed Oct 8, 2024
1 parent 7317620 commit 08aa8bc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions Src/PCompiler/CompilerCore/Parser/PLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ PROVE : 'prove';
USING : 'using';
LEMMA : 'Lemma';
THEOREM : 'Theorem';
EXCEPT : 'except';

// module-system-specific keywords

Expand Down
2 changes: 1 addition & 1 deletion Src/PCompiler/CompilerCore/Parser/PParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ invariantGroupDecl : LEMMA name=iden LBRACE invariantDecl* RBRACE

proofBlockDecl : PROOF LBRACE proofBody RBRACE ;
proofBody : proofItem* ;
proofItem : PROVE (targets+=expr (COMMA targets+=expr)* | goalsAll=MUL) (USING ((premises+=expr (COMMA premises+=expr)*) | premisesAll=MUL))? SEMI # ProveUsingCmd ;
proofItem : PROVE (targets+=expr (COMMA targets+=expr)* | goalsAll=MUL) (USING ((premises+=expr (COMMA premises+=expr)*) | premisesAll=MUL))? (EXCEPT excludes+=expr (COMMA excludes+=expr)*)? SEMI # ProveUsingCmd ;

typeDefDecl : TYPE name=iden SEMI # ForeignTypeDef
| TYPE name=iden ASSIGN type SEMI # PTypeDef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public ProofCommand(string name, ParserRuleContext sourceNode)

public List<Invariant> Goals { get; set; }
public List<Invariant> Premises { get; set; }
public List<Invariant> Excepts { get; set; }
public ParserRuleContext SourceLocation { get; }
public string Name { get; set; }
}
Expand Down
5 changes: 4 additions & 1 deletion Src/PCompiler/CompilerCore/TypeChecker/DeclarationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ public override object VisitProveUsingCmd(PParser.ProveUsingCmdContext context)
var exprVisitor = new ExprVisitor(temporaryFunction, Handler);
List<IPExpr> premises = [];
List<IPExpr> goals = [];
List<IPExpr> excepts = context._excludes.Select(exprVisitor.Visit).ToList();
if (context.premisesAll == null)
{
premises = context._premises.Select(exprVisitor.Visit).ToList();
Expand Down Expand Up @@ -755,8 +756,10 @@ public override object VisitProveUsingCmd(PParser.ProveUsingCmdContext context)
{
proofCmd.Goals = goals.SelectMany(x => ToInvariant(x, context)).ToList();
}
proofCmd.Excepts = excepts.Zip(context._excludes, (x, y) => ToInvariant(x, y)).SelectMany(x => x).ToList();
// exclude things appear in `goals` from `premises`
proofCmd.Premises = proofCmd.Premises.Except(proofCmd.Goals).ToList();
proofCmd.Premises = proofCmd.Premises.Except(proofCmd.Goals).Except(proofCmd.Excepts).ToList();
proofCmd.Goals = proofCmd.Goals.Except(proofCmd.Excepts).ToList();
return proofCmd;
}

Expand Down

0 comments on commit 08aa8bc

Please sign in to comment.