Merge pull request #1115 from AleoHQ/bug/abnf-parser-bugs

[Fix] Abnf and Parser Alignment and Equality Change
This commit is contained in:
Alessandro Coglio 2021-07-13 11:24:57 -07:00 committed by GitHub
commit a0dc00bbd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
122 changed files with 407 additions and 386 deletions

1
Cargo.lock generated
View File

@ -1222,6 +1222,7 @@ dependencies = [
"leo-imports",
"leo-input",
"leo-package",
"leo-parser",
"leo-state",
"leo-synthesizer",
"notify",

View File

@ -61,6 +61,10 @@ version = "1.5.2"
path = "./package"
version = "1.5.2"
[dependencies.leo-parser]
path = "./parser"
version = "1.5.2"
[dependencies.leo-state]
path = "./state"
version = "1.5.2"

View File

@ -1,3 +1,3 @@
function main(a: address, b: address, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: field, b: field, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: group, b: group, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: i128, b: i128, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: i128, b: i128, c: bool) {
console.assert(a != b == c);
console.assert((a != b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: i16, b: i16, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: i16, b: i16, c: bool) {
console.assert(a != b == c);
console.assert((a != b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: i32, b: i32, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: i32, b: i32, c: bool) {
console.assert(a != b == c);
console.assert((a != b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: i64, b: i64, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: i64, b: i64, c: bool) {
console.assert(a != b == c);
console.assert((a != b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: i8, b: i8, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: i8, b: i8, c: bool) {
console.assert(a != b == c);
console.assert((a != b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: u128, b: u128, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: u128, b: u128, c: bool) {
console.assert(a != b == c);
console.assert((a != b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: u16, b: u16, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: u16, b: u16, c: bool) {
console.assert(a != b == c);
console.assert((a != b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: u32, b: u32, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: u32, b: u32, c: bool) {
console.assert(a != b == c);
console.assert((a != b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: u64, b: u64, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: u64, b: u64, c: bool) {
console.assert(a != b == c);
console.assert((a != b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: u8, b: u8, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -1,3 +1,3 @@
function main(a: u8, b: u8, c: bool) {
console.assert(a != b == c);
console.assert((a != b) == c);
}

View File

@ -453,7 +453,7 @@ identifier = letter *( letter / digit / "_" ) ; but not a keyword or aleo1...
; A package name consists of one or more segments separated by single dashes,
; where each segment is a non-empty sequence of lowercase letters and digits.
package-name = 1*( lowercase-letter / digit )
package-name = lowercase-letter *( lowercase-letter / digit )
*( "-" 1*( lowercase-letter / digit ) )
; Annotations have names, which are identifiers immediately preceded by `@`.
@ -848,8 +848,8 @@ ordering-expression = additive-expression
; the rule below makes them left-associative.
equality-expression = ordering-expression
/ equality-expression "==" ordering-expression
/ equality-expression "!=" ordering-expression
/ ordering-expression "==" ordering-expression
/ ordering-expression "!=" ordering-expression
; Next come conjunctive expressions, left-associative.
@ -962,7 +962,7 @@ assert-call = %s"assert" "(" expression ")"
print-function = %s"debug" / %s"error" / %s"log"
print-arguments = "(" [ string-literal *( "," expression ) ] ")"
print-arguments = "(" string-literal *( "," expression ) ")"
print-call = print-function print-arguments
@ -1020,7 +1020,7 @@ member-function-declaration = function-declaration
; this may be relaxed after the backward compatibility is removed,
; allowing member variables and member functions to be intermixed.
circuit-declaration = *annotation %s"circuit" identifier
circuit-declaration = %s"circuit" identifier
"{" [ member-variable-declarations ]
*member-function-declaration "}"

View File

@ -20,6 +20,7 @@ use leo_package::{
outputs::OutputsDirectory,
root::{ZipFile, AUTHOR_PLACEHOLDER},
};
use leo_parser::KEYWORD_TOKENS;
use anyhow::{anyhow, Result};
use structopt::StructOpt;
@ -47,6 +48,10 @@ impl Command for Publish {
let manifest = context.manifest()?;
let package_name = manifest.get_package_name();
if KEYWORD_TOKENS.iter().any(|keyword| keyword.to_string() == package_name) {
return Err(anyhow!("Cannot name a package after a keyword"));
}
let package_version = manifest.get_package_version();
match (

View File

@ -100,6 +100,10 @@ impl SyntaxError {
)
}
pub fn unexpected_statement(got: String, expected: &str, span: &Span) -> Self {
Self::new_from_span(format!("expected '{}', got '{}'", expected, got), span)
}
pub fn unexpected_str(got: &Token, expected: &str, span: &Span) -> Self {
Self::new_from_span(format!("expected '{}', got '{}'", expected, got.to_string()), span)
}

View File

@ -25,6 +25,7 @@
extern crate thiserror;
pub(crate) mod tokenizer;
pub use tokenizer::KEYWORD_TOKENS;
pub(crate) use tokenizer::*;
pub mod errors;

View File

@ -187,7 +187,7 @@ impl ParserContext {
///
pub fn parse_equality_expression(&mut self) -> SyntaxResult<Expression> {
let mut expr = self.parse_ordering_expression()?;
while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Eq, Token::NotEq]) {
if let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Eq, Token::NotEq]) {
let right = self.parse_ordering_expression()?;
expr = Expression::Binary(BinaryExpression {
span: expr.span() + right.span(),

View File

@ -102,11 +102,20 @@ impl ParserContext {
let end_span;
let arguments = if self.eat(Token::LeftParen).is_some() {
let mut args = Vec::new();
let mut comma = false;
loop {
if let Some(end) = self.eat(Token::RightParen) {
if comma {
return Err(SyntaxError::unexpected(
&Token::RightParen,
&[Token::Ident("identifier".into()), Token::Int("number".into())],
&end.span,
));
}
end_span = end.span;
break;
}
comma = false;
if let Some(ident) = self.eat_identifier() {
args.push(ident.name);
} else if let Some((int, _)) = self.eat_int() {
@ -115,10 +124,11 @@ impl ParserContext {
let token = self.peek()?;
return Err(SyntaxError::unexpected_str(&token.token, "ident or int", &token.span));
}
if self.eat(Token::Comma).is_none() {
if self.eat(Token::Comma).is_none() && !comma {
end_span = self.expect(Token::RightParen)?;
break;
}
comma = true;
}
args
} else {

View File

@ -185,7 +185,17 @@ impl ParserContext {
self.fuzzy_struct_state = false;
let body = self.parse_block()?;
let next = if self.eat(Token::Else).is_some() {
Some(Box::new(self.parse_statement()?))
let s = self.parse_statement()?;
match s {
Statement::Block(_) | Statement::Conditional(_) => Some(Box::new(s)),
s => {
return Err(SyntaxError::unexpected_statement(
s.to_string(),
"Block or Conditional",
s.span(),
));
}
}
} else {
None
};

View File

@ -22,6 +22,7 @@
pub(crate) mod token;
use std::sync::Arc;
pub use self::token::KEYWORD_TOKENS;
pub(crate) use self::token::*;
pub(crate) mod lexer;

View File

@ -1,3 +1,3 @@
function main(a: group, b: group, c: bool) {
console.assert(a == b == c);
console.assert((a == b) == c);
}

View File

@ -8,5 +8,5 @@ function main(y: bool) -> bool {
const a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)];
const b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2];
return a == b == y;
return (a == b) == y;
}

View File

@ -9,5 +9,5 @@ function main(y: bool) -> bool {
const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline
const b: [u32; (3, 2)] = [[0; 2]; 3]; // initializer
return a == b == y;
return (a == b) == y;
}

View File

@ -10,5 +10,5 @@ function main(y: bool) -> bool {
const actual = arr[..2]; // Should produce [0, 1]
return expected == actual == y;
return (expected == actual) == y;
}

View File

@ -9,5 +9,5 @@ function main(y: bool) -> bool {
const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline
const b: [u32; (3, 2)] = [0; (3, 2)]; // initializer
return a == b == y;
return (a == b) == y;
}

View File

@ -12,5 +12,5 @@ function main(y: bool) -> bool {
const b: [[[u8; 2]; 3]; 4] = [[[0; 2]; 3]; 4]; // initializer
return a == b == y;
return (a == b) == y;
}

View File

@ -8,5 +8,5 @@ function main(y: bool) -> bool {
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
const b: [[u8; 2]; 3] = [0; (3, 2)]; // initializer
return a == b == y;
return (a == b) == y;
}

View File

@ -12,5 +12,5 @@ function main(y: bool) -> bool {
const b: [[[u8; 2]; 3]; 4] = [0; (4, 3, 2)]; // initializer
return a == b == y;
return (a == b) == y;
}

View File

@ -9,5 +9,5 @@ function main(y: bool) -> bool {
const b: [u8; (3, 2)] = [[0; 2]; 3]; // initializer
return a == b == y;
return (a == b) == y;
}

View File

@ -12,5 +12,5 @@ function main(y: bool) -> bool {
const b: [u8; (4, 3, 2)] = [[[0; 2]; 3]; 4]; // initializer
return a == b == y;
return (a == b) == y;
}

View File

@ -9,5 +9,5 @@ function main(y: bool) -> bool {
const b: [u8; (3, 2)] = [0; (3, 2)]; // initializer
return a == b == y;
return (a == b) == y;
}

View File

@ -12,5 +12,5 @@ function main(y: bool) -> bool{
const b: [u8; (4, 3, 2)] = [0; (4, 3, 2)]; // initializer
return a == b == y;
return (a == b) == y;
}

View File

@ -15,5 +15,5 @@ circuit Foo {
function main(y: bool) -> bool {
let f = Foo { a: 0u8 };
return 1u8 == f.use_a() == true;
return (1u8 == f.use_a()) == true;
}

View File

@ -25,5 +25,5 @@ function main(const x: u8, y: bool) -> bool {
const a = Foo { x };
const b = Foo::new(x);
return b.x == a.x == y;
return (b.x == a.x) == y;
}

View File

@ -15,5 +15,5 @@ circuit Foo {
function main(y: bool) -> bool {
const a = Foo { x: 1u32 };
return a.echo() == 1u32 == true;
return (a.echo() == 1u32) == true;
}

View File

@ -13,5 +13,5 @@ circuit Foo {
function main(y: bool) -> bool {
const a = Foo::echo(1u32);
return a == 1u32 == y;
return (a == 1u32) == y;
}

View File

@ -11,5 +11,5 @@ circuit Foo {
function main(y: bool) -> bool {
const a = Foo { x: 1u32 };
return a.x == 1u32 == y;
return (a.x == 1u32) == y;
}

View File

@ -16,5 +16,5 @@ function main(y: bool) -> bool {
const a = Foo { foo: 1 };
const b = a.foo + Foo::bar();
return b == 2u32 == y;
return (b == 2u32) == y;
}

View File

@ -18,5 +18,5 @@ function main(y: bool) -> bool {
f.set_a(1u8);
f.set_a(2u8);
return f.a == 2u8 == y;
return (f.a == 2u8) == y;
}

View File

@ -22,5 +22,5 @@ function main(y: bool) -> bool {
f.set_a(false, 2u8);
f.set_a(true, 2u8);
return f.a == 2u8 == y;
return (f.a == 2u8) == y;
}

View File

@ -14,5 +14,5 @@ function main(y: bool) -> bool {
f.a = 1u8;
f.a = 2u8;
return f.a == 2u8 == true;
return (f.a == 2u8) == true;
}

View File

@ -25,5 +25,5 @@ function main(y: bool) -> bool {
const t = TestMe {x: 6u8}.test_me();
const u = my_fn().test_me();
const v = TestMe::new().test_me();
return v == 2u8 == y;
return (v == 2u8) == y;
}

View File

@ -16,5 +16,5 @@ function main(y: bool) -> bool {
const a = Foo { f: 1u32 };
const b = a.bar();
return b == 1u32 == y;
return (b == 1u32) == y;
}

View File

@ -15,5 +15,5 @@ function main(y: bool) -> bool {
a += one();
}
return a == 10u32 == y;
return (a == 10u32) == y;
}

View File

@ -17,5 +17,5 @@ function iteration() -> u32 {
function main(y: bool) -> bool {
const total = iteration() + iteration();
return total == 20 == y;
return (total == 20) == y;
}

View File

@ -11,5 +11,5 @@ function one() -> bool {
function main(y: bool) -> bool {
const a = one() && one();
return a == true == y;
return (a == true) == y;
}

View File

@ -9,5 +9,5 @@ function one() -> u32 {
}
function main(y: bool) -> bool {
return one() == 1u32 == y;
return (one() == 1u32) == y;
}

View File

@ -21,5 +21,5 @@ function main(y: bool) -> bool {
const a = 1u32;
bad_mutate(a);
return a == 1u32 == y; // <- value `a` is still `1u32`
return (a == 1u32) == y; // <- value `a` is still `1u32`
}

View File

@ -6,5 +6,5 @@
import test-import.foo as bar;
function main(y: bool) -> bool {
return bar() == 1u32 == y;
return (bar() == 1u32) == y;
}

View File

@ -6,5 +6,5 @@
import test-import.foo;
function main(y: bool) -> bool {
return foo() == 1u32 == true;
return (foo() == 1u32) == true;
}

View File

@ -27,5 +27,5 @@ function main(y: bool) -> bool {
const car = Car { c: 1u32 };
return car.c == 1u32 == y;
return (car.c == 1u32) == y;
}

View File

@ -20,5 +20,5 @@ function main(y: bool) -> bool {
const car = Car { c: 1u32 };
return car.c == 1u32 == y;
return (car.c == 1u32) == y;
}

View File

@ -11,5 +11,5 @@ import test-import.(
function main(y: bool) -> bool {
const a = Point { x: 1u32, y: 0u32 };
return a.x == 1u32 == y;
return (a.x == 1u32) == y;
}

View File

@ -8,5 +8,5 @@ import test-import.*;
function main(y: bool) -> bool {
const a = Point { x: 1u32, y: 0u32 };
return foo() == 1u32 == y;
return (foo() == 1u32) == y;
}

View File

@ -5,5 +5,5 @@ input_file: input/main.in
*/
function main(const a: bool, b: bool) -> bool {
return a == true == b;
return (a == true) == b;
}

View File

@ -6,5 +6,5 @@ input_file: input/main_array.in
function main(const x: [i16; 1], y: bool) -> bool {
console.log("{}", x);
return x[0] == 0 == y;
return (x[0] == 0) == y;
}

View File

@ -5,5 +5,5 @@ input_file: input/main_multiple.in
*/
function main(const a: bool, const b: bool, y: bool) -> bool {
return a != b == y;
return (a != b) == y;
}

View File

@ -13,5 +13,5 @@ inputs:
*/
function main(a: i128, b: i128, c: bool) -> bool {
return a == b == c;
return (a == b) == c;
}

View File

@ -21,5 +21,5 @@ inputs:
*/
function main(a: i128, b: i128, c: bool) -> bool{
return a != b == c;
return (a != b) == c;
}

View File

@ -7,5 +7,5 @@ input_file: ../input/dummy.in
function main(y: bool) -> bool{
const a = -128i128;
const b = -a;
return b == -a == y;
return (b == -a) == y;
}

View File

@ -13,5 +13,5 @@ inputs:
function main(y: bool) -> bool {
const a = 0i128;
return -a == 0i128 == y;
return (-a == 0i128) == y;
}

View File

@ -13,5 +13,5 @@ inputs:
*/
function main(a: i16, b: i16, c: bool) -> bool {
return a == b == c;
return (a == b) == c;
}

View File

@ -21,5 +21,5 @@ inputs:
*/
function main(a: i16, b: i16, c: bool) -> bool{
return a != b == c;
return (a != b) == c;
}

View File

@ -7,5 +7,5 @@ input_file: ../input/dummy.in
function main(y: bool) -> bool {
const a = -128i16;
const b = -a;
return b == -a == y;
return (b == -a) == y;
}

View File

@ -13,5 +13,5 @@ inputs:
function main(y: bool) -> bool {
const a = 0i16;
return -a == 0i16 == y;
return (-a == 0i16) == y;
}

View File

@ -13,5 +13,5 @@ inputs:
*/
function main(a: i32, b: i32, c: bool) -> bool {
return a == b == c;
return (a == b) == c;
}

View File

@ -21,5 +21,5 @@ inputs:
*/
function main(a: i32, b: i32, c: bool) -> bool{
return a != b == c;
return (a != b) == c;
}

View File

@ -7,5 +7,5 @@ input_file: ../input/dummy.in
function main(y: bool) -> bool{
const a = -128i32;
const b = -a;
return b == -a == y;
return (b == -a) == y;
}

View File

@ -13,5 +13,5 @@ inputs:
function main(y: bool) -> bool {
const a = 0i32;
return -a == 0i32 == y;
return (-a == 0i32) == y;
}

View File

@ -13,5 +13,5 @@ inputs:
*/
function main(a: i64, b: i64, c: bool) -> bool {
return a == b == c;
return (a == b) == c;
}

View File

@ -21,5 +21,5 @@ inputs:
*/
function main(a: i64, b: i64, c: bool) -> bool{
return a != b == c;
return (a != b) == c;
}

View File

@ -7,5 +7,5 @@ input_file: ../input/dummy.in
function main(y: bool) -> bool{
const a = -128i64;
const b = -a;
return b == -a == y;
return (b == -a) == y;
}

View File

@ -13,5 +13,5 @@ inputs:
function main(y: bool) -> bool {
const a = 0i64;
return -a == 0i64 == y;
return (-a == 0i64) == y;
}

View File

@ -13,5 +13,5 @@ inputs:
*/
function main(a: i8, b: i8, c: bool) -> bool {
return a == b == c;
return (a == b) == c;
}

View File

@ -21,5 +21,5 @@ inputs:
*/
function main(a: i8, b: i8, c: bool) -> bool{
return a != b == c;
return (a != b) == c;
}

View File

@ -13,5 +13,5 @@ inputs:
function main(y: bool) -> bool {
const a = 0i8;
return -a == 0i8 == y;
return (-a == 0i8) == y;
}

View File

@ -21,5 +21,5 @@ inputs:
*/
function main(a: u128, b: u128, c: bool) -> bool {
return a == b == c;
return (a == b) == c;
}

View File

@ -13,5 +13,5 @@ inputs:
*/
function main(a: u128, b: u128, c: bool) -> bool {
return a != b == c;
return (a != b) == c;
}

View File

@ -21,5 +21,5 @@ inputs:
*/
function main(a: u16, b: u16, c: bool) -> bool {
return a == b == c;
return (a == b) == c;
}

View File

@ -13,5 +13,5 @@ inputs:
*/
function main(a: u16, b: u16, c: bool) -> bool {
return a != b == c;
return (a != b) == c;
}

View File

@ -21,5 +21,5 @@ inputs:
*/
function main(a: u32, b: u32, c: bool) -> bool {
return a == b == c;
return (a == b) == c;
}

View File

@ -13,5 +13,5 @@ inputs:
*/
function main(a: u32, b: u32, c: bool) -> bool {
return a != b == c;
return (a != b) == c;
}

View File

@ -21,5 +21,5 @@ inputs:
*/
function main(a: u64, b: u64, c: bool) -> bool {
return a == b == c;
return (a == b) == c;
}

View File

@ -13,5 +13,5 @@ inputs:
*/
function main(a: u64, b: u64, c: bool) -> bool {
return a != b == c;
return (a != b) == c;
}

View File

@ -21,5 +21,5 @@ inputs:
*/
function main(a: u8, b: u8, c: bool) -> bool {
return a == b == c;
return (a == b) == c;
}

View File

@ -13,5 +13,5 @@ inputs:
*/
function main(a: u8, b: u8, c: bool) -> bool {
return a != b == c;
return (a != b) == c;
}

View File

@ -8,5 +8,5 @@ function main(y: bool) -> bool {
let a = [1u32];
a[0] = 0;
return a[0] == 0u32 == y;
return (a[0] == 0u32) == y;
}

Some files were not shown because too many files have changed in this diff Show More