1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Rename SyntaxChecker to RubyExpression

This commit is contained in:
Takashi Kokubun 2015-11-23 14:14:53 +09:00
parent a2b69e3cbe
commit 957305538c
4 changed files with 9 additions and 9 deletions

View file

@ -1,4 +1,4 @@
require 'hamlit/syntax_checker' require 'hamlit/ruby_expression'
module Hamlit module Hamlit
class HashParser class HashParser
@ -11,7 +11,7 @@ module Hamlit
def parse(text) def parse(text)
exp = wrap_bracket(text) exp = wrap_bracket(text)
return if SyntaxChecker.syntax_error?(exp) return if RubyExpression.syntax_error?(exp)
hash = {} hash = {}
tokens = Ripper.lex(exp)[1..-2] || [] tokens = Ripper.lex(exp)[1..-2] || []

View file

@ -1,7 +1,7 @@
require 'ripper' require 'ripper'
module Hamlit module Hamlit
class SyntaxChecker < Ripper class RubyExpression < Ripper
class ParseError < StandardError; end class ParseError < StandardError; end
def self.syntax_error?(code) def self.syntax_error?(code)

View file

@ -1,4 +1,4 @@
require 'hamlit/syntax_checker' require 'hamlit/ruby_expression'
module Hamlit module Hamlit
class StaticAnalyzer class StaticAnalyzer
@ -26,7 +26,7 @@ module Hamlit
def self.static?(exp) def self.static?(exp)
return false if exp.nil? || exp.strip.empty? return false if exp.nil? || exp.strip.empty?
return false if SyntaxChecker.syntax_error?(exp) return false if RubyExpression.syntax_error?(exp)
Ripper.lex(exp).each do |(_, col), token, str| Ripper.lex(exp).each do |(_, col), token, str|
case token case token

View file

@ -1,12 +1,12 @@
describe Hamlit::SyntaxChecker do describe Hamlit::RubyExpression do
describe '.syntax_error?' do describe '.syntax_error?' do
it { assert_equal(true, Hamlit::SyntaxChecker.syntax_error?('{ hash }')) } it { assert_equal(true, Hamlit::RubyExpression.syntax_error?('{ hash }')) }
it { assert_equal(false, Hamlit::SyntaxChecker.syntax_error?('{ a: b }')) } it { assert_equal(false, Hamlit::RubyExpression.syntax_error?('{ a: b }')) }
end end
describe '.string_literal?' do describe '.string_literal?' do
def assert_literal(expected, code) def assert_literal(expected, code)
actual = Hamlit::SyntaxChecker.string_literal?(code) actual = Hamlit::RubyExpression.string_literal?(code)
assert_equal expected, actual assert_equal expected, actual
end end