Class: Meteor::Core::Kernel
Overview
パーサコアクラス
Direct Known Subclasses
Constant Summary collapse
- EMPTY =
''
- SPACE =
' '
- DOUBLE_QUATATION =
'"'
- TAG_OPEN =
'<'
- TAG_OPEN3 =
'</'
- TAG_OPEN4 =
'<\\\\/'
- TAG_CLOSE =
'>'
- TAG_CLOSE2 =
'\\/>'
- TAG_CLOSE3 =
'/>'
- 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_SE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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_BF =
'r:'
- MODE_AF =
':utf-8'
- MODE =
'r'
- @@pattern_get_attrs_map =
Regexp.new(GET_ATTRS_MAP,nil,E_UTF8)
- @@pattern_clean1 =
Regexp.new(CLEAN_1,nil,E_UTF8)
- @@pattern_clean2 =
Regexp.new(CLEAN_2,nil,E_UTF8)
Constants inherited from Parser
Parser::HTML, Parser::XHTML, Parser::XML
Instance Attribute Summary collapse
-
#doc_type ⇒ Object
Returns the value of attribute doc_type.
-
#element_cache ⇒ Object
Returns the value of attribute element_cache.
Instance Method Summary collapse
-
#attribute(*args) ⇒ String
要素の属性をセットする or 属性の値を取得する.
-
#attribute_map(*args) ⇒ Meteor::AttributeMap
属性マップを取得する.
-
#character_encoding ⇒ Object
文字エンコーディングを取得する.
-
#character_encoding=(enc) ⇒ Object
文字エンコーディングをセットする.
-
#content(*args) ⇒ String
要素の内容をセットする or 内容を取得する.
-
#cxtag(*args) ⇒ Meteor::Element
CX(コメント拡張)タグを取得する.
-
#document ⇒ String
ドキュメントを取得する.
-
#document=(doc) ⇒ Object
ドキュメントをセットする.
-
#element(*args) ⇒ Meteor::Element
要素を取得する.
-
#execute(*args) ⇒ Object
フッククラスの処理を実行する.
-
#flush ⇒ Object
出力する.
-
#initialize(*args) ⇒ Kernel
constructor
イニシャライザ.
-
#read(file_path, encoding) ⇒ Object
ファイルを読み込み、パーサにセットする.
-
#remove_attribute(*args) ⇒ Object
要素の属性を消す.
-
#remove_element(elm) ⇒ Object
要素を消す.
-
#root_element ⇒ Meteor::RootElement
ルート要素を取得する.
Constructor Details
#initialize(*args) ⇒ Kernel
イニシャライザ
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 |
# File 'lib/meteor.rb', line 1089 def initialize(*args) #親要素 #@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
Returns the value of attribute doc_type.
1152 1153 1154 |
# File 'lib/meteor.rb', line 1152 def doc_type @doc_type end |
#element_cache ⇒ Object
Returns the value of attribute element_cache.
1151 1152 1153 |
# File 'lib/meteor.rb', line 1151 def element_cache @element_cache end |
Instance Method Details
#attribute(*args) ⇒ String
要素の属性をセットする or 属性の値を取得する
2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 |
# File 'lib/meteor.rb', line 2057 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_2(args[0],args[1]) #elsif args[0].kind_of?(String) && args[1].kind_of?(String) then # set_attribute_2(args[0],args[1]) elsif args[0].kind_of?(Meteor::Element) && args[1].kind_of?(Meteor::AttributeMap) then args[0].document_sync = true set_attribute_2_m(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(*args) ⇒ Meteor::AttributeMap
属性マップを取得する
2243 2244 2245 2246 2247 2248 2249 2250 |
# File 'lib/meteor.rb', line 2243 def attribute_map(*args) case args.length when ONE get_attribute_map_1(args[0]) else raise ArgumentError end end |
#character_encoding ⇒ Object
文字エンコーディングを取得する
1168 1169 1170 |
# File 'lib/meteor.rb', line 1168 def character_encoding @root.character_encoding end |
#character_encoding=(enc) ⇒ Object
文字エンコーディングをセットする
1159 1160 1161 |
# File 'lib/meteor.rb', line 1159 def character_encoding=(enc) @root.character_encoding = enc end |
#content(*args) ⇒ String
要素の内容をセットする or 内容を取得する
2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 |
# File 'lib/meteor.rb', line 2296 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_s(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(*args) ⇒ Meteor::Element
CX(コメント拡張)タグを取得する
2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 |
# File 'lib/meteor.rb', line 2431 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
ドキュメントを取得する
1147 1148 1149 |
# File 'lib/meteor.rb', line 1147 def document @root.document end |
#document=(doc) ⇒ Object
ドキュメントをセットする
1138 1139 1140 |
# File 'lib/meteor.rb', line 1138 def document=(doc) @root.document = doc end |
#element(*args) ⇒ Meteor::Element
要素を取得する
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 |
# File 'lib/meteor.rb', line 1261 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
フッククラスの処理を実行する
2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 |
# File 'lib/meteor.rb', line 2649 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
出力する
2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 |
# File 'lib/meteor.rb', line 2560 def flush #puts @root.document 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
ファイルを読み込み、パーサにセットする
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 |
# File 'lib/meteor.rb', line 1187 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) 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); #} end |
#remove_attribute(*args) ⇒ Object
要素の属性を消す
2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 |
# File 'lib/meteor.rb', line 2372 def remove_attribute(*args) case args.length #when ONE # remove_attribute_1(args[0]) when TWO remove_attribute_2(args[0],args[1]) else raise ArgumentError end end |
#remove_element(elm) ⇒ Object
要素を消す
2420 2421 2422 2423 |
# File 'lib/meteor.rb', line 2420 def remove_element(elm) replace(elm,EMPTY) elm.usable = false end |
#root_element ⇒ Meteor::RootElement
ルート要素を取得する
1177 1178 1179 |
# File 'lib/meteor.rb', line 1177 def root_element @root end |