gazayas / masamune-ast

A covenience wrapper around Prism, a Ruby source code parser
MIT License
13 stars 1 forks source link

Raise error in AST constructor when `@tree` is `nil` #44

Open gazayas opened 1 year ago

gazayas commented 1 year ago

No error is raised when the syntax in the source code passed to Ripper.sexp is incorrect:

Ripper.sexp("1 +")
#=> nil

We should actually be getting this syntax error:

syntax error, unexpected end-of-input
gazayas commented 1 year ago

It can be confusing when trying to search for things with Masamune, so it would be better to just raise an error from the get go

"hello""

Raises this error:

unterminated string meets end of file
"hello""

Masamune currently creates an object without a problem and performs methods like strings without being aware that the original code is faulty.

irb(main):001:0> require "masamune"
=> true
irb(main):002:0> Masamune::AbstractSyntaxTree.new("\"hello\"\"").strings
=> []
irb(main):003:0> Masamune::AbstractSyntaxTree.new("\"hello\"\"").tree
=> nil