mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Fix some fmt stuff
This commit is contained in:
parent
74c0bdfd5a
commit
7682e09b0a
9 changed files with 163 additions and 48 deletions
|
@ -88,10 +88,34 @@ pub struct WhenPattern<'a> {
|
|||
pub enum StrSegment<'a> {
|
||||
Plaintext(&'a str), // e.g. "foo"
|
||||
Unicode(Loc<&'a str>), // e.g. "00A0" in "\u(00A0)"
|
||||
EscapedChar(char), // e.g. '\n' in "Hello!\n"
|
||||
EscapedChar(EscapedChar), // e.g. '\n' in "Hello!\n"
|
||||
Interpolated(Loc<&'a Expr<'a>>), // e.g. (name) in "Hi, \(name)!"
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum EscapedChar {
|
||||
Newline, // \n
|
||||
Tab, // \t
|
||||
Quote, // \"
|
||||
Backslash, // \\
|
||||
CarriageReturn, // \r
|
||||
}
|
||||
|
||||
impl EscapedChar {
|
||||
/// Returns the char that would have been originally parsed to
|
||||
pub fn to_parsed_char(&self) -> char {
|
||||
use EscapedChar::*;
|
||||
|
||||
match self {
|
||||
Backslash => '\\',
|
||||
Quote => '"',
|
||||
CarriageReturn => 'r',
|
||||
Tab => 't',
|
||||
Newline => 'n',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum StrLiteral<'a> {
|
||||
/// The most common case: a plain string with no escapes or interpolations
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::ast::{Attempting, StrLiteral, StrSegment};
|
||||
use crate::ast::{Attempting, EscapedChar, StrLiteral, StrSegment};
|
||||
use crate::expr;
|
||||
use crate::parser::{
|
||||
allocated, ascii_char, ascii_hex_digits, loc, parse_utf8, unexpected, unexpected_eof,
|
||||
|
@ -201,19 +201,19 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>> {
|
|||
state = new_state;
|
||||
}
|
||||
Some(b'\\') => {
|
||||
escaped_char!('\\');
|
||||
escaped_char!(EscapedChar::Backslash);
|
||||
}
|
||||
Some(b'"') => {
|
||||
escaped_char!('"');
|
||||
escaped_char!(EscapedChar::Quote);
|
||||
}
|
||||
Some(b'r') => {
|
||||
escaped_char!('\r');
|
||||
escaped_char!(EscapedChar::CarriageReturn);
|
||||
}
|
||||
Some(b't') => {
|
||||
escaped_char!('\t');
|
||||
escaped_char!(EscapedChar::Tab);
|
||||
}
|
||||
Some(b'n') => {
|
||||
escaped_char!('\n');
|
||||
escaped_char!(EscapedChar::Newline);
|
||||
}
|
||||
_ => {
|
||||
// Invalid escape! A backslash must be followed
|
||||
|
@ -273,13 +273,13 @@ where
|
|||
let line_bytes = &state.bytes[line_start..(parsed_chars - 3)];
|
||||
|
||||
return match parse_utf8(line_bytes) {
|
||||
Ok(_line) => {
|
||||
Ok(line) => {
|
||||
// state = state.advance_without_indenting(parsed_chars)?;
|
||||
|
||||
// lines.push(line);
|
||||
|
||||
// Ok((StrLiteral::Block(lines.into_bump_slice()), state))
|
||||
todo!("TODO finish making block strings accept escapes");
|
||||
todo!("finsih this");
|
||||
}
|
||||
Err(reason) => state.fail(reason),
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue