diff options
| author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-01-13 05:11:45 +0000 |
|---|---|---|
| committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-01-13 05:11:45 +0000 |
| commit | 86240434eb153c149dbc3d77f4fedf9cffcbfc53 (patch) | |
| tree | eb5eccc07097c5fcf940967f33ab84a7d47c96fe /libgo/go/html | |
| parent | 9599f526f8b241e01ca4d54b5bff9c2e6f6dd75a (diff) | |
| download | ppe42-gcc-86240434eb153c149dbc3d77f4fedf9cffcbfc53.tar.gz ppe42-gcc-86240434eb153c149dbc3d77f4fedf9cffcbfc53.zip | |
libgo: Update to weekly.2011-12-22.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183150 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/html')
| -rw-r--r-- | libgo/go/html/const.go | 12 | ||||
| -rw-r--r-- | libgo/go/html/parse.go | 87 | ||||
| -rw-r--r-- | libgo/go/html/parse_test.go | 3 | ||||
| -rw-r--r-- | libgo/go/html/template/error.go | 6 | ||||
| -rw-r--r-- | libgo/go/html/template/escape.go | 10 | ||||
| -rw-r--r-- | libgo/go/html/template/escape_test.go | 12 |
6 files changed, 105 insertions, 25 deletions
diff --git a/libgo/go/html/const.go b/libgo/go/html/const.go index 832e9dbc096..d7cc8bb9a99 100644 --- a/libgo/go/html/const.go +++ b/libgo/go/html/const.go @@ -7,7 +7,7 @@ package html // Section 12.2.3.2 of the HTML5 specification says "The following elements // have varying levels of special parsing rules". // http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#the-stack-of-open-elements -var isSpecialElement = map[string]bool{ +var isSpecialElementMap = map[string]bool{ "address": true, "applet": true, "area": true, @@ -88,3 +88,13 @@ var isSpecialElement = map[string]bool{ "wbr": true, "xmp": true, } + +func isSpecialElement(element *Node) bool { + switch element.Namespace { + case "", "html": + return isSpecialElementMap[element.Data] + case "svg": + return element.Data == "foreignObject" + } + return false +} diff --git a/libgo/go/html/parse.go b/libgo/go/html/parse.go index 4cb246969e5..6962e643932 100644 --- a/libgo/go/html/parse.go +++ b/libgo/go/html/parse.go @@ -319,10 +319,7 @@ func (p *parser) resetInsertionMode() { case "html": p.im = beforeHeadIM default: - if p.top().Namespace == "" { - continue - } - p.im = inForeignContentIM + continue } return } @@ -705,7 +702,7 @@ func inBodyIM(p *parser) bool { case "address", "div", "p": continue default: - if !isSpecialElement[node.Data] { + if !isSpecialElement(node) { continue } } @@ -723,7 +720,7 @@ func inBodyIM(p *parser) bool { case "address", "div", "p": continue default: - if !isSpecialElement[node.Data] { + if !isSpecialElement(node) { continue } } @@ -814,7 +811,6 @@ func inBodyIM(p *parser) bool { // TODO: adjust foreign attributes. p.addElement(p.tok.Data, p.tok.Attr) p.top().Namespace = namespace - p.im = inForeignContentIM return true case "caption", "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th", "thead", "tr": // Ignore the token. @@ -895,7 +891,7 @@ func (p *parser) inBodyEndTagFormatting(tag string) { // Steps 5-6. Find the furthest block. var furthestBlock *Node for _, e := range p.oe[feIndex:] { - if isSpecialElement[e.Data] { + if isSpecialElement(e) { furthestBlock = e break } @@ -988,7 +984,7 @@ func (p *parser) inBodyEndTagOther(tag string) { p.oe = p.oe[:i] break } - if isSpecialElement[p.oe[i].Data] { + if isSpecialElement(p.oe[i]) { break } } @@ -1206,6 +1202,13 @@ func inTableBodyIM(p *parser) bool { add = true data = "tr" consumed = false + case "caption", "col", "colgroup", "tbody", "tfoot", "thead": + if !p.popUntil(tableScopeStopTags, "tbody", "thead", "tfoot") { + // Ignore the token. + return true + } + p.im = inTableIM + return false default: // TODO. } @@ -1569,6 +1572,19 @@ func afterAfterFramesetIM(p *parser) bool { Type: CommentNode, Data: p.tok.Data, }) + case TextToken: + // Ignore all text but whitespace. + s := strings.Map(func(c rune) rune { + switch c { + case ' ', '\t', '\n', '\f', '\r': + return c + } + return -1 + }, p.tok.Data) + if s != "" { + p.reconstructActiveFormattingElements() + p.addText(s) + } case StartTagToken: switch p.tok.Data { case "html": @@ -1583,8 +1599,19 @@ func afterAfterFramesetIM(p *parser) bool { } // Section 12.2.5.5. -func inForeignContentIM(p *parser) bool { +func parseForeignContent(p *parser) bool { switch p.tok.Type { + case TextToken: + // TODO: HTML integration points. + if p.top().Namespace == "" { + inBodyIM(p) + p.resetInsertionMode() + return true + } + if p.framesetOK { + p.framesetOK = strings.TrimLeft(p.tok.Data, whitespace) == "" + } + p.addText(p.tok.Data) case CommentToken: p.addChild(&Node{ Type: CommentNode, @@ -1592,7 +1619,14 @@ func inForeignContentIM(p *parser) bool { }) case StartTagToken: if breakout[p.tok.Data] { - // TODO. + for i := len(p.oe) - 1; i >= 0; i-- { + // TODO: HTML, MathML integration points. + if p.oe[i].Namespace == "" { + p.oe = p.oe[:i+1] + break + } + } + return false } switch p.top().Namespace { case "mathml": @@ -1606,13 +1640,36 @@ func inForeignContentIM(p *parser) bool { // TODO: adjust foreign attributes. p.addElement(p.tok.Data, p.tok.Attr) case EndTagToken: - // TODO. + for i := len(p.oe) - 1; i >= 0; i-- { + if p.oe[i].Namespace == "" { + return p.im(p) + } + if strings.EqualFold(p.oe[i].Data, p.tok.Data) { + p.oe = p.oe[:i] + break + } + } + return true default: // Ignore the token. } return true } +// Section 12.2.5. +func (p *parser) inForeignContent() bool { + if len(p.oe) == 0 { + return false + } + n := p.oe[len(p.oe)-1] + if n.Namespace == "" { + return false + } + // TODO: MathML, HTML integration points. + // TODO: MathML's annotation-xml combining with SVG's svg. + return true +} + func (p *parser) parse() error { // Iterate until EOF. Any other error will cause an early return. consumed := true @@ -1625,7 +1682,11 @@ func (p *parser) parse() error { return err } } - consumed = p.im(p) + if p.inForeignContent() { + consumed = parseForeignContent(p) + } else { + consumed = p.im(p) + } } // Loop until the final token (the ErrorToken signifying EOF) is consumed. for { diff --git a/libgo/go/html/parse_test.go b/libgo/go/html/parse_test.go index e887631c63d..015b5838f0b 100644 --- a/libgo/go/html/parse_test.go +++ b/libgo/go/html/parse_test.go @@ -172,7 +172,8 @@ func TestParser(t *testing.T) { {"tests3.dat", -1}, {"tests4.dat", -1}, {"tests5.dat", -1}, - {"tests6.dat", 36}, + {"tests6.dat", 47}, + {"tests10.dat", 16}, } for _, tf := range testFiles { f, err := os.Open("testdata/webkit/" + tf.filename) diff --git a/libgo/go/html/template/error.go b/libgo/go/html/template/error.go index 9622d7e48ee..dcac7489676 100644 --- a/libgo/go/html/template/error.go +++ b/libgo/go/html/template/error.go @@ -183,11 +183,11 @@ const ( func (e *Error) Error() string { if e.Line != 0 { - return fmt.Sprintf("exp/template/html:%s:%d: %s", e.Name, e.Line, e.Description) + return fmt.Sprintf("html/template:%s:%d: %s", e.Name, e.Line, e.Description) } else if e.Name != "" { - return fmt.Sprintf("exp/template/html:%s: %s", e.Name, e.Description) + return fmt.Sprintf("html/template:%s: %s", e.Name, e.Description) } - return "exp/template/html: " + e.Description + return "html/template: " + e.Description } // errorf creates an error given a format string f and args. diff --git a/libgo/go/html/template/escape.go b/libgo/go/html/template/escape.go index 2f6be3b6c21..c6f723ae4a4 100644 --- a/libgo/go/html/template/escape.go +++ b/libgo/go/html/template/escape.go @@ -486,9 +486,17 @@ func (e *escaper) escapeTree(c context, name string, line int) (context, string) } t := e.template(name) if t == nil { + // Two cases: The template exists but is empty, or has never been mentioned at + // all. Distinguish the cases in the error messages. + if e.tmpl.set[name] != nil { + return context{ + state: stateError, + err: errorf(ErrNoSuchTemplate, line, "%q is an incomplete or empty template", name), + }, dname + } return context{ state: stateError, - err: errorf(ErrNoSuchTemplate, line, "no such template %s", name), + err: errorf(ErrNoSuchTemplate, line, "no such template %q", name), }, dname } if dname != name { diff --git a/libgo/go/html/template/escape_test.go b/libgo/go/html/template/escape_test.go index 2d15c718448..a57f9826b5b 100644 --- a/libgo/go/html/template/escape_test.go +++ b/libgo/go/html/template/escape_test.go @@ -928,7 +928,7 @@ func TestErrors(t *testing.T) { }, { `{{template "foo"}}`, - "z:1: no such template foo", + "z:1: no such template \"foo\"", }, { `<div{{template "y"}}>` + @@ -944,23 +944,23 @@ func TestErrors(t *testing.T) { }, { `<input type=button value=onclick=>`, - `exp/template/html:z: "=" in unquoted attr: "onclick="`, + `html/template:z: "=" in unquoted attr: "onclick="`, }, { `<input type=button value= onclick=>`, - `exp/template/html:z: "=" in unquoted attr: "onclick="`, + `html/template:z: "=" in unquoted attr: "onclick="`, }, { `<input type=button value= 1+1=2>`, - `exp/template/html:z: "=" in unquoted attr: "1+1=2"`, + `html/template:z: "=" in unquoted attr: "1+1=2"`, }, { "<a class=`foo>", - "exp/template/html:z: \"`\" in unquoted attr: \"`foo\"", + "html/template:z: \"`\" in unquoted attr: \"`foo\"", }, { `<a style=font:'Arial'>`, - `exp/template/html:z: "'" in unquoted attr: "font:'Arial'"`, + `html/template:z: "'" in unquoted attr: "font:'Arial'"`, }, { `<a=foo>`, |

