module Temple::StaticAnalyzer
def available?
def available? defined?(Ripper) && Ripper.respond_to?(:lex) end
def static?(code)
def static?(code) return false if code.nil? || code.strip.empty? return false if syntax_error?(code) Ripper.lex(code).each do |_, token, str| case token when *STATIC_TOKENS # noop when :on_kw return false unless STATIC_KEYWORDS.include?(str) when :on_op return false unless STATIC_OPERATORS.include?(str) when *DYNAMIC_TOKENS return false else return false end end true end
def syntax_error?(code)
def syntax_error?(code) SyntaxChecker.new(code).parse false rescue SyntaxChecker::ParseError true end