module Eggshell::ExpressionEvaluator::Parser

Constants

CONSTS
FL_BRACE_OP_COLLECT

Indicates that for an opening brace (e.g. `if (…) {`), collect remaining items after brace.

FL_ONE_STATEMENT

Indicates only one statement allowed

STATE_NAMES
ST_ARRAY
ST_GROUP
ST_HASH
ST_INDEX_ACCESS
ST_LABEL
ST_LABEL_CALL
ST_LABEL_MEMBER
ST_NULL
ST_NUM
ST_OPERATOR
ST_OPERATOR_TERN
ST_STRING
ST_STRING_BLOCK
ST_STRING_EMBED

Public Class Methods

reassemble(struct, sep = '') click to toggle source
# File lib/eggshell/expression-evaluator/parser.rb, line 419
def self.reassemble(struct, sep = '')
        buff = []
        s = ''
        struct.each do |ele|
                if ele.is_a?(Array)
                        if ele[0] == :op
                                buff << reassemble(ele[1])
                        elsif ele[0] == :op_tern
                                buff << reassemble(ele[1])
                                buff << ' ? '
                                buff << reassemble(ele[2])
                                buff << ' : '
                                buff << reassemble(ele[3])
                        elsif ele[0] == :func
                                buff << ele[1] + '('
                                buff << reassemble(ele[2], ',')
                                buff << ')'
                        elsif ele[0] == :group
                                buff << '('
                                buff << reassemble(ele[1..-1])
                                buff << ')'
                        elsif ele[0] == :var
                                if ele.length > 2
                                        buff << reassemble(ele[1..-1])
                                else
                                        buff << ele[1]
                                end
                        elsif ele[0] == :index_access
                                buff << '['
                                if ele[1].is_a?(Array)
                                        buff << reassemble(ele[1])
                                else
                                        buff << ele[1]
                                end
                                buff << ']'
                        end
                else
                        buff << s
                        buff << (ele.is_a?(String) ? '"' + ele.gsub('"', '\\"') + '"' : ele)
                        s = sep
                end
        end
        
        buff.join('')
end