Class: StrScanParser
Overview
Constant Summary
collapse
- TAG_START =
/<narf:/
- TAG_END =
/>/
- TAG_CLOSE_START =
/<\/narf:/
- TAG_NAME =
/(\w+)/
- WHITESPACE =
/\s*/
- QUOTE =
/"/
- QUOTED_ATTRIBUTE_VALUE =
/([^"?]+)/
- UNQUOTED_ATTRIBUTE_VALUE =
/([\w.\/\$?]+)/
- EQUALS =
/=/
- ATTRIBUTE_NAME =
/(\w+)/
Instance Method Summary
collapse
#initialize, #match, #rest, #rest?
Constructor Details
This class inherits a constructor from StrScanParserR
Instance Method Details
#match_attribute ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/web/tagparser.rb', line 28
def match_attribute
if @scanner.scan(ATTRIBUTE_NAME)
name = @scanner[1]
if @scanner.scan(EQUALS)
match_value do |value|
yield({ name => value })
end || raise(MissingAttributeException.new)
else
yield({ name => nil })
end
end
end
|
#match_close_tag ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/web/tagparser.rb', line 64
def match_close_tag
if @scanner.scan(TAG_CLOSE_START)
tag = nil
if @scanner.scan(TAG_NAME)
tag = @scanner[1]
end @scanner.scan(TAG_END) yield tag if tag
end
end
|
#match_identifier ⇒ Object
75
76
77
78
79
|
# File 'lib/web/tagparser.rb', line 75
def match_identifier
if @scanner.scan(/\{\$([\w.\?]*?)\}/)
yield @scanner[1]
end
end
|
#match_tag ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/web/tagparser.rb', line 41
def match_tag
if @scanner.scan(TAG_START)
name = ""
nvs = {}
if @scanner.scan(TAG_NAME)
name = @scanner[1]
while true
@scanner.scan(WHITESPACE)
match_attribute do |nv|
nvs.update(nv)
end || if @scanner.scan(TAG_END)
yield Tag.new(name,nvs)
return true
else
raise(TagNotClosedException.new)
end
end
else
raise(TagNotNamedException.new)
end
end
end
|