| 1 |
# WSDL4R - XMLSchema pattern definition for WSDL. |
|---|
| 2 |
# Copyright (C) 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. |
|---|
| 3 |
|
|---|
| 4 |
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can |
|---|
| 5 |
# redistribute it and/or modify it under the same terms of Ruby's license; |
|---|
| 6 |
# either the dual license version in 2003, or any later version. |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
require 'wsdl/info' |
|---|
| 10 |
require 'strscan' |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
module WSDL |
|---|
| 14 |
module XMLSchema |
|---|
| 15 |
|
|---|
| 16 |
class CharclassTranslatorToken |
|---|
| 17 |
def initialize(scanner,inside=false) |
|---|
| 18 |
@container = [] |
|---|
| 19 |
@scanner = scanner |
|---|
| 20 |
@inside = inside |
|---|
| 21 |
end |
|---|
| 22 |
def to_a |
|---|
| 23 |
@container |
|---|
| 24 |
end |
|---|
| 25 |
def translate |
|---|
| 26 |
while !@scanner.eos? |
|---|
| 27 |
flat = @scanner.scan(/[a-zA-Z0-9]-[a-zA-Z0-9]/) |
|---|
| 28 |
unless flat.nil? |
|---|
| 29 |
@container << eval("('" + flat.sub(/-/,"'..'") + "').to_a") |
|---|
| 30 |
next |
|---|
| 31 |
end |
|---|
| 32 |
c = @scanner.getch() |
|---|
| 33 |
case c |
|---|
| 34 |
when "[" |
|---|
| 35 |
c = CharclassTranslatorToken.new(@scanner,true) |
|---|
| 36 |
@container << c |
|---|
| 37 |
c.translate |
|---|
| 38 |
when "]" |
|---|
| 39 |
break |
|---|
| 40 |
else |
|---|
| 41 |
@container << c |
|---|
| 42 |
end |
|---|
| 43 |
end |
|---|
| 44 |
if @inside |
|---|
| 45 |
i = 0 |
|---|
| 46 |
while i<@container.length |
|---|
| 47 |
if @container[i].class != String and @container[i+1] == "-" and @container[i+2].class != String |
|---|
| 48 |
@container[i] = @container[i].to_a - @container[i+2].to_a |
|---|
| 49 |
@container.delete_at(i+1) |
|---|
| 50 |
@container.delete_at(i+1) |
|---|
| 51 |
else |
|---|
| 52 |
i+=1 |
|---|
| 53 |
end |
|---|
| 54 |
end |
|---|
| 55 |
@container.flatten! |
|---|
| 56 |
end |
|---|
| 57 |
end |
|---|
| 58 |
|
|---|
| 59 |
def to_s |
|---|
| 60 |
@container.inject('') { |s,i| i.class == String ? s << i : s << "[" + i.to_a.to_s + "]" } |
|---|
| 61 |
end |
|---|
| 62 |
end |
|---|
| 63 |
|
|---|
| 64 |
class Pattern < Info |
|---|
| 65 |
def initialize |
|---|
| 66 |
super |
|---|
| 67 |
end |
|---|
| 68 |
|
|---|
| 69 |
def parse_element(element) |
|---|
| 70 |
nil |
|---|
| 71 |
end |
|---|
| 72 |
|
|---|
| 73 |
def parse_attr(attr, value) |
|---|
| 74 |
case attr |
|---|
| 75 |
when ValueAttrName |
|---|
| 76 |
s = value.source |
|---|
| 77 |
s.gsub!("\\i",'[_:A-Za-z]') |
|---|
| 78 |
s.gsub!("\\I",'[^_:A-Za-z]') |
|---|
| 79 |
s.gsub!("\\c",'[-._:A-Za-z0-9]') |
|---|
| 80 |
s.gsub!("\\C",'[^-._:A-Za-z0-9]') |
|---|
| 81 |
|
|---|
| 82 |
ss = CharclassTranslatorToken.new(StringScanner.new(s)) |
|---|
| 83 |
ss.translate |
|---|
| 84 |
|
|---|
| 85 |
parent.pattern = /\A#{ss.to_s}\z/n |
|---|
| 86 |
value.source |
|---|
| 87 |
end |
|---|
| 88 |
end |
|---|
| 89 |
end |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
end |
|---|
| 93 |
end |
|---|