Module: Temple::StaticAnalyzer

Defined in:
lib/temple/static_analyzer.rb

Defined Under Namespace

Classes: ShorthandSyntaxChecker, SyntaxChecker

Constant Summary collapse

STATIC_TOKENS =
[
  :on_tstring_beg, :on_tstring_end, :on_tstring_content,
  :on_embexpr_beg, :on_embexpr_end,
  :on_lbracket, :on_rbracket,
  :on_qwords_beg, :on_words_sep, :on_qwords_sep,
  :on_lparen, :on_rparen,
  :on_lbrace, :on_rbrace, :on_label,
  :on_int, :on_float, :on_imaginary,
  :on_comma, :on_sp, :on_ignored_nl,
].freeze
DYNAMIC_TOKENS =
[
  :on_ident, :on_period,
].freeze
STATIC_KEYWORDS =
[
  'true', 'false', 'nil',
].freeze
STATIC_OPERATORS =
[
  '=>',
].freeze

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/temple/static_analyzer.rb', line 8

def available?
  true
end

.static?(code) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/temple/static_analyzer.rb', line 12

def static?(code)
  return false if code.nil? || code.strip.empty?
  (result = Prism.parse(code)).success? && static_node?(result.value)
end

.syntax_error?(code) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/temple/static_analyzer.rb', line 17

def syntax_error?(code)
  !Prism.parse_success?(code)
end