mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-19 12:35:07 +00:00
Parsing support for snake_case identifiers
In this initial commit, I have done the following: - Added unit tests to roc_parse's ident.rs file to cover at least the simplest Ident enum cases (Tag, OpaqueRef, and simple Access) - Added '_' as a valid "rest" character in both uppercase and lowercase identifier parts - Updated the test_syntax snapshots appropriately There is still a lot left to do here. Such as: - Do we want to allow multiple '_'s to parse successfully? - Handle qualified access - Handle accessor functions - Handle record update functions - Remove the UnderscoreInMiddle case from BadIdent - Write unit tests for Malformed Idents I am not a "Rustacean" by any means, but have been through the Book in years past. Any feedback on the way I wrote the tests or any other part of the implementation would be very appreciated.
This commit is contained in:
parent
d7825428df
commit
a2083cec30
31 changed files with 1214 additions and 460 deletions
|
@ -1,5 +1,5 @@
|
|||
use bumpalo::Bump;
|
||||
use roc_fmt::{annotation::Formattable, header::fmt_header};
|
||||
use roc_fmt::{annotation::Formattable, annotation::MigrationFlags, header::fmt_header};
|
||||
use roc_parse::{
|
||||
ast::{Defs, Expr, FullAst, Header, Malformed, SpacesBefore},
|
||||
header::parse_module_defs,
|
||||
|
@ -83,24 +83,25 @@ impl<'a> Output<'a> {
|
|||
pub fn format(&self) -> InputOwned {
|
||||
let arena = Bump::new();
|
||||
let mut buf = Buf::new_in(&arena);
|
||||
let flags = MigrationFlags::new(false);
|
||||
match self {
|
||||
Output::Header(header) => {
|
||||
fmt_header(&mut buf, header);
|
||||
fmt_header(&mut buf, header, &flags);
|
||||
buf.fmt_end_of_file();
|
||||
InputOwned::Header(buf.as_str().to_string())
|
||||
}
|
||||
Output::ModuleDefs(defs) => {
|
||||
defs.format(&mut buf, 0);
|
||||
defs.format(&mut buf, &flags, 0);
|
||||
buf.fmt_end_of_file();
|
||||
InputOwned::ModuleDefs(buf.as_str().to_string())
|
||||
}
|
||||
Output::Expr(expr) => {
|
||||
expr.format(&mut buf, 0);
|
||||
expr.format(&mut buf, &flags, 0);
|
||||
InputOwned::Expr(buf.as_str().to_string())
|
||||
}
|
||||
Output::Full(full) => {
|
||||
fmt_header(&mut buf, &full.header);
|
||||
full.defs.format(&mut buf, 0);
|
||||
fmt_header(&mut buf, &full.header, &flags);
|
||||
full.defs.format(&mut buf, &flags, 0);
|
||||
buf.fmt_end_of_file();
|
||||
InputOwned::Full(buf.as_str().to_string())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue