Class: Meteor::Core::Kernel
Overview
パーサコアクラス
Direct Known Subclasses
Constant Summary collapse
- EMPTY =
''
- SPACE =
' '
- DOUBLE_QUATATION =
'"'
- TAG_OPEN =
'<'
- TAG_OPEN3 =
'</'
- TAG_CLOSE =
TAG_OPEN4 = ‘<\\/’
'>'
- TAG_CLOSE3 =
TAG_CLOSE2 = ‘\/>’
'/>'
- ATTR_EQ =
'="'
- TAG_SEARCH_1_1 =
element TAG_SEARCH_1_1 = “([^<>]*)>(((?!(<\/”
'(\\s?[^<>]*)>(((?!('
- TAG_SEARCH_1_2 =
TAG_SEARCH_1_2 = “)).)*)<\/”;
'[^<>]*>)).)*)<\\/'
- TAG_SEARCH_1_3 =
'(\\s?[^<>]*)\\/>'
- TAG_SEARCH_1_4 =
TAG_SEARCH_1_4 = “([^<>\/]*)>”
'(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))'
- TAG_SEARCH_1_4_2 =
'(\\s[^<>]*)>'
- TAG_SEARCH_NC_1_1 =
'\\s?[^<>]*>((?!('
- TAG_SEARCH_NC_1_2 =
'[^<>]*>)).)*<\\/'
- TAG_SEARCH_NC_1_3 =
'\\s?[^<>]*\\/>'
- TAG_SEARCH_NC_1_4 =
'(?:\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))'
- TAG_SEARCH_NC_1_4_2 =
'\\s[^<>]*>'
- TAG_SEARCH_2_1 =
TAG_SEARCH_2_1 = “\s(*”
'(\\s[^<>]*'
- TAG_SEARCH_2_1_2 =
'(\\s[^<>]*(?:'
- TAG_SEARCH_2_2 =
TAG_SEARCH_2_2 = “"[^<>]*)>(((?!(<\/”
'"[^<>]*)>(((?!('
- TAG_SEARCH_2_2_2 =
'")[^<>]*)>(((?!('
- TAG_SEARCH_2_3 =
'"[^<>]*)'
- TAG_SEARCH_2_3_2 =
'"[^<>]*)\\/>'
- TAG_SEARCH_2_3_2_2 =
'")[^<>]*)\\/>'
- TAG_SEARCH_2_4 =
TAG_SEARCH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]*'
- TAG_SEARCH_3_1_2 =
'<([^<>"]*)\\s([^<>]*'
- TAG_SEARCH_3_1_2_2 =
'<([^<>"]*)\\s([^<>]*('
- TAG_SEARCH_3_2 =
'"[^<>]*\\/>'
- TAG_SEARCH_3_2_2 =
'"[^<>]*)\\/>'
- TAG_SEARCH_3_2_2_2 =
'")[^<>]*)\\/>'
- TAG_SEARCH_4_1 =
'(\\s[^<>\\/]*)>('
- TAG_SEARCH_4_2 =
'.*?<'
- TAG_SEARCH_4_3 =
TAG_SEARCH_4_3 = “\s*>”
'(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))'
- TAG_SEARCH_4_4 =
'<\\/'
- TAG_SEARCH_4_5 =
'.*?<\/'
- TAG_SEARCH_4_6 =
'.*?)<\/'
- TAG_SEARCH_4_7 =
TAG_SEARCH_4_7 = ‘"[^<>\/]*)>(”
'"(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))('
- TAG_SEARCH_4_7_2 =
'")(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))('
- TAG_SEARCH_NC_3_1 =
'<[^<>"]*\\s[^<>]*'
- TAG_SEARCH_NC_3_1_2 =
'<([^<>"]*)\\s(?:[^<>]*'
- TAG_SEARCH_NC_3_1_2_2 =
'<([^<>"]*)\\s(?:[^<>]*('
- TAG_SEARCH_NC_3_2 =
'"[^<>]*\\/>'
- TAG_SEARCH_NC_3_2_2 =
'"[^<>]*)\\/>'
- TAG_SEARCH_NC_3_2_2_2 =
'")[^<>]*)\\/>'
- SET_ATTR_1 =
setAttribute
'="[^"]*"'
- GET_ATTR_1 =
getAttributeValue
'="([^"]*)"'
- GET_ATTRS_MAP =
attributeMap
'([^\\s]*)="([^\"]*)"'
- ERASE_ATTR_1 =
removeAttribute
'="[^"]*"\\s?'
- SEARCH_CX_1 =
'<!--\\s@'
- SEARCH_CX_2 =
'\\s([^<>]*id="'
- SEARCH_CX_3 =
'"[^<>]*)-->(((?!(<!--\\s/@'
- SEARCH_CX_4 =
')).)*)<!--\\s/@'
- SEARCH_CX_5 =
'\\s-->'
- SEARCH_CX_6 =
'<!--\\s@([^<>]*)\\s[^<>]*id="'
- SET_CX_1 =
setElementToCXTag
'<!-- @'
- SET_CX_2 =
'-->'
- SET_CX_3 =
'<!-- /@'
- SET_CX_4 =
' -->'
- SET_MONO_1 =
setMonoInfo
'\\A[^<>]*\\Z'
- CLEAN_1 =
clean
'<!--\\s@[^<>]*\\s[^<>]*(\\s)*-->'
- CLEAN_2 =
'<!--\\s\\/@[^<>]*(\\s)*-->'
- AND_1 =
escape
'&'
- AND_2 =
'&'
- AND_3 =
'amp'
- LT_1 =
'<'
- LT_2 =
'<'
- LT_3 =
'lt'
- GT_1 =
'>'
- GT_2 =
'>'
- GT_3 =
'gt'
- QO_2 =
'"'
- QO_3 =
'quot'
- AP_1 =
'\''
- AP_2 =
'''
- AP_3 =
'apos'
- EN_1 =
EN_1 = “\\”
"\\"
- ESCAPE_ENTITY_REF =
EN_2 = “\\\\” DOL_1 = “\$” DOL_2 = “\\\$” PLUS_1 = “\+” PLUS_2 = “\\+”
''
- MODE_UTF8 =
'r:UTF-8'
- MODE_BF =
'r:'
- MODE_AF =
':utf-8'
- MODE =
'r'
- @@pattern_get_attrs_map =
Regexp.new(GET_ATTRS_MAP)
- @@pattern_clean1 =
Regexp.new(CLEAN_1)
- @@pattern_clean2 =
Regexp.new(CLEAN_2)
Constants inherited from Parser
Parser::HTML, Parser::XHTML, Parser::XML
Instance Attribute Summary collapse
-
#doc_type ⇒ Object
- Fixnum
-
ドキュメントタイプ.
-
#element_cache ⇒ Object
- Hash
-
要素キャッシュ.
Instance Method Summary collapse
- #attribute(*args) ⇒ Object
- #attribute_map(*args) ⇒ Object
-
#character_encoding ⇒ Object
文字エンコーディングを取得する.
-
#character_encoding=(enc) ⇒ Object
文字エンコーディングをセットする.
- #content(*args) ⇒ Object
-
#cxtag(*args) ⇒ Object
CX(コメント拡張)タグを取得する.
-
#document ⇒ String
ドキュメントを取得する.
-
#document=(doc) ⇒ Object
ドキュメントをセットする.
-
#element(*args) ⇒ Object
要素を取得する.
-
#execute(*args) ⇒ Object
フッククラスの処理を実行する.
-
#flush ⇒ Object
反映する.
-
#initialize ⇒ Kernel
constructor
イニシャライザ.
-
#read(file_path, encoding) ⇒ Object
ファイルを読み込み、パーサにセットする.
-
#remove_element(elm) ⇒ Object
要素を消す.
-
#root_element ⇒ Meteor::RootElement
ルート要素を取得する.
Constructor Details
#initialize ⇒ Kernel
イニシャライザ
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 |
# File 'lib/meteor.rb', line 1145 def initialize #親要素 #@parent = nil; #正規表現パターン #@pattern = nil #ルート要素 @root = RootElement.new #if RUBY_VERSION >= RUBY_VERSION_1_9_0 then @element_cache = Hash.new() #else # @element_cache = Meteor::Core::Util::OrderHash.new #end #@res = nil #@_attributes = nil #@_mixed_content = nil #@pattern_cc = nil #@pattern_cc_1 = nil #@pattern_cc_1b = nil #@pattern_cc_1_1 = nil #@pattern_cc_1_2 = nil #@pattern_cc_2 = nil #@pattern_cc_2_1 = nil #@pattern_cc_2_2 = nil #@pattern_2 = nil #@pattern_1 = nil #@pattern_1b = nil #@cnt = 0 #@position = 0 #@position2 = 0 #@_elmName = nil #@_attrName = nil #@_attrValue = nil #@_attrName1 = nil #@_attrValue1 = nil #@_attrName2 = nil #@_attrValue2 = nil #@sbuf = nil; #@sbuf = '' #@rx_document = nil; #@rx_document2 = nil; end |
Instance Attribute Details
#doc_type ⇒ Object
- Fixnum
-
ドキュメントタイプ
1208 1209 1210 |
# File 'lib/meteor.rb', line 1208 def doc_type @doc_type end |
#element_cache ⇒ Object
- Hash
-
要素キャッシュ
1207 1208 1209 |
# File 'lib/meteor.rb', line 1207 def element_cache @element_cache end |
Instance Method Details
#attribute(elm, attr_name, attr_value) ⇒ Meteor::Element #attribute(elm, attr_name) ⇒ String
2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 |
# File 'lib/meteor.rb', line 2141 def attribute(*args) case args.length #when ONE # get_attribute_value_1(args[0]) when TWO #if args[0].kind_of?(Meteor::Element) && args[1].kind_of?(String) then get_attribute_value(args[0],args[1]) #elsif args[0].kind_of?(String) && args[1].kind_of?(String) then # set_attribute_2(args[0],args[1]) #else # raise ArgumentError #end when THREE args[0].document_sync = true set_attribute_3(args[0],args[1],args[2]) else raise ArgumentError end end |
#attribute_map(elm, attr_map) ⇒ Meteor::Element #attribute_map(elm) ⇒ Meteor::AttributeMap
2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 |
# File 'lib/meteor.rb', line 2261 def attribute_map(*args) case args.length when ONE get_attribute_map(args[0]) when TWO #if args[0].kind_of?(Meteor::Element) && args[1].kind_of?(Meteor::AttributeMap) then args[0].document_sync = true set_attribute_map(args[0],args[1]) #end else raise ArgumentError end end |
#character_encoding ⇒ Object
文字エンコーディングを取得する
1222 1223 1224 |
# File 'lib/meteor.rb', line 1222 def character_encoding @root.character_encoding end |
#character_encoding=(enc) ⇒ Object
文字エンコーディングをセットする
1214 1215 1216 |
# File 'lib/meteor.rb', line 1214 def character_encoding=(enc) @root.character_encoding = enc end |
#content(elm, content, entity_ref = true) ⇒ Meteor::Element #content(elm, content) ⇒ Meteor::Element #content(elm) ⇒ String
2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 |
# File 'lib/meteor.rb', line 2329 def content(*args) case args.length when ONE #if args[0].kind_of?(Meteor::Element) then get_content_1(args[0]) #else # raise ArgumentError #end when TWO #if args[0].kind_of?(Meteor::Element) && args[1].kind_of?(String) then args[0].document_sync = true set_content_2(args[0],args[1]) #else # raise ArgumentError #end when THREE args[0].document_sync = true set_content_3(args[0],args[1],args[2]) else raise ArgumentError end end |
#cxtag(elm_name, id) ⇒ Meteor::Element #cxtag(id) ⇒ Meteor::Element
CX(コメント拡張)タグを取得する
2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 |
# File 'lib/meteor.rb', line 2451 def cxtag(*args) case args.length when ONE cxtag_1(args[0]) if @elm_ then @element_cache.store(@elm_.object_id,@elm_) end when TWO cxtag_2(args[0],args[1]) if @elm_ then @element_cache.store(@elm_.object_id,@elm_) end else raise ArgumentError end end |
#document ⇒ String
ドキュメントを取得する
1203 1204 1205 |
# File 'lib/meteor.rb', line 1203 def document @root.document end |
#document=(doc) ⇒ Object
ドキュメントをセットする
1195 1196 1197 |
# File 'lib/meteor.rb', line 1195 def document=(doc) @root.document = doc end |
#element(elm_name) ⇒ Meteor::Element #element(elm_name, attr_name, attr_value) ⇒ Meteor::Element #element(attr_name, attr_value) ⇒ Meteor::Element #element(elm_name, attr_name1, attr_value1, attr_name2, attr_value2) ⇒ Meteor::Element #element(attr_name1, attr_value1, attr_name2, attr_value2) ⇒ Meteor::Element
要素を取得する
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 |
# File 'lib/meteor.rb', line 1334 def element(*args) case args.length when ONE if args[0].kind_of?(String) then element_1(args[0]) if @elm_ then @element_cache.store(@elm_.object_id,@elm_) end elsif args[0].kind_of?(Meteor::Element) then shadow(args[0]) else raise ArgumentError end when TWO element_2(args[0],args[1]) if @elm_ then @element_cache.store(@elm_.object_id,@elm_) end when THREE element_3(args[0],args[1],args[2]) if @elm_ then @element_cache.store(@elm_.object_id,@elm_) end when FOUR element_4(args[0],args[1],args[2],args[3]) if @elm_ then @element_cache.store(@elm_.object_id,@elm_) end when FIVE element_5(args[0],args[1],args[2],args[3],args[4]) if @elm_ then @element_cache.store(@elm_.object_id,@elm_) end else @elm_ = nil raise ArgumentError end end |
#execute(*args) ⇒ Object
フッククラスの処理を実行する
2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 |
# File 'lib/meteor.rb', line 2710 def execute(*args) case args.length when TWO execute_2(args[0],args[1]) when THREE execute_3(args[0],args[1],args[2]) else raise ArgumentError end end |
#flush ⇒ Object
反映する
2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 |
# File 'lib/meteor.rb', line 2622 def flush if @root.element then if @root.element.origin.mono then if @root.element.origin.cx then #@root.hookDocument << SET_CX_1 << @root.element.name << SPACE #@root.hookDocument << @root.element.attributes << SET_CX_2 #@root.hookDocument << @root.element.mixed_content << SET_CX_3 #@root.hookDocument << @root.element.name << SET_CX_4 @root.hook_document << "<!-- @#{@root.element.name} #{@root.element.attributes}-->#{@root.element.mixed_content}<!-- /@#{@root.element.name} -->" else #@root.hookDocument << TAG_OPEN << @root.element.name #@root.hookDocument << @root.element.attributes << TAG_CLOSE << @root.element.mixed_content #@root.hookDocument << TAG_OPEN3 << @root.element.name << TAG_CLOSE @root.hook_document << "<#{@root.element.name}#{@root.element.attributes}>#{@root.element.mixed_content}</#{@root.element.name}>" end @root.element = Element.new!(@root.element.origin,self) else reflect @_attributes = @root.element.attributes #replace2regex(@_attributes) if @root.element.origin.cx then #@root.hookDocument << SET_CX_1 << @root.element.name << SPACE #@root.hookDocument << @_attributes << SET_CX_2 #@root.hookDocument << @root.document << SET_CX_3 #@root.hookDocument << @root.element.name << SET_CX_4 @root.hook_document << "<!-- @#{@root.element.name} #{@_attributes}-->#{@root.document}<!-- /@#{@root.element.name} -->" else #@root.hookDocument << TAG_OPEN << @root.element.name #@root.hookDocument << @_attributes << TAG_CLOSE << @root.document #@root.hookDocument << TAG_OPEN3 << @root.element.name << TAG_CLOSE @root.hook_document << "<#{@root.element.name}#{@_attributes}>#{@root.document}</#{@root.element.name}>" end @root.element = Element.new!(@root.element.origin,self) end else reflect @element_cache.clear #フック判定がFALSEの場合 clean end end |
#read(file_path, encoding) ⇒ Object
ファイルを読み込み、パーサにセットする
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 |
# File 'lib/meteor.rb', line 1239 def read(file_path, encoding) #try { @character_encoding = encoding #ファイルのオープン if RUBY_VERSION >= RUBY_VERSION_1_9_0 then if ParserFactory::ENC_UTF8.eql?(encoding) then #io = File.open(file_path,MODE_BF << encoding) io = File.open(file_path,MODE_UTF8) else io = File.open(file_path,MODE_BF << encoding << MODE_AF) end #読込及び格納 @root.document = io.read else #読込及び格納 io = open(file_path,MODE) @root.document = io.read #@root.document = @root.document.kconv(get_encoding(), Kconv.guess(@root.document)) enc = Kconv.guess(@root.document) #enc = get_encoding if !Kconv::UTF8.equal?(enc) then @root.document = @root.document.kconv(Kconv::UTF8, enc) end end #ファイルのクローズ io.close #@root.document = str #} catch (FileNotFoundException e) { #FileNotFoundException時の処理 #e.printStackTrace(); #@document = EMPTY; #} catch (Exception e) { # //上記以外の例外時の処理 # e.printStackTrace(); # this.setDocument(EMPTY); #} # #def get_encoding() # case @character_encoding # when 'UTF-8','UTF8','u','U' # @encoding = 'UTF8' # Kconv::UTF8 # when 'ISO-2022-JP','JIS' # Kconv::JIS # when 'Shift_JIS','SJIS','s','S' # @encoding = 'SJIS' # Kconv::SJIS # when 'EUC-JP','EUC','e','E' # @encoding = 'EUC' # Kconv::EUC # when 'ASCII' # Kconv::ASCII # #when "UTF-16" # # return KConv::UTF16 # else # Kconv::UTF8 # end #end #private :get_encoding end |
#remove_element(elm) ⇒ Object
要素を消す
2435 2436 2437 2438 2439 |
# File 'lib/meteor.rb', line 2435 def remove_element(elm) replace(elm,EMPTY) elm.usable = false nil end |
#root_element ⇒ Meteor::RootElement
ルート要素を取得する
1230 1231 1232 |
# File 'lib/meteor.rb', line 1230 def root_element @root end |