Class: Mdextab::Layer
- Inherits:
-
Object
- Object
- Mdextab::Layer
- Defined in:
- lib/mdextab/layer.rb
Overview
入れ子のTableにを管理するレイヤークラス
Instance Attribute Summary collapse
-
#cur_layer ⇒ Layer
現在のレイヤー.
-
#return_from_nested_layer ⇒ Boolean
入れ子のレイヤーからリターンしたかを示す.
-
#size ⇒ Integer
レイヤーの階層数.
Instance Method Summary collapse
-
#add_layer(fname, lineno, state = :START) ⇒ Symbol
新しいレイヤーの追加.
-
#check_layers(fname) ⇒ void
全レイヤーの状態検査.
-
#cur_state ⇒ Symbol
カレントレイヤーの状態を設定.
-
#cur_state=(val) ⇒ Object
カレントレイヤーの状態を設定.
-
#initialize(mes, output) ⇒ Layer
constructor
初期化.
-
#peek_prev_layer ⇒ Layer?
1つ前のレイヤーを返す.
-
#pop_layer ⇒ Layer
カレントレイヤーを取り出して返す.
-
#process_nested_table_start(token, lineno, fname) ⇒ void
入れ子のTABLE_STARTトークンとトークン出現行の処理.
-
#process_table_end(token) ⇒ void
TABLE_ENDトークンの処理.
-
#process_table_end_for_prev_env(token) ⇒ void
入れ子のTABLE_ENDトークンの処理.
-
#star=(val) ⇒ Boolean
カレントレイヤーのstarの存在の有無を取得.
-
#star=(val) ⇒ Object
カレントレイヤーのstarの存在の有無を設定.
-
#tablee ⇒ Table
カレントレイヤーのtableを取得.
-
#table=(val) ⇒ Object
カレントレイヤーのtableを設定.
Constructor Details
#initialize(mes, output) ⇒ Layer
初期化
20 21 22 23 24 25 26 27 28 |
# File 'lib/mdextab/layer.rb', line 20 def initialize(mes, output) @mes = mes @output = output @return_from_nested_layer = false @layer_struct = Struct.new(:table, :star, :cur_state, :fname, :lineno) @cur_layer = nil @layers = [] end |
Instance Attribute Details
#cur_layer ⇒ Layer
現在のレイヤー
10 11 12 |
# File 'lib/mdextab/layer.rb', line 10 def cur_layer @cur_layer end |
#return_from_nested_layer ⇒ Boolean
入れ子のレイヤーからリターンしたかを示す
7 8 9 |
# File 'lib/mdextab/layer.rb', line 7 def return_from_nested_layer @return_from_nested_layer end |
#size ⇒ Integer
レイヤーの階層数
13 14 15 |
# File 'lib/mdextab/layer.rb', line 13 def size @size end |
Instance Method Details
#add_layer(fname, lineno, state = :START) ⇒ Symbol
新しいレイヤーの追加
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/mdextab/layer.rb', line 81 def add_layer(fname, lineno, state=:START) new_layer = @layer_struct.new(nil, nil, nil, fname, lineno) @layers << new_layer @size = @layers.size # raise if state.class != Symbol new_layer.cur_state = state new_layer.star = if @cur_layer @cur_layer.star else false end @cur_layer = new_layer end |
#check_layers(fname) ⇒ void
fnameはデバッグ出力、エラー出力に使う
This method returns an undefined value.
全レイヤーの状態検査
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/mdextab/layer.rb', line 195 def check_layers(fname) case @cur_layer.cur_state when :OUT_OF_TABLE if @layers.size > 1 @mes.output_fatal("illeagal nested env after parsing|:OUT_OF_TABLE") @mes.output_fatal("@layers.size=#{@layers.size} :TABLE_START #{fname} #{table.lineno}") @layers.map { |x| @mes.output_debug("== @layers.cur_state=#{x.cur_state} :TABLE_START #{fname} #{x.table.lineno}") } @mes.output_debug("== table") @mes.output_info(table) exit(@mes.ec("EXIT_CODE_EXCEPTION")) end when :START if @layers.size > 1 @mes.output_fatal("illeagal nested env after parsing|:START") @mes.output_fatal("@layers.size=#{@layers.size}") @layers.map { |x| @mes.output_error("== @layers.cur_state=#{x.cur_state} :TABLE_START #{fname} #{x.table.lineno}") } @mes.output_error("== table") @mes.output_error(table) exit(@mes.ec("EXIT_CODE_EXCEPTION")) end else @mes.output_fatal("illeagal state after parsing(@cur_layer.cur_state=#{@cur_layer.cur_state}|fname=#{fname}") @mes.output_fatal("@layers.size=#{@layers.size}") @mes.output_error("== cur_state=#{@cur_layer.cur_state}") @layers.map { |x| @mes.output_error("== @layers.cur_state=#{x.cur_state} #{fname}:#{x.table.lineno}") } @mes.output_error("") exit(@mes.ec("EXIT_CODE_ILLEAG<AL_STATE")) end end |
#cur_state ⇒ Symbol
カレントレイヤーの状態を設定
41 42 43 44 45 |
# File 'lib/mdextab/layer.rb', line 41 def cur_state raise if @cur_layer.cur_state.class != Symbol @cur_layer.cur_state end |
#cur_state=(val) ⇒ Object
カレントレイヤーの状態を設定
33 34 35 36 |
# File 'lib/mdextab/layer.rb', line 33 def cur_state=(val) # raise if val.class != Symbol @cur_layer.cur_state = val end |
#peek_prev_layer ⇒ Layer?
1つ前のレイヤーを返す
112 113 114 115 116 |
# File 'lib/mdextab/layer.rb', line 112 def peek_prev_layer return nil unless @layers.size > 1 @layers[@layers.size - 2] end |
#pop_layer ⇒ Layer
カレントレイヤーを取り出して返す
99 100 101 102 103 104 105 |
# File 'lib/mdextab/layer.rb', line 99 def pop_layer tmp_ = @layers.pop @size = @layers.size @cur_layer = @layers.last tmp_ end |
#process_nested_table_start(token, lineno, fname) ⇒ void
This method returns an undefined value.
入れ子のTABLE_STARTトークンとトークン出現行の処理
125 126 127 128 129 130 131 132 133 |
# File 'lib/mdextab/layer.rb', line 125 def process_nested_table_start(token, lineno, fname) # TBODYトークンが出現する前にTABLE_STARTトークンが出現した場合、仮想的なTBODYトークンが出現したとみなす table.add_tbody(lineno) if table.tbody.nil? @mes.output_debug("B process_nested_table_start 1 @cur_layer.table=#{@cur_layer.table.object_id} token.kind=#{token.kind} token.opt[:lineno]=#{token.opt[:lineno]} cur_state=#{@cur_layer.cur_state}") # 新しいレイヤーを追加して、それをカレントレイヤーとし、カレントレイヤーにTableを追加する add_layer(fname, lineno, :OUT_OF_TABLE) @cur_layer.table = Table.new(token.opt[:lineno], @mes, token.opt[:attr]) @mes.output_debug("process_nested_table_start 3 token.kind=#{token.kind} cur_state=#{@cur_layer.cur_state}") end |
#process_table_end(token) ⇒ void
This method returns an undefined value.
TABLE_ENDトークンの処理
140 141 142 143 144 145 146 |
# File 'lib/mdextab/layer.rb', line 140 def process_table_end(token) prev_layer = peek_prev_layer return unless prev_layer # 一つ前のレイヤーが存在すれば、入れ子のTABLE_ENDトークンとして処理する process_table_end_for_prev_env(token) end |
#process_table_end_for_prev_env(token) ⇒ void
tokenはデバッグ出力、エラー出力に使う
This method returns an undefined value.
入れ子のTABLE_ENDトークンの処理
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/mdextab/layer.rb', line 154 def process_table_end_for_prev_env(token) tmp_table = @cur_layer.table pop_layer @return_from_nested_layer = true # pop_layerを呼んだ後なので、カレントレイヤーはメソッド呼び出し時より一つ前のレイヤー case @cur_layer.cur_state when :IN_TD @cur_layer.table.td_append(tmp_table, @cur_layer.star) when :IN_TD_NO_TBODY @cur_layer.table.td_append(tmp_table, @cur_layer.star) when :IN_TH @cur_layer.table.th_append(tmp_table, @cur_layer.star) when :IN_TH_NO_TBODY @cur_layer.table.th_append(tmp_table, @cur_layer.star) when :IN_TABLE if @cur_layer.table.nil? @mes.output_debug("In process_nested_table_env_for_prev_env: table=nil token.kind=#{token.kind} token.opt[:lineno]=#{token.opt[:lineno]} cur_state=#{@cur_layer.cur_state}") raise end @cur_layer.table.add(tmp_table) when :IN_TABLE_BODY @cur_layer.table.add(tmp_table) when :START @mes.output_debug("In process_nested_table_env_for_prev_env: table=nil token.kind=#{token.kind} token.opt[:lineno]=#{token.opt[:lineno]} cur_state=#{@cur_layer.cur_state}") raise else v = @cur_layer.cur_state || "nil" @mes.output_fatal("E100 cur_state=#{v}") @mes.output_fatal("table=#{@cur_layer.table}") @mes.output_fatal("IllegalState(#{@cur_layer.cur_state} in process_table_end(#{token})") exit(@mes.ec("EXIT_CODE_TABLE_END")) end end |
#star=(val) ⇒ Boolean
カレントレイヤーのstarの存在の有無を取得
71 72 73 |
# File 'lib/mdextab/layer.rb', line 71 def star @cur_layer.star end |
#star=(val) ⇒ Object
カレントレイヤーのstarの存在の有無を設定
64 65 66 |
# File 'lib/mdextab/layer.rb', line 64 def star=(val) @cur_layer.star = val end |
#tablee ⇒ Table
カレントレイヤーのtableを取得
57 58 59 |
# File 'lib/mdextab/layer.rb', line 57 def table @cur_layer.table end |
#table=(val) ⇒ Object
カレントレイヤーのtableを設定
50 51 52 |
# File 'lib/mdextab/layer.rb', line 50 def table=(val) @cur_layer.table = val end |