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:
Anthony Bullard 2024-11-20 09:00:57 -06:00
parent d7825428df
commit a2083cec30
No known key found for this signature in database
31 changed files with 1214 additions and 460 deletions

View file

@ -6019,25 +6019,6 @@ All branches in an `if` must have the same type!
"
);
test_report!(
closure_underscore_ident,
indoc!(
r"
\the_answer -> 100
"
),
@r"
NAMING PROBLEM in /code/proj/Main.roc
I am trying to parse an identifier here:
4 \the_answer -> 100
^
Underscores are not allowed in identifiers. Use camelCase instead!
"
);
test_report!(
#[ignore]
double_binop,
@ -10697,26 +10678,26 @@ All branches in an `if` must have the same type!
);
test_report!(
underscore_in_middle_of_identifier,
call_with_declared_identifier_with_more_than_one_underscore,
indoc!(
r"
f = \x, y, z -> x + y + z
f__arg = \x, y, z -> x + y + z
\a, _b -> f a var_name 1
\a, b -> f__arg a b 1
"
),
|golden| pretty_assertions::assert_eq!(
golden,
indoc!(
r"
SYNTAX PROBLEM in /code/proj/Main.roc
r"── NAMING PROBLEM in /code/proj/Main.roc ───────────────────────────────────────
Underscores are not allowed in identifier names:
I am trying to parse an identifier here:
6 \a, _b -> f a var_name 1
^^^^^^^^
4 f__arg = \x, y, z -> x + y + z
^^^^^^
I recommend using camelCase. It's the standard style in Roc code!
While snake case is allowed here, only a single consecutive underscore
should be used.
"
),
)