Explains syntax errors based on their source

example:

source = "def foo; puts 'lol'" # Note missing end
explain ExplainSyntax.new(
  code_lines: CodeLine.from_source(source)
).call
explain.errors.first
# => "Unmatched keyword, missing `end' ?"

When the error cannot be determined by lexical counting then ripper is run against the input and the raw ripper errors returned.

Example:

source = "1 * " # Note missing a second number
explain ExplainSyntax.new(
  code_lines: CodeLine.from_source(source)
).call
explain.errors.first
# => "syntax error, unexpected end-of-input"
Constants
No documentation available
Class Methods
No documentation available
Instance Methods
No documentation available

Returns an array of syntax error messages

If no missing pairs are found it falls back on the original ripper error messages

Returns an array of missing elements

For example this:

ExplainSyntax.new(code_lines: lines).missing
# => ["}"]

Would indicate that the source is missing a ‘}` character in the source code

Converts a missing string to an human understandable explanation.

Example:

explain.why("}")
# => "Unmatched `{', missing `}' ?"