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
|
|
@ -3,7 +3,7 @@ use std::fmt;
|
|||
use crate::builtin::Builtin;
|
||||
use crate::span::{HasSpan, Span};
|
||||
|
||||
use super::{Expr, Ident, Space};
|
||||
use super::{Expr, Ident, Separated, Space};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum NumLitStr {
|
||||
|
|
@ -126,11 +126,13 @@ impl HasSpan for TableLitElem {
|
|||
}
|
||||
|
||||
/// `'{ a, foo: b }`
|
||||
///
|
||||
/// Structure: `'{ s0 elems s1 }`
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TableLit {
|
||||
pub elems: Vec<(Space, TableLitElem, Space)>,
|
||||
/// `Some` if there is a trailing comma, `None` otherwise.
|
||||
pub trailing_comma: Option<Space>,
|
||||
pub s0: Space,
|
||||
pub elems: Separated<TableLitElem, (Space, Space), Space>,
|
||||
pub s1: Space,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue