glaemscribe 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -207,11 +207,12 @@ module Glaemscribe
207
207
  return @mode if(@mode.errors.any?)
208
208
 
209
209
  # Get the attributes of the mode
210
- @mode.language = doc.root_node.gpath('language').first.args.first
211
- @mode.writing = doc.root_node.gpath('writing').first.args.first
212
- @mode.human_name = doc.root_node.gpath('mode').first.args.first
213
- @mode.authors = doc.root_node.gpath('authors').first.args.first
214
- @mode.version = doc.root_node.gpath('version').first.args.first
210
+ @mode.language = doc.root_node.gpath('language').first.args.first
211
+ @mode.writing = doc.root_node.gpath('writing').first.args.first
212
+ @mode.human_name = doc.root_node.gpath('mode').first.args.first
213
+ @mode.authors = doc.root_node.gpath('authors').first.args.first
214
+ @mode.version = doc.root_node.gpath('version').first.args.first
215
+ @mode.raw_mode_name = doc.root_node.gpath('raw_mode').first.args.first if doc.root_node.gpath('raw_mode').first
215
216
 
216
217
  doc.root_node.gpath("options.option").each{ |option_element|
217
218
  values = {}
@@ -0,0 +1,22 @@
1
+ # From http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/43424
2
+ class Object
3
+ def deep_clone
4
+ return @deep_cloning_obj if @deep_cloning
5
+ @deep_cloning_obj = clone
6
+ @deep_cloning_obj.instance_variables.each do |var|
7
+ val = @deep_cloning_obj.instance_variable_get(var)
8
+ begin
9
+ @deep_cloning = true
10
+ val = val.deep_clone
11
+ rescue TypeError
12
+ next
13
+ ensure
14
+ @deep_cloning = false
15
+ end
16
+ @deep_cloning_obj.instance_variable_set(var, val)
17
+ end
18
+ deep_cloning_obj = @deep_cloning_obj
19
+ @deep_cloning_obj = nil
20
+ deep_cloning_obj
21
+ end
22
+ end
@@ -38,7 +38,7 @@ module Glaemscribe
38
38
  end
39
39
 
40
40
  def apply_loop(charset, tokens, new_tokens, reversed, token, idx)
41
- if token == '*SPACE'
41
+ if token == '*SPACE' || token =='*LF'
42
42
  reset_trigger_states(charset)
43
43
  return
44
44
  end
data/lib/api/sheaf.rb CHANGED
@@ -31,6 +31,7 @@ module Glaemscribe
31
31
  module API
32
32
  class Sheaf
33
33
 
34
+ attr_reader :linkable
34
35
  attr_reader :fragments
35
36
  attr_reader :sheaf_chain
36
37
  attr_reader :mode
@@ -44,8 +45,9 @@ module Glaemscribe
44
45
  def dst?; @sheaf_chain.dst?; end
45
46
 
46
47
  # Should pass a sheaf expression, e.g. : "h, s, t"
47
- def initialize(sheaf_chain, expression)
48
+ def initialize(sheaf_chain, expression, linkable)
48
49
 
50
+ @linkable = linkable
49
51
  @sheaf_chain = sheaf_chain
50
52
  @mode = sheaf_chain.mode
51
53
  @rule = sheaf_chain.rule
@@ -65,12 +65,16 @@ module Glaemscribe
65
65
  sheaf_exps = expression.split(SHEAF_REGEXP_OUT).map{ |elt| elt.strip }.reject{ |elt| elt.empty? }
66
66
  sheaf_exps = sheaf_exps.map { |sheaf_exp|
67
67
  sheaf_exp =~ SHEAF_REGEXP_IN
68
- sheaf_exp = $1 if $1 # Take the interior of the brackets it was a [...] expression
69
- sheaf_exp.strip
68
+ linkable = false
69
+ if $1 # Take the interior of the brackets it was a [...] expression
70
+ sheaf_exp = $1
71
+ linkable = true
72
+ end
73
+ { exp: sheaf_exp.strip, linkable: linkable }
70
74
  }
71
75
 
72
- @sheaves = sheaf_exps.map{ |sheaf_exp| Sheaf.new(self,sheaf_exp) }
73
- @sheaves = [Sheaf.new(self,"")] if @sheaves.empty?
76
+ @sheaves = sheaf_exps.map{ |sd| Sheaf.new(self, sd[:exp], sd[:linkable]) }
77
+ @sheaves = [Sheaf.new(self,"",false)] if @sheaves.empty?
74
78
  end
75
79
 
76
80
  def p
@@ -27,6 +27,8 @@ module Glaemscribe
27
27
  attr_accessor :sheaf_chain
28
28
  attr_accessor :cross_map
29
29
  attr_accessor :errors
30
+
31
+ attr_reader :prototype
30
32
 
31
33
  # If a cross schema is passed, the prototype of the chain will be permutated
32
34
  def initialize(sheaf_chain, cross_schema = nil)
@@ -41,40 +43,57 @@ module Glaemscribe
41
43
  # Construct the identity array
42
44
  identity_cross_array = []
43
45
  sheaf_count = sheaf_chain.sheaves.count
44
- sheaf_count.times{|i| identity_cross_array << i+1}
46
+ sheaf_count.times { |i| identity_cross_array << i }
45
47
 
48
+ # Make a list of iterable sheaves
49
+ iterable_idxs = []
50
+ prototype_array = []
51
+ sheaf_chain.sheaves.each_with_index { |sheaf,i|
52
+ if sheaf.linkable
53
+ iterable_idxs.push(i)
54
+ prototype_array.push(sheaf.fragments.count)
55
+ end
56
+ }
57
+
58
+ @cross_array = identity_cross_array
59
+ @prototype = prototype_array.join('x') || 'CONST'
60
+
46
61
  # Construct the cross array
47
62
  if cross_schema
48
- @cross_array = cross_schema.split(",").map{ |i| i.to_i }
49
- ca_count = @cross_array.count
50
- @errors << "#{sheaf_count} sheafs found in right predicate, but #{ca_count} elements in cross rule." if ca_count != sheaf_count
51
- @errors << "Cross rule should contain each element of #{identity_cross_array} once and only once." if identity_cross_array != @cross_array.sort
52
- else
53
- @cross_array = identity_cross_array
54
- end
55
- end
56
-
57
- # Calculate the prototype of the chain
58
- def prototype
59
- res = @sizes.clone
60
- res2 = @sizes.clone
61
63
 
62
- res.count.times{ |i| res2[i] = res[@cross_array[i]-1] }
63
- res = res2
64
-
65
- # Remove all sheaves of size 1 (which are constant)
66
- res.delete(1)
64
+ cross_schema = cross_schema.split(",").map{ |i| i.to_i - 1 }
65
+
66
+ # Verify that the number of iterables is equal to the cross schema length
67
+ it_count = iterable_idxs.count
68
+ ca_count = cross_schema.count
69
+ @errors << "#{it_count} linkable sheaves found in right predicate, but #{ca_count} elements in cross rule." and return if ca_count != it_count
70
+
71
+ # Verify that the cross schema is correct (should be a permutation of the identity)
72
+ it_identity_array = []
73
+ it_count.times { |i| it_identity_array << i }
74
+ @errors << "Cross rule schema should be a permutation of the identity (it should contain 1,2,..,n numbers once and only once)." and return if it_identity_array != cross_schema.sort
75
+
76
+ proto_array_permutted = prototype_array.clone
77
+
78
+ # Now calculate the cross array
79
+ cross_schema.each_with_index{ |to,from|
80
+ to_permut = iterable_idxs[from]
81
+ permut = iterable_idxs[to]
82
+ @cross_array[to_permut] = permut
83
+
84
+ proto_array_permutted[from] = prototype_array[to]
85
+ }
86
+ prototype_array = proto_array_permutted
87
+ end
67
88
 
68
- # Create a prototype string
69
- res = res.join("x")
70
- res = "1" if res.empty?
71
- res
89
+ # Recalculate prototype
90
+ @prototype = prototype_array.join('x') || 'CONST'
72
91
  end
73
92
 
74
93
  def iterate
75
94
  pos = 0
76
95
  while pos < @sizes.count do
77
- realpos = @cross_array[pos]-1
96
+ realpos = @cross_array[pos]
78
97
  @iterators[realpos] += 1
79
98
  if @iterators[realpos] >= @sizes[realpos]
80
99
  @iterators[realpos] = 0
data/lib/glaemscribe.rb CHANGED
@@ -32,6 +32,7 @@ module Glaemscribe
32
32
 
33
33
  require API_PATH + "/api/debug.rb"
34
34
  require API_PATH + "/api/constants.rb"
35
+ require API_PATH + "/api/object_additions.rb"
35
36
 
36
37
  require API_PATH + "/api/fragment.rb"
37
38
  require API_PATH + "/api/sheaf_chain_iterator.rb"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glaemscribe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin 'Talagan' Babut
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-04 00:00:00.000000000 Z
11
+ date: 2017-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -58,6 +58,7 @@ files:
58
58
  - glaemresources/modes/mercian.glaem
59
59
  - glaemresources/modes/quenya-sarati.glaem
60
60
  - glaemresources/modes/quenya.glaem
61
+ - glaemresources/modes/raw-tengwar.glaem
61
62
  - glaemresources/modes/rlyehian.glaem
62
63
  - glaemresources/modes/sindarin-beleriand.glaem
63
64
  - glaemresources/modes/sindarin-daeron.glaem
@@ -76,6 +77,7 @@ files:
76
77
  - lib/api/if_tree.rb
77
78
  - lib/api/mode.rb
78
79
  - lib/api/mode_parser.rb
80
+ - lib/api/object_additions.rb
79
81
  - lib/api/option.rb
80
82
  - lib/api/post_processor/resolve_virtuals.rb
81
83
  - lib/api/post_processor/reverse.rb