glaemscribe 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,46 +1,46 @@
1
1
  # encoding: UTF-8
2
2
  #
3
3
  # Glǽmscribe (also written Glaemscribe) is a software dedicated to
4
- # the transcription of texts between writing systems, and more
5
- # specifically dedicated to the transcription of J.R.R. Tolkien's
4
+ # the transcription of texts between writing systems, and more
5
+ # specifically dedicated to the transcription of J.R.R. Tolkien's
6
6
  # invented languages to some of his devised writing systems.
7
- #
7
+ #
8
8
  # Copyright (C) 2015 Benjamin Babut (Talagan).
9
- #
9
+ #
10
10
  # This program is free software: you can redistribute it and/or modify
11
11
  # it under the terms of the GNU Affero General Public License as published by
12
12
  # the Free Software Foundation, either version 3 of the License, or
13
13
  # any later version.
14
- #
14
+ #
15
15
  # This program is distributed in the hope that it will be useful,
16
16
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
17
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
18
  # GNU Affero General Public License for more details.
19
- #
19
+ #
20
20
  # You should have received a copy of the GNU Affero General Public License
21
21
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
22
22
 
23
23
  module Glaemscribe
24
24
  module API
25
-
25
+
26
26
  class PrePostProcessorOperator
27
27
  attr_reader :glaeml_element
28
28
  attr_reader :finalized_glaeml_element
29
-
29
+
30
30
  def initialize(mode, glaeml_element)
31
31
  @mode = mode
32
32
  @glaeml_element = glaeml_element
33
33
  end
34
-
34
+
35
35
  def eval_arg(arg, trans_options)
36
36
  return nil if arg.nil?
37
37
  if arg =~ /^\\eval\s/
38
38
  to_eval = $'
39
39
  return Eval::Parser.new().parse(to_eval, trans_options)
40
40
  end
41
- return arg
41
+ return arg
42
42
  end
43
-
43
+
44
44
  def finalize_glaeml_element(ge, trans_options)
45
45
  ge.args.map! { |arg| eval_arg(arg, trans_options) }
46
46
  ge.children.each{ |child|
@@ -48,37 +48,37 @@ module Glaemscribe
48
48
  }
49
49
  ge
50
50
  end
51
-
51
+
52
52
  def finalize(trans_options)
53
53
  @finalized_glaeml_element = finalize_glaeml_element(@glaeml_element.clone, trans_options)
54
54
  end
55
-
55
+
56
56
  def apply
57
57
  raise "Pure virtual method, should be overloaded."
58
58
  end
59
59
  end
60
-
60
+
61
61
  class TranscriptionPrePostProcessor
62
62
  attr_reader :root_code_block
63
-
63
+
64
64
  attr_reader :operators
65
-
65
+
66
66
  def initialize(mode)
67
67
  @mode = mode
68
- @root_code_block = IfTree::CodeBlock.new
68
+ @root_code_block = IfTree::CodeBlock.new
69
69
  end
70
-
70
+
71
71
  def descend_if_tree(code_block, trans_options)
72
- code_block.terms.each{ |term|
72
+ code_block.terms.each{ |term|
73
73
  if(term.is_pre_post_processor_operators?)
74
74
  term.operators.each{ |operator|
75
75
  @operators << operator
76
- }
76
+ }
77
77
  else
78
78
  term.if_conds.each{ |if_cond|
79
-
79
+
80
80
  if_eval = Eval::Parser.new()
81
-
81
+
82
82
  if(if_eval.parse(if_cond.expression, trans_options) == true)
83
83
  descend_if_tree(if_cond.child_code_block, trans_options)
84
84
  break
@@ -87,7 +87,7 @@ module Glaemscribe
87
87
  end
88
88
  }
89
89
  end
90
-
90
+
91
91
  def finalize(trans_options)
92
92
  @operators = []
93
93
  # Select operators depending on conditions
@@ -99,44 +99,47 @@ module Glaemscribe
99
99
  end
100
100
 
101
101
  end
102
-
103
- class PreProcessorOperator < PrePostProcessorOperator
102
+
103
+ class PreProcessorOperator < PrePostProcessorOperator
104
104
  end
105
-
105
+
106
106
  class PostProcessorOperator < PrePostProcessorOperator
107
107
  end
108
-
109
- class TranscriptionPreProcessor < TranscriptionPrePostProcessor
108
+
109
+ class TranscriptionPreProcessor < TranscriptionPrePostProcessor
110
110
  # Apply all preprocessor rules consecutively
111
111
  def apply(l)
112
112
  ret = l
113
113
  @operators.each{ |operator|
114
114
  ret = operator.apply(ret)
115
- }
115
+ }
116
116
  ret
117
117
  end
118
118
  end
119
-
119
+
120
120
  class TranscriptionPostProcessor < TranscriptionPrePostProcessor
121
-
121
+
122
122
  attr_accessor :out_space
123
-
123
+
124
124
  def apply(tokens, out_charset)
125
-
125
+
126
+ # Cleanup the output of the chain by removing empty tokens
127
+ tokens.select!{ |tok| tok != "" }
128
+
126
129
  # Apply filters
127
130
  @operators.each{ |operator|
128
131
  tokens = operator.apply(tokens,out_charset)
129
- }
132
+ }
130
133
 
131
134
  out_space_str = " "
132
- out_space_str = @out_space.map{ |token|
135
+ out_space_str = @out_space.map{ |token|
133
136
  out_charset[token]&.str || UNKNOWN_CHAR_OUTPUT
134
137
  }.join("") if @out_space
135
138
 
136
139
  # Convert output
137
140
  ret = ""
138
141
  tokens.each{ |token|
139
- case token
142
+ case token
140
143
  when ""
141
144
  when "*UNKNOWN"
142
145
  ret += UNKNOWN_CHAR_OUTPUT
@@ -145,13 +148,13 @@ module Glaemscribe
145
148
  when "*LF"
146
149
  ret += "\n"
147
150
  else
148
- c = out_charset[token]
151
+ c = out_charset[token]
149
152
  ret += (c.nil?)?(UNKNOWN_CHAR_OUTPUT):c.str
150
- end
153
+ end
151
154
  }
152
155
  ret
153
- end
154
- end
155
-
156
+ end
157
+ end
158
+
156
159
  end
157
160
  end
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.3.0
4
+ version: 1.3.1
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: 2022-09-23 00:00:00.000000000 Z
11
+ date: 2022-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  requirements: []
161
- rubygems_version: 3.3.7
161
+ rubygems_version: 3.2.22
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: Glǽmscribe