Skip to content

Commit

Permalink
[Aleo ins parser] Fix in struct/array parsing.
Browse files Browse the repository at this point in the history
This is fairly minor, but the current parser disallows whitespace between a
component of a struct or an array and the comma that separates it from the next
component. For instance, this is currently disallowed:
```
{x: 0u8 , y: 1u8}
```
because of the space between `0u8` and `,`. Regardless of whether it is good or
bad style to put a space there, other parts of the Aleo instruction syntax allow
whitespace just before separators like commas or colons. Thus, this PR allows
that.
  • Loading branch information
acoglio committed Sep 28, 2023
1 parent 38eb9f0 commit a1dac9b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions console/program/src/data/plaintext/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ impl<N: Network> Parser for Plaintext<N> {
// Parse the "{" from the string.
let (string, _) = tag("{")(string)?;
// Parse the members.
let (string, members) = map_res(separated_list1(tag(","), parse_pair), |members: Vec<_>| {
let (string, members) =
map_res(separated_list1(pair(Sanitizer::parse_whitespaces,tag(",")), parse_pair), |members: Vec<_>| {
// Ensure the members has no duplicate names.
if has_duplicates(members.iter().map(|(name, ..)| name)) {
return Err(error("Duplicate member in struct"));
Expand All @@ -67,7 +68,7 @@ impl<N: Network> Parser for Plaintext<N> {
// Parse the "[" from the string.
let (string, _) = tag("[")(string)?;
// Parse the members.
let (string, members) = separated_list1(tag(","), Plaintext::parse)(string)?;
let (string, members) = separated_list1(pair(Sanitizer::parse_whitespaces,tag(",")), Plaintext::parse)(string)?;
// Parse the whitespace and comments from the string.
let (string, _) = Sanitizer::parse(string)?;
// Parse the ']' from the string.
Expand Down

0 comments on commit a1dac9b

Please sign in to comment.