Skip to content

Commit ad9175b

Browse files
authored
Merge pull request #33 from Certora/semicolon_detection
CERT-5435 semicolon detection
2 parents 7a076af + 3ae56f5 commit ad9175b

File tree

8 files changed

+51
-5
lines changed

8 files changed

+51
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## [2.0.2] - 2024-03-13
3+
### Fixed
4+
- Semicolon not detected at the end of a `definition` statement.
5+
26
## [2.0.1] - 2024-03-06
37
### Added
48
- Now compiling to `linux-aarch64` aka ARM on Linux

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cvldoc_parser_core"
3-
version = "2.0.1"
3+
version = "2.0.2"
44
edition = "2021"
55

66
[dependencies]

src/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ fn decl_parser() -> impl Parser<Token, Intermediate, Error = Simple<Token>> {
135135
let rhs = none_of(Token::Semicolon)
136136
.repeated()
137137
.at_least(1)
138-
.then_ignore(just(Token::Semicolon))
139-
.map_with_span(|_, span| span);
138+
.map_with_span(|_, span| span)
139+
.then_ignore(just(Token::Semicolon));
140140

141141
just(Token::Definition)
142142
.ignore_then(ident())

src/parse/lexer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub fn cvl_lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>
4848
';' => Token::Semicolon,
4949
'=' => Token::Equals,
5050
'!' => Token::Excl,
51+
'+' => Token::Plus,
52+
'/' => Token::Slash,
5153
};
5254
let arrow = just("=>").to(Token::Arrow);
5355

src/parse/tests/cvl2.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::parse::{cvl_parser, decl_parser};
2+
13
use super::*;
24
use indoc::formatdoc;
35
use itertools::Itertools;
@@ -573,3 +575,37 @@ fn persistent_ghosts() {
573575
check_ghost(&parsed[0], "pers", true);
574576
check_ghost(&parsed[1], "non_pers", false);
575577
}
578+
579+
#[test]
580+
/// this shouldn't trip up the definition end detection:
581+
/// the semicolon should be detected even if it's not whitespace-separated from the previous token.
582+
fn definition_does_not_stop() {
583+
let src = indoc! {"
584+
methods {
585+
function x() external returns uint envfree;
586+
function i() external returns int envfree;
587+
}
588+
589+
// myInvariant: run0 pass run1 fail
590+
591+
definition addBv(uint x, uint y) returns mathint = x+y;
592+
593+
/**
594+
* My amazing invariant (should be @title)
595+
* @notice it is very amazing. Please notice
596+
*/
597+
invariant myInvariant() addBv(x(),1) <= max_uint256 {
598+
preserved setX(uint y) with (env e) {
599+
require y < 1000;
600+
}
601+
}
602+
"};
603+
604+
let parsed = Builder::new(src).build().unwrap();
605+
606+
assert_eq!(parsed.len(), 3);
607+
608+
assert_matches!(&parsed[0].ast, Ast::Methods { .. });
609+
assert_matches!(&parsed[1].ast, Ast::Definition { definition, ..} if definition == "x+y");
610+
assert_matches!(&parsed[2].ast, Ast::Invariant { .. });
611+
}

src/parse/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub enum Token {
3535
Semicolon,
3636
Equals,
3737
Excl,
38+
Plus,
39+
Slash,
3840
Arrow,
3941
Axiom,
4042
Using,
@@ -86,6 +88,8 @@ impl Display for Token {
8688
Token::Semicolon => write!(f, ";"),
8789
Token::Equals => write!(f, "="),
8890
Token::Excl => write!(f, "!"),
91+
Token::Plus => write!(f, "+"),
92+
Token::Slash => write!(f, "/"),
8993
Token::Arrow => write!(f, "=>"),
9094
Token::Axiom => write!(f, "axiom"),
9195
Token::Using => write!(f, "using"),

src/python_wrapper/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cvldoc_parser_py"
3-
version = "2.0.1"
3+
version = "2.0.2"
44
edition = "2021"
55

66
[lib]

src/python_wrapper/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "maturin"
44

55
[project]
66
name = "cvldoc_parser"
7-
version = "2.0.1"
7+
version = "2.0.2"
88
requires-python = ">=3.9"
99
classifiers = [
1010
"Programming Language :: Rust",

0 commit comments

Comments
 (0)