biglot: generic class for polyglots with two glots and a set of transitions
[ohcount] / ext / ohcount_native / glots / biglot.rb
1 require 'polyglot'
2
3 module Ohcount
4         # Generic "two languages" polyglot
5         class Biglot < Polyglot
6
7                 # A Biglot is defined by its name, the first language, the second language, and an array of transitions
8                 # Each transition is specified as an array of parameters to initialize a StitchTransition
9                 def initialize(name, lang1, lang2, states, trans)
10                         @name = name
11
12                         @states = (lang1.all_states rescue lang1.states) + (lang2.all_states rescue lang2.states)
13                         @extra_states = []
14
15                         @transitions = (lang1.all_transitions rescue lang1.transitions) + (lang2.all_transitions rescue lang2.transitions)
16                         @extra_transitions = []
17
18                         states.each { |ar| @extra_states << State.new(*ar) }
19                         trans.each { |ar| @extra_transitions << StitchTransition.new(*ar) }
20                 end
21         end
22 end