Skip to content

CERT-5435 semicolon detection #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 13, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## [2.0.2] - 2024-03-13
### Fixed
- Semicolon not detected at the end of a `definition` statement.

## [2.0.1] - 2024-03-06
### Added
- Now compiling to `linux-aarch64` aka ARM on Linux
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cvldoc_parser_core"
version = "2.0.1"
version = "2.0.2"
edition = "2021"

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ fn decl_parser() -> impl Parser<Token, Intermediate, Error = Simple<Token>> {
let rhs = none_of(Token::Semicolon)
.repeated()
.at_least(1)
.then_ignore(just(Token::Semicolon))
.map_with_span(|_, span| span);
.map_with_span(|_, span| span)
.then_ignore(just(Token::Semicolon));

just(Token::Definition)
.ignore_then(ident())
Expand Down
2 changes: 2 additions & 0 deletions src/parse/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub fn cvl_lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>
';' => Token::Semicolon,
'=' => Token::Equals,
'!' => Token::Excl,
'+' => Token::Plus,
'/' => Token::Slash,
};
let arrow = just("=>").to(Token::Arrow);

Expand Down
36 changes: 36 additions & 0 deletions src/parse/tests/cvl2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::parse::{cvl_parser, decl_parser};

use super::*;
use indoc::formatdoc;
use itertools::Itertools;
Expand Down Expand Up @@ -573,3 +575,37 @@ fn persistent_ghosts() {
check_ghost(&parsed[0], "pers", true);
check_ghost(&parsed[1], "non_pers", false);
}

#[test]
/// this shouldn't trip up the definition end detection:
/// the semicolon should be detected even if it's not whitespace-separated from the previous token.
fn definition_does_not_stop() {
let src = indoc! {"
methods {
function x() external returns uint envfree;
function i() external returns int envfree;
}

// myInvariant: run0 pass run1 fail

definition addBv(uint x, uint y) returns mathint = x+y;

/**
* My amazing invariant (should be @title)
* @notice it is very amazing. Please notice
*/
invariant myInvariant() addBv(x(),1) <= max_uint256 {
preserved setX(uint y) with (env e) {
require y < 1000;
}
}
"};

let parsed = Builder::new(src).build().unwrap();

assert_eq!(parsed.len(), 3);

assert_matches!(&parsed[0].ast, Ast::Methods { .. });
assert_matches!(&parsed[1].ast, Ast::Definition { definition, ..} if definition == "x+y");
assert_matches!(&parsed[2].ast, Ast::Invariant { .. });
}
4 changes: 4 additions & 0 deletions src/parse/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub enum Token {
Semicolon,
Equals,
Excl,
Plus,
Slash,
Arrow,
Axiom,
Using,
Expand Down Expand Up @@ -86,6 +88,8 @@ impl Display for Token {
Token::Semicolon => write!(f, ";"),
Token::Equals => write!(f, "="),
Token::Excl => write!(f, "!"),
Token::Plus => write!(f, "+"),
Token::Slash => write!(f, "/"),
Token::Arrow => write!(f, "=>"),
Token::Axiom => write!(f, "axiom"),
Token::Using => write!(f, "using"),
Expand Down
2 changes: 1 addition & 1 deletion src/python_wrapper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cvldoc_parser_py"
version = "2.0.1"
version = "2.0.2"
edition = "2021"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion src/python_wrapper/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "maturin"

[project]
name = "cvldoc_parser"
version = "2.0.1"
version = "2.0.2"
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Rust",
Expand Down