Created
November 12, 2025 00:37
-
-
Save zenspider/8c72c83404d3fdb2ec8f1aeede1b8c62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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