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

Support underscore in variable names #6

Closed
wants to merge 1 commit into from

Conversation

johshoff
Copy link

@johshoff johshoff commented Jan 8, 2017

Implement a function to grab a rust identifier. This is more proof of concept than ultimate solution.

I tried using macros, but without succeeding. Along the lines of take_while!(is_identifier_character). There might also be solutions using nom's regexps. This solution is more or less lifted from nom's implementation of alphanumeric. They probably implemented it in rust for a reason. Not sure if it's for speed or if macros weren't sufficient for them either.

Also, implementation aside, this does not actually correctly implement a correct rust identifier parser. That is a lot more complicated:https://doc.rust-lang.org/reference.html#identifiers (which is even disputed)

@maghoff
Copy link
Owner

maghoff commented Jan 9, 2017

Pertaining to issue #3

@maghoff
Copy link
Owner

maghoff commented Jan 9, 2017

syn is a crate that implements parsing of rust code with nom. If we would be able to reuse the identifier parser from syn, that would be perfect. A cursory look seems to indicate that they do not publicly export the identifier nom parser, but they do export one with a slightly different interface: parse_ident.

@maghoff
Copy link
Owner

maghoff commented Jan 9, 2017

In the meantime, I might merge this just to get support for underscore.

}
}
IResult::Done(input.slice(input_length..), input)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is written with two-space indents. Mind converting to four-space to match the surrounding code?

@maghoff
Copy link
Owner

maghoff commented Jan 9, 2017

I have fixed the travis config. I think you need to rebase on top of master for the inline travis check to pass.

@maghoff
Copy link
Owner

maghoff commented Feb 3, 2017

I fixed this by completely rewriting the parser, incidentally using syn to verify the identifier names

@maghoff maghoff closed this Feb 3, 2017
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.

2 participants