Module: Eggshell::ExpressionEvaluator::Parser

Defined in:
lib/eggshell/expression-evaluator/parser.rb

Defined Under Namespace

Classes: DefaultParser

Constant Summary collapse

ST_NULL =
0
ST_NUM =
1
ST_STRING =
2
ST_STRING_EMBED =
4
ST_STRING_BLOCK =
8
ST_LABEL =
16
ST_LABEL_CALL =
17
ST_LABEL_MEMBER =
19
ST_OPERATOR =
32
ST_OPERATOR_TERN =
33
ST_GROUP =
64
ST_HASH =
128
ST_ARRAY =
256
ST_INDEX_ACCESS =
ST_ARRAY|ST_LABEL
CONSTS =
{
	'true' => true,
	'false' => false,
	'nil' => nil,
	'null' => nil
}.freeze
FL_ONE_STATEMENT =

Indicates only one statement allowed

1
FL_BRACE_OP_COLLECT =

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

2

Class Method Summary collapse

Class Method Details

.reassemble(struct, sep = '') ⇒ Object



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/eggshell/expression-evaluator/parser.rb', line 376

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