mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +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,4 +1,5 @@
|
|||
use log::{debug, info};
|
||||
use roc_fmt::annotation::MigrationFlags;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use bumpalo::Bump;
|
||||
|
@ -92,7 +93,8 @@ impl DocInfo {
|
|||
let arena = &Bump::new();
|
||||
|
||||
let ast = Ast::parse(arena, source).ok()?;
|
||||
let fmt = ast.fmt();
|
||||
let flags = MigrationFlags::new(false);
|
||||
let fmt = ast.fmt(&flags);
|
||||
|
||||
if source == fmt.as_str() {
|
||||
None
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use bumpalo::Bump;
|
||||
use roc_fmt::Buf;
|
||||
use roc_fmt::{annotation::MigrationFlags, Buf};
|
||||
use roc_parse::{
|
||||
ast::{Defs, Header, SpacesBefore},
|
||||
header::parse_module_defs,
|
||||
|
@ -40,12 +40,12 @@ impl<'a> Ast<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn fmt(&self) -> FormattedAst<'a> {
|
||||
pub fn fmt(&self, flags: &MigrationFlags) -> FormattedAst<'a> {
|
||||
let mut buf = Buf::new_in(self.arena);
|
||||
|
||||
roc_fmt::header::fmt_header(&mut buf, &self.module);
|
||||
roc_fmt::header::fmt_header(&mut buf, &self.module, flags);
|
||||
|
||||
roc_fmt::def::fmt_defs(&mut buf, &self.defs, 0);
|
||||
roc_fmt::def::fmt_defs(&mut buf, &self.defs, flags, 0);
|
||||
|
||||
buf.fmt_end_of_file();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue