Merge branch 'trunk' of github.com:rtfeldman/roc into editor-let-value

This commit is contained in:
Anton-4 2021-08-21 12:05:59 +02:00
commit 169520f956
301 changed files with 15511 additions and 10303 deletions

View file

@ -1,6 +1,6 @@
use crate::ast::{AssignedField, CommentOrNewline, Def, Expr, Pattern, Spaceable, TypeAnnotation};
use crate::blankspace::{space0_after_e, space0_around_ee, space0_before_e, space0_e};
use crate::ident::{lowercase_ident, parse_ident_help, Ident};
use crate::ident::{lowercase_ident, parse_ident, Ident};
use crate::keyword;
use crate::parser::{
self, backtrackable, optional, sep_by1, sep_by1_e, specialize, specialize_ref, then,
@ -252,7 +252,7 @@ fn underscore_expression<'a>() -> impl Parser<'a, Expr<'a>, EExpr<'a>> {
match output {
Some(name) => Ok((MadeProgress, Expr::Underscore(name), final_state)),
None => Ok((MadeProgress, Expr::Underscore(&""), final_state)),
None => Ok((MadeProgress, Expr::Underscore(""), final_state)),
}
}
}
@ -2097,7 +2097,7 @@ fn if_expr_help<'a>(
/// 5. A reserved keyword (e.g. `if ` or `case `), meaning we should do something else.
fn assign_or_destructure_identifier<'a>() -> impl Parser<'a, Ident<'a>, EExpr<'a>> {
crate::ident::parse_ident_help
crate::ident::parse_ident
}
#[allow(dead_code)]
@ -2238,7 +2238,7 @@ fn record_field_help<'a>(
fn record_updateable_identifier<'a>() -> impl Parser<'a, Expr<'a>, ERecord<'a>> {
specialize(
|_, r, c| ERecord::Updateable(r, c),
map_with_arena!(parse_ident_help, ident_to_expr),
map_with_arena!(parse_ident, ident_to_expr),
)
}

View file

