Skip to content

Instantly share code, notes, and snippets.

@zenspider
Created November 12, 2025 00:37
Show Gist options
  • Select an option

  • Save zenspider/8c72c83404d3fdb2ec8f1aeede1b8c62 to your computer and use it in GitHub Desktop.

Select an option

Save zenspider/8c72c83404d3fdb2ec8f1aeede1b8c62 to your computer and use it in GitHub Desktop.
ERR_RE = /unexpected (?:end-of-input|\$end|end-of-file|END_OF_FILE)|embedded document meets end of file|unterminated (?:string|regexp|list) meets end of file/.freeze
def self.complete_expression?(str)
catch(:valid) do
eval("BEGIN{throw :valid}\n#{str}")
end
true
rescue SyntaxError => ex
if ENV["FASTER"] then
msg = ex.message
[
/unexpected (?:end-of-input|\$end|end-of-file|END_OF_FILE)/,
/embedded document meets end of file/,
/unterminated (?:string|regexp|list) meets end of file/
].none? { |re| re.match? msg }
else
not ERR_RE.match? ex.message
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment