Class: Kibuvits_krl171bt4_gstatement

Inherits:
Object
  • Object
show all
Defined in:
lib/kibuvits_ruby_library_krl171bt4_.rb

Overview

The Kibuvits_krl171bt4_gstatement instances represents an EBNF style statement like MY_GSTATEMENT_TYPE:==MOUSE MOUSEJUMP* CAT?

The Kibuvits_krl171bt4_gstatement acts as a container for other instances of the Kibuvits_krl171bt4_gstatement. The overall idea behind the Kibuvits_krl171bt4_gstatement is that if all of the terms and terminals at the right side of the :== are represented by elements that reside inside the Kibuvits_krl171bt4_gstatement based container, then one can generate code by using the Decorator design pattern. One just has to call the to_s method of the container to get the generated code. :-)

The EBNF spec that is given to the container at initialization detetermins the internal structure of the container.

The set of supported operators in the spec is {|,?,+,*}, but a limitation is that only one level of braces is supported, i.e. nesting of braces is not allowd, and none of the operators, the {|,?,+,*}, may be used outside of braces, except when the right side of the EBNF style spec does not contain any braces.

Examples of supported, i.e. valid, specifications:

UUU:== A |B |C
UUU:==(A |B |C )
UUU:== A?|B*|C+
UUU:==(A?|B*|C+)
UUU:==(A )B  C
UUU:==(A |B) C
UUU:== A (B|C+) D # gets autocompleted to "(A)(B|C+)(D)"

Examples of UNsupported, i.e. INvalid, specifications:

UUU:== A  B |C
UUU:==(A  B |C )
UUU:== A?|B  C
UUU:==(A )B  C+
UUU:== A (B|C+) D+

The reason, why the “UUU:== A (B|C+) D+” is not supported is that the autocompletion is not advanced enough to handle the operator after D. The reason, why the “ UUU:== A B |C” is not supported is that it actually entails “UUU:==(A B)|C”, where the | operator is outside of the brackets. If multiple nesting is not allowed, one can not autocomple it to “UUU:==((A B)|C)”.

There’s also a limitation that on the right side of the “:==” each term/terminal can be used only once.

NOT supported:

UUU:==(A B A+)

The reason for that limitation is that later, when one inserts elements that correspond to the terms and terminals, one is not able to determine, to which of the terminals the insertable element must correspond to. For example, in the case of the “UUU:==(A B A+)”, it’s not possible to determine, if it should represent/generate code for the first “A” or the second “A”.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s_specification_in_EBNF, msgcs) ⇒ Kibuvits_krl171bt4_gstatement

Returns a new instance of Kibuvits_krl171bt4_gstatement.



9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 9897

def initialize s_specification_in_EBNF, msgcs
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, String, s_specification_in_EBNF
      kibuvits_krl171bt4_typecheck bn, Kibuvits_krl171bt4_msgc_stack, msgcs
   end # if
   s_spec=s_specification_in_EBNF
   thrf_do_some_partial_verifications s_spec
   init_some_of_the_mainstructs
   parse_specification(s_specification_in_EBNF)
   @msgcs=msgcs
   @s_spec=s_specification_in_EBNF
   @s_prefix=@@lc_emptystring
   @s_suffix=@@lc_emptystring
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9524
9525
9526
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 9524

def name
  @name
end

#s_prefixObject

for code generation simplification



9525
9526
9527
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 9525

def s_prefix
  @s_prefix
end

#s_specObject (readonly)

Returns the value of attribute s_spec.



9524
9525
9526
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 9524

def s_spec
  @s_spec
end

#s_suffixObject

for code generation simplification



9525
9526
9527
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 9525

def s_suffix
  @s_suffix
end

Instance Method Details

#complete?Boolean

Returns true, if the gstatement has enough elements to satisfy the specification that it received at initialization.

Returns:

  • (Boolean)


9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 9953

def complete?
   @mx.synchronize do
      return @b_complete_cache if !@b_complete_cache_out_of_sync
      b_out=nil
      b_out=@b_complete_cache
      break if !@b_complete_cache_out_of_sync
      b_out=true
      @ar_level1.each do |ht_level2|
         update_ht_level2_b_complete(ht_level2)
         b_out=b_out&&ht_level2[@@lc_b_complete]
         if !b_out
            @b_complete_cache=false
            @b_complete_cache_out_of_sync=false
            break
         end # if
      end # loop
      @b_complete_cache=b_out
      @b_complete_cache_out_of_sync=false
   end #synchronize
   return @b_complete_cache
end

#insert(x_gstatement) ⇒ Object

It throws, if the x_gstatement is not insertable. One should always test for insertability prior to calling this method.



10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10027

def insert x_gstatement
   @mx.synchronize do
      @b_complete_cache_out_of_sync=true
      if !insertable? x_gstatement
         kibuvits_krl171bt4_throw "x_gstatement, which is of class \""+
         x_gstatement.class.to_s+"\", is not insertable. "
      end # if
      s_name=x_gstatement.name
      ht_level3=@ht_gstatement_name_2_ht_level3[s_name]
      ar_level3_elements=ht_level3[@@lc_ar_level3_elements]
      ar_level3_elements<<x_gstatement
   end # synchronize
end

#insertable?(x_gstatement_candidate) ⇒ Boolean

Only the gstatements that have a name that matches with the specification of this gstatement, are insertable, provided that the container gstatement is not full.

For example, if a specification is: MYTYPE:== a b c then at most one gstatement with name of “a” can be inserted to a gstatement, whiches name is “MYTYPE”.

This method returns always a boolean value, even, if the tested instance is not a Kibuvits_krl171bt4_gstatement istance.

Returns:

  • (Boolean)


9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 9987

def insertable? x_gstatement_candidate
   # The synchronization is because API users are
   # expected to check insertability prior to inserting,
   # but that can change after insertion.
   @mx2.synchronize do
      return false if @ar_level1.length==0
      ob=x_gstatement_candidate
      # There's a difference between Ruby 1.8 and 1.9 that
      # in the case of the Ruby 1.8 method names are returned, but
      # in the case of the Ruby 1.9 Symbol instances are returned.
      # It's not Kibuvits specific, but one will not normalize
      # it at the Kibuvits_krl171bt4_refl.get_methods_by_name either.
      # One just waits for the Ruby itself to stabilize to something.
      ht_method_names_or_symbols=Kibuvits_krl171bt4_refl.get_methods_by_name(
      @@lc_s_claim_to_be_a_gstatement_42_7,ob,"protected",@msgcs)
      kibuvits_krl171bt4_throw @msgcs.to_s if @msgcs.b_failure
      ht_method_names=Hash.new
      ht_method_names_or_symbols.each_key do |s_or_sym|
         ht_method_names[s_or_sym.to_s]=@@lc_emptystring
      end # loop
      if !ht_method_names.has_key? @@lc_s_claim_to_be_a_gstatement_42_7
         return false
      end # if
      s_name=ob.name
      return false if !@ht_gstatement_name_2_ht_level3.has_key? s_name
      ht_level3=@ht_gstatement_name_2_ht_level3[s_name]
      i_level3_max_length=ht_level3[@@lc_i_level3_max_length]
      return true if i_level3_max_length==(-1)
      # Here the i_level3_max_length==1
      ar_level3_elements=ht_level3[@@lc_ar_level3_elements]
      i_len=ar_level3_elements.length
      b_out=false
      b_out=true if i_len==0
      return b_out
   end # synchronize
end

#to_sObject



10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10077

def to_s
   i_len=@ar_level1.length
   ht_level2=nil
   s_out=@s_prefix
   s_out=s_out+to_s_elemspecific_prefix
   i_len.times do |i_level1_index|
      ht_level2=@ar_level1[i_level1_index]
      s_out=s_out+to_s_ht_level2(ht_level2)
   end # loop
   s_out=s_out+to_s_elemspecific_suffix
   s_out=s_out+@s_suffix
   return s_out
end