Module: Kwartz::JstlExpressionParser

Included in:
JstlHandler, JstlTranslator
Defined in:
lib/kwartz/binding/jstl.rb

Instance Method Summary collapse

Instance Method Details

#parse_expr_str(expr_str, linenum) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kwartz/binding/jstl.rb', line 20

def parse_expr_str(expr_str, linenum)
  case expr_str
  when /\A(\w+)\z/             # variable
    expr = expr_str
  when /\A(\w+)\.(\w+)\z/      # object.property
    expr = expr_str
  when /\A(\w+)\[('.*?'|".*?"|:\w+)\]\z/   # hash
    key = $2[0] == ?: ? "'#{$2[1..-1]}'" : $2
    expr = "#{$1}[#{key}]"
  when /\A(\w+)\[(\w+)\]\z/    # array or hash
    expr = "#{$1}[#{$2}]"
  else
    raise convert_error("'#{expr_str}': invalid expression.", linenum)
  end
  return expr
end

#parse_expr_str!(expr_str) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/kwartz/binding/jstl.rb', line 38

def parse_expr_str!(expr_str)
  begin
    return parse_expr_str(expr_str, 0)
  rescue
    return expr_str
  end
end