class PSD::EngineData

General purpose parser for the text data markup present within PSD documents.

Constants

INSTRUCTIONS

All of the instructions as defined by the EngineData spec.

VERSION

Attributes

node[RW]
node_stack[RW]
property[RW]
property_stack[RW]
result[RW]
text[R]

Public Class Methods

load(file) click to toggle source

Read a file containing EngineData markup and initialize a new instance.

# File lib/psd/enginedata.rb, line 38
def self.load(file)
  self.new File.new(file, 'rb').read
end
new(text) click to toggle source

Create a new Text instance and initialize our parsing stacks.

# File lib/psd/enginedata.rb, line 43
def initialize(text)
  @text = Text.new(text)

  @property_stack = []
  @node_stack = []

  @property = :root
  @node = nil

  @parsed = false
end

Public Instance Methods

parse!() click to toggle source

Parses the full document.

# File lib/psd/enginedata.rb, line 56
def parse!
  return if parsed?

  while true
    line = @text.current
    @parsed = true and return if line.nil?

    parse_tokens(line)
    @text.next!
  end
end
parse_tokens(text) click to toggle source

Go through each instruction until a token match is found, then parse the matches.

# File lib/psd/enginedata.rb, line 75
def parse_tokens(text)
  INSTRUCTIONS.each do |inst|
    match = inst.match(text)
    return inst.new(self, text).execute! if match
  end

  # This is a hack for the Japanese character rules that the format embeds
  match = Instruction::String.match(text + @text.next)
  if match
    text += @text.next!
    return Instruction::String.new(self, text).execute!
  end

  raise TokenNotFound.new("Text = #{text.dump}, Line = #{@text.line + 1}")
end
parsed?() click to toggle source

Has the document been parsed yet?

# File lib/psd/enginedata.rb, line 69
def parsed?
  @parsed
end