Handle things separated by things differently
I noticed that programs like '{} would parse correctly while '{ } would
expect an inner element. This was because the leading space was actually
part of the element parser, which is a violation of the (as of yet
unspoken) rule that parsers should not parse surrounding whitespace.
Because whitespace whas treated differently from everywhere else and
because this implementation was wrong, I decided to reimplement it,
abstracting the concept of things separated by other things with
optional trailing things. I did this in such a way that surrounding
whitespace is not touched.
This commit is contained in:
parent
407786b98c
commit
6533c9dcf7
10 changed files with 116 additions and 77 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use crate::span::{HasSpan, Span};
|
||||
|
||||
use super::{Expr, Space, TableLitElem};
|
||||
use super::{Expr, Separated, Space, TableLitElem};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Program {
|
||||
|
|
@ -12,12 +12,12 @@ pub enum Program {
|
|||
span: Span,
|
||||
},
|
||||
|
||||
/// Structure: `s0 module elems trailing_comma`
|
||||
/// Structure: `s0 module s1 elems s2`
|
||||
Module {
|
||||
s0: Space,
|
||||
elems: Vec<(Space, TableLitElem, Space)>,
|
||||
/// `Some` if there is a trailing comma, `None` otherwise.
|
||||
trailing_comma: Option<Space>,
|
||||
s1: Space,
|
||||
elems: Separated<TableLitElem, (Space, Space), Space>,
|
||||
s2: Space,
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue