This is an archive of the discontinued LLVM Phabricator instance.

Add parseBareIdentifier to AsmParser
AbandonedPublic

Authored by j2kun on Jul 26 2023, 11:20 AM.

Diff Detail

Event Timeline

j2kun created this revision.Jul 26 2023, 11:20 AM
Herald added a project: Restricted Project. · View Herald Transcript
j2kun requested review of this revision.Jul 26 2023, 11:20 AM
j2kun updated this revision to Diff 544453.Jul 26 2023, 11:25 AM

Removed the parseCaret after determining I can't make it work

j2kun updated this revision to Diff 544454.Jul 26 2023, 11:27 AM

Revert ParserTest.cpp formatting change

j2kun updated this revision to Diff 544455.Jul 26 2023, 11:30 AM
j2kun retitled this revision from Add parseBareIdentifier to Add parseBareIdentifier to AsmParser.

Still getting the hang of the arc CLI tool, sorry for the noise

j2kun updated this revision to Diff 544457.Jul 26 2023, 11:31 AM

Remove caret token def

j2kun updated this revision to Diff 544495.Jul 26 2023, 1:34 PM

Add optional variant

rriddle requested changes to this revision.EditedJul 27 2023, 2:53 PM

I'm not really sure we need to expose this, why does parseKeyword not work for you?

This revision now requires changes to proceed.Jul 27 2023, 2:53 PM
makslevental accepted this revision.Jul 27 2023, 2:54 PM

Seem eminently reasonable to me.

j2kun added a comment.Jul 27 2023, 3:09 PM

I'm not really sure we need to expose this, why does parseKeyword not work for you?

My mistake. I thought that parseKeyword only included reserved words as defined by TOK_KEYWORD, but it includes bare identifiers as well. I'll make sure that works for my needs and then abandon this patch if so.

I'm not really sure we need to expose this, why does parseKeyword not work for you?

My mistake. I thought that parseKeyword only included reserved words as defined by TOK_KEYWORD, but it includes bare identifiers as well. I'll make sure that works for my needs and then abandon this patch if so.

Yeah, likely chose the wrong name a long time ago, but there is a separation between the lexer and what's exposed in the public API (we try not to expose many "lexer" specific things, like what is a keyword or bare identifier -> they are all keywords)

j2kun added a comment.EditedJul 27 2023, 3:34 PM

Ah yes, now I see why parseKeyword isn't sufficient. I would like to have the bare_identifier be arbitrary, similar to how AffineMap allows for an arbitrary variable name.

The use case is for a polynomial dialect. I would like to have an attribute polynomial like #poly.polynomial<1 + x**1024> (note I can't use caret for the exponentiation op because it's handled specially in the lexer), but without requiring the specific variable name x. I suppose that not forcing the user to use x is a nice-to-have, but that's the discrepancy here.

rriddle added a comment.EditedJul 27 2023, 3:36 PM

Ah yes, now I see why parseKeyword isn't sufficient. I would like to have the bare_identifier be arbitrary, similar to how AffineMap allows for an arbitrary variable name.

The use case is for a polynomial dialect. I would like to have an attribute polynomial like #poly.polynomial<1 + x^1024>, but without requiring the specific variable name x. I suppose that not forcing the user to use x is a nice-to-have, but that's the discrepancy here.

What do you mean by arbitrary? There are several overloads, one takes a StringRef (i.e. an expected keyword), and one takes a StringRef * that parses any keyword.

one takes a StringRef * that parses any keyword.

That was the trick, thanks! Abandoning this revision

j2kun abandoned this revision.Jul 28 2023, 11:15 AM