Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc(recipes/identifier): convert to greedy parser #1334

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sno2
Copy link

@sno2 sno2 commented Jul 1, 2021

Basically, the current recipe for identifier is greedy and likes to take everything that it can and silently stop if it sees something it doesn't like (i.e. whitespace). However, I think it would be a lot better to just make it check the entire string to be a valid identifier and just make use of the multispace1 or any other delimiters you want ((, ), ect.) surrounding the identifier when using it within a different parser (i.e. variable initialization as stated in the docs added). This should make it easier to use because I actually had a big bug that I didn't realize was there until later from the identifier saying it's valid when it's not because it requires you to check if the rest of the input (input, parsed) is empty.

Tests I used:

#[cfg(test)]
mod tests {
  	#[test]
	fn fn23() {
		function("let foo;").unwrap();
		function("let _asdf23;").unwrap();
		function("let 23asdf;").expect_err("Can't begin with numbers");
		function("let a\nnb;").expect_err("Can't have newlines");
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant