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

[mlir][parser] Extend AsmParser with slash token and optional floats #11

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

andidr
Copy link
Collaborator

@andidr andidr commented Jan 30, 2025

The first commit adds a token for a forward slash to the token definition list and the methods to AsmParser::parseSlash() and AsmParser::parseOptionalSlash(), similar to other tokens used as
operators (e.g., star, plus, etc.). This allows implementations of attributes that contain arithmetic expressions to support an operator using a forward slash, e.g., a division.

The second commit adds a new method parseOptionalFloat to AsmParser that attempts to parse a floating point value. Unlike parseFloat, no errors are emitted and all tokens are put back if parsing fails.

This adds a token for a forward slash to the token definition list and
the methods to `AsmParser::parseSlash()` and
`AsmParser::parseOptionalSlash()`, similar to other tokens used as
operators (e.g., star, plus, etc.). This allows implementations of
attributes that contain arithmetic expressions to support an operator
using a forward slash, e.g., a division.
@andidr andidr force-pushed the andi/parser-extensions branch from 9b1128f to b920cd6 Compare January 30, 2025 13:44
@andidr andidr changed the title [mlir][parser] Add token type and parser methods for forward slashes [mlir][parser] Extend AsmParser for token slashes and optional floats Feb 4, 2025
@andidr andidr force-pushed the andi/parser-extensions branch from cea12f2 to ba0006e Compare February 4, 2025 14:35
@andidr andidr changed the title [mlir][parser] Extend AsmParser for token slashes and optional floats [mlir][parser] Extend AsmParser with slash token and optional floats Feb 4, 2025
andidr and others added 3 commits February 19, 2025 16:09
This adds a new method `parseOptionalFloat` to `AsmParser` that
attempts to parse a floating point value. Unlike `parseFloat`, no
errors are emitted and all tokens are put back if parsing fails.
The current detection logic will fail for containers with an overloaded
`push_back` member. This causes issues with types like `std::vector` and
`SmallVector<SomeNonTriviallyCopyableT>`, which have both
`push_back(const T&)` and `push_back(T&&)`.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D147101
…mParser

Add the methods `AsmParser::pushLexerPos()` and
`AsmParser::popLexerPos()` that allow parsing code to speculatively
parse portions of the input and to back off in case of a failure.
@andidr andidr force-pushed the andi/parser-extensions branch from 0c3e146 to 146ae26 Compare February 19, 2025 15:10
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