Class: StrScanParser

Inherits:
StrScanParserR show all
Defined in:
lib/web/tagparser.rb

Overview

:nodoc:

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

Methods inherited from StrScanParserR

#initialize, #match, #rest, #rest?

Constructor Details

This class inherits a constructor from StrScanParserR

Instance Method Details

#match_attributeObject



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_tagObject



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 # TODO raise missing name exception
      @scanner.scan(TAG_END) # TODO raise missing end tag exception
      yield tag if tag
	end
end

#match_identifierObject



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_tagObject



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

#match_valueObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/web/tagparser.rb', line 17

def match_value 
	if @scanner.scan(QUOTE)
 if @scanner.scan(QUOTED_ATTRIBUTE_VALUE)
		yield @scanner[1]
		@scanner.scan(QUOTE) || raise(MissingQuoteException.new)
 end
	elsif @scanner.scan(UNQUOTED_ATTRIBUTE_VALUE)
 yield @scanner[1]
	end
end