This repository has been archived by the owner on Sep 8, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve lexing of ternaries that include symbols in Ruby lexer (rouge…
…-ruby#1476) Ruby's rules for how it parses ternaries are complicated. This is all the more the case if the ternary contains symbols. The current lexer uses a simple test to determine whether a colon demarcates the branches of the ternary: is the colon immediately followed by another colon? While this rule suffices for many cases, it causes ternaries including symbols to be lexed incorrectly. This commit replaces the simple rule with a rule for each of the following cases: - **Simple case**: The simple case is where there is whitespace following the colon being matched. - **Complex case**: The complex case is where there are no additional colons on that line (excluding colons in trailing comments) that follow the colon being matched. If either of the above cases apply, the colon is tokenised as `Punctuation` and the lexer moves to the `:expr_start` state. These rules have been tested with a number of complex ternaries involving colons and are lexed in a manner consistent with Ruby's parser. These test cases have been added to the visual sample.
- Loading branch information