Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ruby-syntax-tree/syntax_tree
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.6.2
Choose a base ref
...
head repository: ruby-syntax-tree/syntax_tree
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.6.3
Choose a head ref
  • 3 commits
  • 5 files changed
  • 2 contributors

Commits on Oct 11, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    vinistock Vinicius Stock
    Copy the full SHA
    666e7c8 View commit details
  2. Merge pull request #167 from vinistock/vs/raise_parse_error_on_else_m…

    …issing_end
    
    Raise ParseError on missing end for else statement
    kddnewton authored Oct 11, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3e07be7 View commit details
  3. Bump to v3.6.3

    kddnewton committed Oct 11, 2022
    Copy the full SHA
    cb72efc View commit details
Showing with 25 additions and 3 deletions.
  1. +8 −1 CHANGELOG.md
  2. +1 −1 Gemfile.lock
  3. +5 −0 lib/syntax_tree/parser.rb
  4. +1 −1 lib/syntax_tree/version.rb
  5. +10 −0 test/parser_test.rb
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

## [3.6.3] - 2022-10-11

### Changed

- [#167](https://github.com/ruby-syntax-tree/syntax_tree/pull/167) - Change the error encountered when an `else` node does not have an associated `end` token to be a parse error.

## [3.6.2] - 2022-10-04

### Changed
@@ -364,7 +370,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

- 🎉 Initial release! 🎉

[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.2...HEAD
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.3...HEAD
[3.6.3]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.2...v3.6.3
[3.6.2]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.1...v3.6.2
[3.6.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.0...v3.6.1
[3.6.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.5.0...v3.6.0
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
syntax_tree (3.6.2)
syntax_tree (3.6.3)
prettier_print

GEM
5 changes: 5 additions & 0 deletions lib/syntax_tree/parser.rb
Original file line number Diff line number Diff line change
@@ -1327,6 +1327,11 @@ def on_else(statements)
token.is_a?(Kw) && %w[end ensure].include?(token.value)
end

if index.nil?
message = "Cannot find expected else ending"
raise ParseError.new(message, *find_token_error(keyword.location))
end

node = tokens[index]
ending = node.value == "end" ? tokens.delete_at(index) : node

2 changes: 1 addition & 1 deletion lib/syntax_tree/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SyntaxTree
VERSION = "3.6.2"
VERSION = "3.6.3"
end
10 changes: 10 additions & 0 deletions test/parser_test.rb
Original file line number Diff line number Diff line change
@@ -55,5 +55,15 @@ def test_errors_on_missing_token_without_location
def test_handles_strings_with_non_terminated_embedded_expressions
assert_raises(Parser::ParseError) { SyntaxTree.parse('"#{"') }
end

def test_errors_on_else_missing_two_ends
assert_raises(Parser::ParseError) { SyntaxTree.parse(<<~RUBY) }
def foo
if something
else
call do
end
RUBY
end
end
end