class Calyx::Syntax::Concat

A type of production rule representing a string combining both template substitutions and raw content.

Constants

DEREF_OP
END_TOKEN
EXPRESSION
START_TOKEN

Public Class Methods

new(expressions) click to toggle source

Initialize the concat node with an expansion of terminal and non-terminal fragments.

@param [Array] expansion

# File lib/calyx/syntax/concat.rb, line 41
def initialize(expressions)
  @expressions = expressions
end
parse(production, registry) click to toggle source

Parses an interpolated string into fragments combining terminal strings and non-terminal rules.

Returns a concat node which is the head of a tree of child nodes.

@param [String] production @param [Calyx::Registry] registry

# File lib/calyx/syntax/concat.rb, line 18
def self.parse(production, registry)
  expressions = production.split(EXPRESSION).map do |atom|
    if atom.is_a?(String)
      if atom.chars.first == START_TOKEN && atom.chars.last == END_TOKEN
        head, *tail = atom.slice(1, atom.length-2).split(DEREF_OP)
        if tail.any?
          ExpressionChain.parse(head, tail, registry)
        else
          Expression.parse(head, registry)
        end
      else
        Terminal.new(atom)
      end
    end
  end

  self.new(expressions)
end

Public Instance Methods

evaluate(options) click to toggle source

Evaluate all the child nodes of this node and concatenate each expansion together into a single result.

@param [Calyx::Options] options @return [Array]

# File lib/calyx/syntax/concat.rb, line 50
def evaluate(options)
  expansion = @expressions.reduce([]) do |exp, atom|
    exp << atom.evaluate(options)
  end

  #[:expansion, expansion]
  # TODO: fix this along with a git rename
  # Commented out because of a lot of tests depending on :concat symbol
  [:concat, expansion]
end