-
Notifications
You must be signed in to change notification settings - Fork 165
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
Add end position information to BNFC'Position #463
Open
aabounegm
wants to merge
3
commits into
BNFC:master
Choose a base branch
from
aabounegm:position-range
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+91
−39
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,8 +136,8 @@ restOfAlex tokenText cf = concat | |
] | ||
, [ "{" | ||
, "-- | Create a token with position." | ||
, "tok :: (" ++ stringType ++ " -> Tok) -> (Posn -> " ++ stringType ++ " -> Token)" | ||
, "tok f p = PT p . f" | ||
, "tok :: (" ++ stringType ++ " -> Tok) -> (Posn -> Int -> " ++ stringType ++ " -> Token)" | ||
, "tok f p l = PT p l . f" | ||
, "" | ||
, "-- | Token without position." | ||
, "data Tok" | ||
|
@@ -173,7 +173,7 @@ restOfAlex tokenText cf = concat | |
, "" | ||
, "-- | Token with position." | ||
, "data Token" | ||
, " = PT Posn Tok" | ||
, " = PT Posn Int Tok" | ||
, " | Err Posn" | ||
, " deriving (Eq, Show, Ord)" | ||
, "" | ||
|
@@ -188,33 +188,49 @@ restOfAlex tokenText cf = concat | |
, "" | ||
, "-- | Get the position of a token." | ||
, "tokenPosn :: Token -> Posn" | ||
, "tokenPosn (PT p _) = p" | ||
, "tokenPosn (Err p) = p" | ||
, "tokenPosn (PT posn _len _tok) = posn" | ||
, "tokenPosn (Err posn) = posn" | ||
, "" | ||
, "-- | Get line and column of a token." | ||
, "-- | Get the length of a token." | ||
, "tokenLen :: Token -> Int" | ||
, "tokenLen (PT _posn len _tok) = len" | ||
, "tokenLen (Err _) = 0" | ||
, "" | ||
, "-- | Get start line and column of a token." | ||
, "tokenLineCol :: Token -> (Int, Int)" | ||
, "tokenLineCol = posLineCol . tokenPosn" | ||
, "" | ||
, "-- | Get end line and column of a token." | ||
, "tokenLineColEnd :: Token -> (Int, Int)" | ||
, "tokenLineColEnd t = (l, c + n)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if a token spans several lines? Note that the user can define their own tokens that may contain newline characters. |
||
, " where" | ||
, " (l, c) = tokenLineCol t" | ||
, " n = tokenLen t" | ||
, "" | ||
, "-- | Get line and column for both start and end of a token." | ||
, "tokenSpan :: Token -> ((Int, Int), (Int, Int))" | ||
, "tokenSpan t = (tokenLineCol t, tokenLineColEnd t)" | ||
, "" | ||
, "-- | Get line and column of a position." | ||
, "posLineCol :: Posn -> (Int, Int)" | ||
, "posLineCol (Pn _ l c) = (l,c)" | ||
, "" | ||
, "-- | Convert a token into \"position token\" form." | ||
, "mkPosToken :: Token -> ((Int, Int), " ++ stringType ++ ")" | ||
, "mkPosToken t = (tokenLineCol t, tokenText t)" | ||
, "mkPosToken :: Token -> (((Int, Int), Int), " ++ stringType ++ ")" | ||
, "mkPosToken t = ((tokenLineCol t, tokenLen t), tokenText t)" | ||
, "" | ||
, "-- | Convert a token to its text." | ||
, "tokenText :: Token -> " ++ stringType | ||
, "tokenText t = case t of" | ||
, " PT _ (TS s _) -> s" | ||
, " PT _ (TL s) -> " ++ applyP stringPack "show s" | ||
, " PT _ (TI s) -> s" | ||
, " PT _ (TV s) -> s" | ||
, " PT _ (TD s) -> s" | ||
, " PT _ (TC s) -> s" | ||
, " PT _ _ (TS s _) -> s" | ||
, " PT _ _ (TL s) -> " ++ applyP stringPack "show s" | ||
, " PT _ _ (TI s) -> s" | ||
, " PT _ _ (TV s) -> s" | ||
, " PT _ _ (TD s) -> s" | ||
, " PT _ _ (TC s) -> s" | ||
, " Err _ -> " ++ apply stringPack "\"#error\"" | ||
] | ||
, [ " PT _ (T_" ++ name ++ " s) -> s" | name <- tokenNames cf ] | ||
, [ " PT _ _ (T_" ++ name ++ " s) -> s" | name <- tokenNames cf ] | ||
, [ "" | ||
, "-- | Convert a token to a string." | ||
, "prToken :: Token -> String" | ||
|
@@ -295,7 +311,7 @@ restOfAlex tokenText cf = concat | |
, " AlexEOF -> []" | ||
, " AlexError (pos, _, _, _) -> [Err pos]" | ||
, " AlexSkip inp' len -> go inp'" | ||
, " AlexToken inp' len act -> act pos (" ++ stringTake ++ " len str) : (go inp')" | ||
, " AlexToken inp' len act -> act pos len (" ++ stringTake ++ " len str) : (go inp')" | ||
, "" | ||
, "alexGetByte :: AlexInput -> Maybe (Byte,AlexInput)" | ||
, "alexGetByte (p, c, (b:bs), s) = Just (b, (p, c, bs, s))" | ||
|
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
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.
These functions should only be imported when used (currently, that would be under condition
functor
), otherwise compilation generates warnings with-Wall
.