-
Notifications
You must be signed in to change notification settings - Fork 82
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
Parse numbers in Alex's parser, not tokenizer #200
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
-- Issue #197 | ||
-- reported 2022-01-21 by https://github.com/Commelina | ||
-- fixed 2022-01-23 by Andreas Abel & John Ericson | ||
-- | ||
-- Problem was: | ||
-- Surface syntax regressed and could no longer handle character strings | ||
-- that looked like numbers. | ||
|
||
module Main (main) where | ||
|
||
import System.Exit | ||
} | ||
|
||
%wrapper "posn" | ||
%token "Token" | ||
|
||
@iec60559suffix = (32|64|128)[x]? | ||
@any = [0-9]+[x]? | ||
|
||
:- | ||
|
||
$white+ ; | ||
@iec60559suffix { \ _ -> Good } | ||
@any { \ _ -> Bad } | ||
|
||
{ | ||
data Token = Good String | Bad String | ||
deriving (Eq, Show) | ||
|
||
input = "32 32x 99 99x 128x" | ||
expected_result = [Good "32", Good "32x", Bad "99", Bad "99x", Good "128x"] | ||
|
||
main :: IO () | ||
main | ||
| result == expected_result = do | ||
exitWith ExitSuccess | ||
| otherwise = do | ||
print result | ||
exitFailure | ||
where | ||
result = alexScanTokens input | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
$1 * 10 + $2
.Is this what breaks #141: https://github.com/simonmar/alex/runs/4911840593?check_suite_focus=true#step:22:116 ?
Anyway, fixed this in #201.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yes, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I realized another problem with recognizing numbers in the parser.
natnum
happily accepts digit separated by spaces, like1 4
inr{1 4,1 4}
is happily accepted as 14 repetitions ofr
now.I do not think we want to allow that.
How about a middle ground, recognizing numbers in the scanner, but not storing them as
Integer
, but asString
, so we can get them back into character sequences. I'll play with this solution in #199 a bit...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use lexer states to only lex numerals inside the multiplicity-brackets
{nnn,mmm}
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, and both of those look interesting to me.