@ -7,7 +7,6 @@ use crate::parser::{
};
use crate::string_literal;
use bumpalo::collections::Vec;
use inlinable_string::InlinableString;
use roc_region::all::Loc;
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
@ -48,12 +47,6 @@ impl<'a> From<ModuleName<'a>> for &'a str {
}
}
impl<'a> From<ModuleName<'a>> for InlinableString {
fn from(name: ModuleName<'a>) -> InlinableString {
name.0.into()
}
}
impl<'a> ModuleName<'a> {
pub fn new(name: &'a str) -> Self {
ModuleName(name)

View file

@ -138,13 +138,10 @@ macro_rules! advance_state {
};
}
pub fn parse_ident_help<'a>(
arena: &'a Bump,
state: State<'a>,
) -> ParseResult<'a, Ident<'a>, EExpr<'a>> {
pub fn parse_ident<'a>(arena: &'a Bump, state: State<'a>) -> ParseResult<'a, Ident<'a>, EExpr<'a>> {
let initial = state;
match parse_ident_help_help(arena, state) {
match parse_ident_help(arena, state) {
Ok((progress, ident, state)) => {
if let Ident::Access { module_name, parts } = ident {
if module_name.is_empty() {
@ -526,7 +523,7 @@ fn chomp_access_chain<'a>(buffer: &'a [u8], parts: &mut Vec<'a, &'a str>) -> Res
}
}
fn parse_ident_help_help<'a>(
fn parse_ident_help<'a>(
arena: &'a Bump,
mut state: State<'a>,
) -> ParseResult<'a, Ident<'a>, BadIdent> {

View file

@ -15,7 +15,7 @@ pub fn positive_number_literal<'a>() -> impl Parser<'a, NumLiteral<'a>, Number>
move |_arena, state: State<'a>| {
match state.bytes.get(0) {
Some(first_byte) if (*first_byte as char).is_ascii_digit() => {
parse_number_base(false, &state.bytes, state)
parse_number_base(false, state.bytes, state)
}
_ => {
// this is not a number at all
@ -33,7 +33,7 @@ pub fn number_literal<'a>() -> impl Parser<'a, NumLiteral<'a>, Number> {
parse_number_base(true, &state.bytes[1..], state)
}
Some(first_byte) if (*first_byte as char).is_ascii_digit() => {
parse_number_base(false, &state.bytes, state)
parse_number_base(false, state.bytes, state)
}
_ => {
// this is not a number at all

View file

@ -436,8 +436,8 @@ pub enum Number {
pub enum EString<'a> {
Open(Row, Col),
CodePointOpen(Row, Col),
CodePointEnd(Row, Col),
CodePtOpen(Row, Col),
CodePtEnd(Row, Col),
Space(BadInputError, Row, Col),
EndlessSingle(Row, Col),

View file

@ -1,6 +1,6 @@
use crate::ast::Pattern;
use crate::blankspace::{space0_around_ee, space0_before_e, space0_e};
use crate::ident::{lowercase_ident, parse_ident_help, Ident};
use crate::ident::{lowercase_ident, parse_ident, Ident};
use crate::parser::Progress::{self, *};
use crate::parser::{
backtrackable, optional, specialize, specialize_ref, word1, EPattern, PInParens, PRecord,
@ -172,8 +172,7 @@ fn loc_ident_pattern_help<'a>(
let original_state = state;
let (_, loc_ident, state) =
specialize(|_, r, c| EPattern::Start(r, c), loc!(parse_ident_help))
.parse(arena, state)?;
specialize(|_, r, c| EPattern::Start(r, c), loc!(parse_ident)).parse(arena, state)?;
match loc_ident.value {
Ident::GlobalTag(tag) => {
@ -259,7 +258,7 @@ fn loc_ident_pattern_help<'a>(
Located {
region: loc_ident.region,
value: Pattern::Malformed(
String::from_str_in(&malformed_str, &arena).into_bump_str(),
String::from_str_in(&malformed_str, arena).into_bump_str(),
),
},
state,
@ -299,7 +298,7 @@ fn underscore_pattern_help<'a>() -> impl Parser<'a, Pattern<'a>, EPattern<'a>> {
match output {
Some(name) => Ok((MadeProgress, Pattern::Underscore(name), final_state)),
None => Ok((MadeProgress, Pattern::Underscore(&""), final_state)),
None => Ok((MadeProgress, Pattern::Underscore(""), final_state)),
}
}
}

View file

@ -6,10 +6,10 @@ pub type Problems = Vec<Loc<Problem>>;
pub enum Problem {
// UNICODE CODE POINT
/// TODO Invalid hex code - Unicode code points must be specified using hexadecimal characters (the numbers 0-9 and letters A-F)
NonHexCharsInUnicodeCodePoint,
NonHexCharsInUnicodeCodePt,
/// TODO Invalid Unicode code point. It must be no more than \\u{10FFFF}.
UnicodeCodePointTooLarge,
InvalidUnicodeCodePoint,
UnicodeCodePtTooLarge,
InvalidUnicodeCodePt,
MalformedEscapedUnicode,
NoUnicodeDigits,

View file

@ -18,7 +18,7 @@ fn ascii_hex_digits<'a>() -> impl Parser<'a, &'a str, EString<'a>> {
// We didn't find any hex digits!
return Err((
NoProgress,
EString::CodePointEnd(state.line, state.column),
EString::CodePtEnd(state.line, state.column),
state,
));
} else {
@ -32,7 +32,7 @@ fn ascii_hex_digits<'a>() -> impl Parser<'a, &'a str, EString<'a>> {
Err((
NoProgress,
EString::CodePointEnd(state.line, state.column),
EString::CodePtEnd(state.line, state.column),
state,
))
}
@ -257,9 +257,9 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, EString<'a>> {
// give a canonicalization error if the digits form
// an invalid unicode code point.
let (_progress, loc_digits, new_state) = between!(
word1(b'(', EString::CodePointOpen),
word1(b'(', EString::CodePtOpen),
loc(ascii_hex_digits()),
word1(b')', EString::CodePointEnd)
word1(b')', EString::CodePtEnd)
)
.parse(arena, state)?;

View file

@ -303,12 +303,12 @@ fn applied_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>, Type
),
|(ctor, args): (TypeAnnotation<'a>, Vec<'a, Located<TypeAnnotation<'a>>>)| {
match &ctor {
TypeAnnotation::Apply(ref module_name, ref name, _) => {
TypeAnnotation::Apply(module_name, name, _) => {
if args.is_empty() {
// ctor is already an Apply with no args, so return it directly.
ctor
} else {
TypeAnnotation::Apply(*module_name, *name, args.into_bump_slice())
TypeAnnotation::Apply(module_name, name, args.into_bump_slice())
}
}
TypeAnnotation::Malformed(_) => ctor,
@ -371,7 +371,7 @@ fn expression<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>
.parse(arena, state)?;
// prepare arguments
let mut arguments = Vec::with_capacity_in(rest.len() + 1, &arena);
let mut arguments = Vec::with_capacity_in(rest.len() + 1, arena);
arguments.push(first);
arguments.extend(rest);
let output = arena.alloc(arguments);