keyword in record field

This commit is contained in:
Folkert 2021-02-08 22:39:12 +01:00
parent 860aa6d194
commit 0ccf17007e
6 changed files with 144 additions and 57 deletions

View file

@ -1,7 +1,9 @@
use crate::ast::Attempting;
use crate::keyword;
use crate::parser::Progress::{self, *};
use crate::parser::{peek_utf8_char, unexpected, ParseResult, Parser, State, SyntaxError};
use crate::parser::{
backtrackable, peek_utf8_char, unexpected, ParseResult, Parser, State, SyntaxError,
};
use bumpalo::collections::string::String;
use bumpalo::collections::vec::Vec;
use bumpalo::Bump;
@ -383,7 +385,7 @@ where
/// * A record field, e.g. "email" in `.email` or in `email:`
/// * A named pattern match, e.g. "foo" in `foo =` or `foo ->` or `\foo ->`
pub fn lowercase_ident<'a>() -> impl Parser<'a, &'a str, SyntaxError<'a>> {
move |arena, state| {
move |arena, state: State<'a>| {
let (progress, ident, state) =
global_tag_or_ident(|first_char| first_char.is_lowercase()).parse(arena, state)?;

View file

@ -336,7 +336,7 @@ pub enum BadInputError {
pub fn bad_input_to_syntax_error<'a>(
bad_input: BadInputError,
row: Row,
col: Col,
_col: Col,
) -> SyntaxError<'a> {
use crate::parser::BadInputError::*;
match bad_input {
@ -407,21 +407,6 @@ pub enum ContextStack<'a> {
}
impl<'a> ContextStack<'a> {
fn into_vec(self) -> std::vec::Vec<ContextItem> {
let mut result = std::vec::Vec::new();
let mut next = &self;
while let ContextStack::Cons(item, rest) = next {
next = rest;
result.push(*item);
}
result.reverse();
result
}
pub fn uncons(&'a self) -> Option<(ContextItem, &'a Self)> {
match self {
ContextStack::Cons(item, rest) => Some((*item, rest)),
@ -458,7 +443,7 @@ pub struct ParseProblem<'a, T> {
}
pub fn fail<'a, T>() -> impl Parser<'a, T, SyntaxError<'a>> {
move |arena, state: State<'a>| Err((NoProgress, SyntaxError::ConditionFailed, state))
move |_arena, state: State<'a>| Err((NoProgress, SyntaxError::ConditionFailed, state))
}
pub trait Parser<'a, Output, Error> {
@ -505,7 +490,7 @@ where
let after_parse = state.clone();
match by.parse(arena, state) {
Ok((_, _, state)) => {
Ok((_, _, _state)) => {
Err((NoProgress, SyntaxError::ConditionFailed, original_state))
}
Err(_) => Ok((progress, answer, after_parse)),
@ -659,7 +644,7 @@ where
}
fn line_too_long_e<'a, TE, E>(
arena: &'a Bump,
_arena: &'a Bump,
state: State<'a>,
to_error: TE,
) -> (Progress, E, State<'a>)
@ -1307,6 +1292,7 @@ where
}
}
#[allow(dead_code)]
fn in_context<'a, AddContext, P1, P2, Start, A, X, Y>(
add_context: AddContext,
parser_start: P1,

View file

@ -241,7 +241,9 @@ macro_rules! record_type_field {
use $crate::parser::Either::*;
// You must have a field name, e.g. "email"
let (progress, loc_label, state) = loc!(lowercase_ident()).parse(arena, state).map_err(|(p, _, s)| (p, TRecord::Field(s.line, s.column), s))?;
let row = state.line;
let col = state.column;
let (progress, loc_label, state) = loc!(lowercase_ident()).parse(arena, state).map_err(|(p, _, s)| (p, TRecord::Field(row, col), s))?;
debug_assert_eq!(progress, MadeProgress);
let (_, spaces, state) =
@ -327,7 +329,6 @@ fn record_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>, Synta
#[inline(always)]
fn record_type_internal<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>, TRecord<'a>> {
use crate::type_annotation::TypeAnnotation::*;
type Fields<'a> = Vec<'a, Located<AssignedField<'a, TypeAnnotation<'a>>>>;
let field_term = move |a, s| match term(min_indent).parse(a, s) {
Ok(t) => Ok(t),