diff --git a/.gitignore b/.gitignore
index cfdf953..1190f2e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,7 +3,7 @@ _htmlab
.gop
coverage.txt
index.htm
-gop_autogen*.go
+# gop_autogen*.go
# Binaries for programs and plugins
*.exe
diff --git a/chore/pysigfetch/gop_autogen.go b/chore/pysigfetch/gop_autogen.go
new file mode 100644
index 0000000..7bcfaea
--- /dev/null
+++ b/chore/pysigfetch/gop_autogen.go
@@ -0,0 +1,8 @@
+// Code generated by gop (Go+); DO NOT EDIT.
+
+package main
+
+const _ = true
+
+func main() {
+}
diff --git a/chore/pysigfetch/pysigfetch.gop b/chore/pysigfetch/pysigfetch.gop
new file mode 100644
index 0000000..e69de29
diff --git a/hdq.go b/hdq.go
index d4765d7..22bd6d1 100644
--- a/hdq.go
+++ b/hdq.go
@@ -1,14 +1,16 @@
/*
- Copyright 2021 The GoPlus Authors (goplus.org)
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+Copyright 2021 The GoPlus Authors (goplus.org)
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
*/
package hdq
diff --git a/hdq_helper.go b/hdq_helper.go
index d712cc0..83d1086 100644
--- a/hdq_helper.go
+++ b/hdq_helper.go
@@ -1,14 +1,16 @@
/*
- Copyright 2021 The GoPlus Authors (goplus.org)
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+Copyright 2021 The GoPlus Authors (goplus.org)
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
*/
package hdq
@@ -176,6 +178,16 @@ func (p NodeSet) Ul() (ret NodeSet) {
return p.dataAtom(atom.Ul)
}
+// Dl returns NodeSet which node type is ElementNode and it's element type is `dl`.
+func (p NodeSet) Dl() (ret NodeSet) {
+ return p.dataAtom(atom.Dl)
+}
+
+// Dt returns NodeSet which node type is ElementNode and it's element type is `dt`.
+func (p NodeSet) Dt() (ret NodeSet) {
+ return p.dataAtom(atom.Dt)
+}
+
// Span returns NodeSet which node type is ElementNode and it's element type is `span`.
func (p NodeSet) Span() (ret NodeSet) {
return p.dataAtom(atom.Span)
diff --git a/hdqtest/hdqtest.go b/hdqtest/hdqtest.go
new file mode 100644
index 0000000..f15db7f
--- /dev/null
+++ b/hdqtest/hdqtest.go
@@ -0,0 +1,80 @@
+/*
+Copyright 2024 The GoPlus Authors (goplus.org)
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package hdqtest
+
+import (
+ "encoding/json"
+ "log"
+ "os"
+ "path"
+ "reflect"
+ "strings"
+ "testing"
+
+ "github.com/goplus/hdq"
+)
+
+// func(doc hdq.NodeSet) any
+type Converter = any
+
+// FromDir tests all html files in a directory.
+func FromDir(t *testing.T, sel, relDir string, conv Converter) {
+ dir, err := os.Getwd()
+ if err != nil {
+ t.Fatal("Getwd failed:", err)
+ }
+ dir = path.Join(dir, relDir)
+ fis, err := os.ReadDir(dir)
+ if err != nil {
+ t.Fatal("ReadDir failed:", err)
+ }
+ vConv := reflect.ValueOf(conv)
+ for _, fi := range fis {
+ name := fi.Name()
+ if !fi.IsDir() || strings.HasPrefix(name, "_") {
+ continue
+ }
+ t.Run(name, func(t *testing.T) {
+ testFrom(t, dir+"/"+name, sel, vConv)
+ })
+ }
+}
+
+func testFrom(t *testing.T, pkgDir, sel string, conv reflect.Value) {
+ if sel != "" && !strings.Contains(pkgDir, sel) {
+ return
+ }
+ log.Println("Parsing", pkgDir)
+ in := pkgDir + "/in.html"
+ out := pkgDir + "/out.json"
+ b, err := os.ReadFile(out)
+ if err != nil {
+ t.Fatal("ReadFile failed:", err)
+ }
+ expected := string(b)
+ ret := ConvFile(in, conv)
+ retb, _ := json.MarshalIndent(ret, "", "\t")
+ if v := string(retb); v != expected {
+ t.Fatalf("\n==> got:\n%s\n==> expected:\n%s\n", v, expected)
+ }
+}
+
+// ConvFile converts a html source to an object.
+func ConvFile(in any, conv reflect.Value) any {
+ doc := reflect.ValueOf(hdq.Source(in))
+ out := conv.Call([]reflect.Value{doc})
+ return out[0].Interface()
+}
diff --git a/html_utils.go b/html_utils.go
index b594128..26c0e5c 100644
--- a/html_utils.go
+++ b/html_utils.go
@@ -1,14 +1,16 @@
/*
- Copyright 2021 The GoPlus Authors (goplus.org)
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+Copyright 2021 The GoPlus Authors (goplus.org)
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
*/
package hdq
@@ -142,7 +144,7 @@ func (p *textPrinter) printNode(node *html.Node) {
return
}
if node.Type == html.TextNode {
- p.printText(strings.Trim(node.Data, " \t\r\n"))
+ p.printText(strings.Trim(node.Data, " \t\r\n¶"))
return
}
for child := node.FirstChild; child != nil; child = child.NextSibling {
diff --git a/pysig/torch/_testdata/eye/in.html b/pysig/torch/_testdata/eye/in.html
new file mode 100644
index 0000000..b973bab
--- /dev/null
+++ b/pysig/torch/_testdata/eye/in.html
@@ -0,0 +1,909 @@
+
+
+
+
+
+
+
dtype (torch.dtype, optional) – the desired data type of returned tensor.
+Default: if None, uses a global default (see torch.set_default_dtype()).
+
layout (torch.layout, optional) – the desired layout of returned Tensor.
+Default: torch.strided.
+
device (torch.device, optional) – the desired device of returned tensor.
+Default: if None, uses the current device for the default tensor type
+(see torch.set_default_device()). device will be the CPU
+for CPU tensor types and the current CUDA device for CUDA tensor types.
+
requires_grad (bool, optional) – If autograd should record operations on the
+returned tensor. Default: False.
+
+
+
Returns
+
A 2-D tensor with ones on the diagonal and zeros elsewhere
To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pysig/torch/_testdata/eye/out.json b/pysig/torch/_testdata/eye/out.json
new file mode 100644
index 0000000..781cc15
--- /dev/null
+++ b/pysig/torch/_testdata/eye/out.json
@@ -0,0 +1,5 @@
+{
+ "name": "eye",
+ "doc": "",
+ "sig": "( n , m = None , * , out = None , dtype = None , layout = torch.strided , device = None , requires_grad = False ) → Tensor"
+}
\ No newline at end of file
diff --git a/pysig/torch/gop_autogen.go b/pysig/torch/gop_autogen.go
new file mode 100644
index 0000000..1b0e288
--- /dev/null
+++ b/pysig/torch/gop_autogen.go
@@ -0,0 +1,52 @@
+// Code generated by gop (Go+); DO NOT EDIT.
+
+package torch
+
+import (
+ "github.com/goplus/hdq"
+ "github.com/qiniu/x/errors"
+ "strings"
+)
+
+const GopPackage = "github.com/goplus/hdq"
+const _ = true
+
+type Result struct {
+ Name string `json:"name"`
+ Doc string `json:"doc"`
+ Sig string `json:"sig"`
+}
+//line pysig/torch/pysig_torch.gop:32:1
+func New(doc hdq.NodeSet) Result {
+//line pysig/torch/pysig_torch.gop:33:1
+ fn := doc.Any().Dl().Class("py function")
+//line pysig/torch/pysig_torch.gop:34:1
+ decl := func() (_gop_ret string) {
+//line pysig/torch/pysig_torch.gop:34:1
+ var _gop_err error
+//line pysig/torch/pysig_torch.gop:34:1
+ _gop_ret, _gop_err = fn.FirstElementChild().Dt().Text__0()
+//line pysig/torch/pysig_torch.gop:34:1
+ if _gop_err != nil {
+//line pysig/torch/pysig_torch.gop:34:1
+ _gop_err = errors.NewFrame(_gop_err, "fn.firstElementChild.dt.text", "pysig/torch/pysig_torch.gop", 34, "torch.New")
+//line pysig/torch/pysig_torch.gop:34:1
+ panic(_gop_err)
+ }
+//line pysig/torch/pysig_torch.gop:34:1
+ return
+ }()
+//line pysig/torch/pysig_torch.gop:35:1
+ pos := strings.IndexByte(decl, '(')
+//line pysig/torch/pysig_torch.gop:36:1
+ if pos > 0 {
+//line pysig/torch/pysig_torch.gop:37:1
+ name := strings.TrimPrefix(decl[:pos], "torch.")
+//line pysig/torch/pysig_torch.gop:38:1
+ sig := decl[pos:]
+//line pysig/torch/pysig_torch.gop:39:1
+ return Result{strings.TrimSpace(name), "", strings.TrimSpace(sig)}
+ }
+//line pysig/torch/pysig_torch.gop:41:1
+ return Result{"", "", ""}
+}
diff --git a/pysig/torch/pysig_torch.gop b/pysig/torch/pysig_torch.gop
new file mode 100644
index 0000000..b5963c2
--- /dev/null
+++ b/pysig/torch/pysig_torch.gop
@@ -0,0 +1,42 @@
+/*
+Copyright 2024 The GoPlus Authors (goplus.org)
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package torch
+
+import (
+ "strings"
+
+ "github.com/goplus/hdq"
+)
+
+// -----------------------------------------------------------------------------
+
+type Result struct {
+ Name string `json:"name"`
+ Doc string `json:"doc"`
+ Sig string `json:"sig"`
+}
+
+func New(doc hdq.NodeSet) Result {
+ fn := doc.any.dl.class("py function")
+ decl := fn.firstElementChild.dt.text!
+ pos := strings.indexByte(decl, '(')
+ if pos > 0 {
+ name := strings.trimPrefix(decl[:pos], "torch.")
+ sig := decl[pos:]
+ return {strings.trimSpace(name), "", strings.trimSpace(sig)}
+ }
+ return {"", "", ""}
+}
diff --git a/pysig/torch/pysig_torch_test.go b/pysig/torch/pysig_torch_test.go
new file mode 100644
index 0000000..cae55ca
--- /dev/null
+++ b/pysig/torch/pysig_torch_test.go
@@ -0,0 +1,26 @@
+/*
+Copyright 2024 The GoPlus Authors (goplus.org)
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package torch
+
+import (
+ "testing"
+
+ "github.com/goplus/hdq/hdqtest"
+)
+
+func TestTestdata(t *testing.T) {
+ hdqtest.FromDir(t, "", "./_testdata", New)
+}
diff --git a/stream/http/httpstrm.go b/stream/http/httpstrm.go
index bcfe956..be0dcc3 100644
--- a/stream/http/httpstrm.go
+++ b/stream/http/httpstrm.go
@@ -1,14 +1,16 @@
/*
- Copyright 2021 The GoPlus Authors (goplus.org)
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+Copyright 2021 The GoPlus Authors (goplus.org)
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
*/
package http
diff --git a/stream/stream.go b/stream/stream.go
index 1ca242b..0bfcf4c 100644
--- a/stream/stream.go
+++ b/stream/stream.go
@@ -1,14 +1,16 @@
/*
- Copyright 2021 The GoPlus Authors (goplus.org)
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+Copyright 2021 The GoPlus Authors (goplus.org)
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
*/
package stream
diff --git a/stream/stream_test.go b/stream/stream_test.go
index 683fcc9..e1754aa 100644
--- a/stream/stream_test.go
+++ b/stream/stream_test.go
@@ -1,14 +1,16 @@
/*
- Copyright 2021 The GoPlus Authors (goplus.org)
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+Copyright 2021 The GoPlus Authors (goplus.org)
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
*/
package stream
diff --git a/stream/zip/zipstrm.go b/stream/zip/zipstrm.go
index 289c8d8..b9d36e0 100644
--- a/stream/zip/zipstrm.go
+++ b/stream/zip/zipstrm.go
@@ -1,14 +1,16 @@
/*
- Copyright 2021 The GoPlus Authors (goplus.org)
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+Copyright 2021 The GoPlus Authors (goplus.org)
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
*/
package zip
diff --git a/tutorial/01-Links/gop_autogen.go b/tutorial/01-Links/gop_autogen.go
new file mode 100644
index 0000000..63c5993
--- /dev/null
+++ b/tutorial/01-Links/gop_autogen.go
@@ -0,0 +1,51 @@
+// Code generated by gop (Go+); DO NOT EDIT.
+
+package main
+
+import (
+ "fmt"
+ "github.com/goplus/hdq"
+)
+
+const _ = true
+//line tutorial/01-Links/links.gop:6:1
+func links(r interface{}) []string {
+//line tutorial/01-Links/links.gop:7:1
+ doc := hdq.Source(r)
+//line tutorial/01-Links/links.gop:8:1
+ return func() (_gop_ret []string) {
+//line tutorial/01-Links/links.gop:8:1
+ doc.Any().A().Gop_Enum(func(a hdq.NodeSet) {
+//line tutorial/01-Links/links.gop:8:1
+ if
+//line tutorial/01-Links/links.gop:8:1
+ link := func() (_gop_ret string) {
+//line tutorial/01-Links/links.gop:8:1
+ var _gop_err error
+//line tutorial/01-Links/links.gop:8:1
+ _gop_ret, _gop_err = a.Href__0()
+//line tutorial/01-Links/links.gop:8:1
+ if _gop_err != nil {
+//line tutorial/01-Links/links.gop:8:1
+ return ""
+ }
+//line tutorial/01-Links/links.gop:8:1
+ return
+ }(); link != "" {
+//line tutorial/01-Links/links.gop:8:1
+ _gop_ret = append(_gop_ret, link)
+ }
+ })
+//line tutorial/01-Links/links.gop:8:1
+ return
+ }()
+}
+//line tutorial/01-Links/links.gop:11
+func main() {
+ for
+//line tutorial/01-Links/links.gop:11:1
+ _, link := range links("zip://../02-GithubRepos/data.zip#index.htm") {
+//line tutorial/01-Links/links.gop:12:1
+ fmt.Println(link)
+ }
+}
diff --git a/tutorial/02-GithubRepos/gop_autogen.go b/tutorial/02-GithubRepos/gop_autogen.go
new file mode 100644
index 0000000..8cb3d89
--- /dev/null
+++ b/tutorial/02-GithubRepos/gop_autogen.go
@@ -0,0 +1,152 @@
+// Code generated by gop (Go+); DO NOT EDIT.
+
+package repos
+
+import (
+ "github.com/goplus/hdq"
+ "github.com/qiniu/x/errors"
+)
+
+const GopPackage = "github.com/goplus/hdq"
+const _ = true
+
+type Repo struct {
+ Repo string
+ ForkedFrom string
+ Title string
+ Language string
+ UpdateTime string
+ Forks int
+}
+type Result struct {
+ Repos []Repo
+ Next string
+}
+//line tutorial/02-GithubRepos/repos.gop:18:1
+func newRepo(node hdq.NodeSet) Repo {
+//line tutorial/02-GithubRepos/repos.gop:19:1
+ aRepo := node.Any().A().Attr__1("itemprop", "name codeRepository").One()
+//line tutorial/02-GithubRepos/repos.gop:20:1
+ repo := func() (_gop_ret string) {
+//line tutorial/02-GithubRepos/repos.gop:20:1
+ var _gop_err error
+//line tutorial/02-GithubRepos/repos.gop:20:1
+ _gop_ret, _gop_err = aRepo.Href__0()
+//line tutorial/02-GithubRepos/repos.gop:20:1
+ if _gop_err != nil {
+//line tutorial/02-GithubRepos/repos.gop:20:1
+ _gop_err = errors.NewFrame(_gop_err, "aRepo.href", "tutorial/02-GithubRepos/repos.gop", 20, "repos.newRepo")
+//line tutorial/02-GithubRepos/repos.gop:20:1
+ panic(_gop_err)
+ }
+//line tutorial/02-GithubRepos/repos.gop:20:1
+ return
+ }()
+//line tutorial/02-GithubRepos/repos.gop:21:1
+ root := aRepo.ParentN(3).One()
+//line tutorial/02-GithubRepos/repos.gop:22:1
+ forkedFrom := func() (_gop_ret string) {
+//line tutorial/02-GithubRepos/repos.gop:22:1
+ var _gop_err error
+//line tutorial/02-GithubRepos/repos.gop:22:1
+ _gop_ret, _gop_err = root.Any().Span().Any().TextContains("Forked from").One().NextSibling(1).A().Href__0()
+//line tutorial/02-GithubRepos/repos.gop:22:1
+ if _gop_err != nil {
+//line tutorial/02-GithubRepos/repos.gop:22:1
+ return ""
+ }
+//line tutorial/02-GithubRepos/repos.gop:22:1
+ return
+ }()
+//line tutorial/02-GithubRepos/repos.gop:23:1
+ title := func() (_gop_ret string) {
+//line tutorial/02-GithubRepos/repos.gop:23:1
+ var _gop_err error
+//line tutorial/02-GithubRepos/repos.gop:23:1
+ _gop_ret, _gop_err = root.Any().P().Attr__1("itemprop", "description").Text__0()
+//line tutorial/02-GithubRepos/repos.gop:23:1
+ if _gop_err != nil {
+//line tutorial/02-GithubRepos/repos.gop:23:1
+ return ""
+ }
+//line tutorial/02-GithubRepos/repos.gop:23:1
+ return
+ }()
+//line tutorial/02-GithubRepos/repos.gop:24:1
+ language := func() (_gop_ret string) {
+//line tutorial/02-GithubRepos/repos.gop:24:1
+ var _gop_err error
+//line tutorial/02-GithubRepos/repos.gop:24:1
+ _gop_ret, _gop_err = root.Any().Span().Attr__1("itemprop", "programmingLanguage").One().Text__0()
+//line tutorial/02-GithubRepos/repos.gop:24:1
+ if _gop_err != nil {
+//line tutorial/02-GithubRepos/repos.gop:24:1
+ return ""
+ }
+//line tutorial/02-GithubRepos/repos.gop:24:1
+ return
+ }()
+//line tutorial/02-GithubRepos/repos.gop:25:1
+ updateTime := func() (_gop_ret string) {
+//line tutorial/02-GithubRepos/repos.gop:25:1
+ var _gop_err error
+//line tutorial/02-GithubRepos/repos.gop:25:1
+ _gop_ret, _gop_err = root.Any().Element("relative-time").One().Attr__0("datetime")
+//line tutorial/02-GithubRepos/repos.gop:25:1
+ if _gop_err != nil {
+//line tutorial/02-GithubRepos/repos.gop:25:1
+ return ""
+ }
+//line tutorial/02-GithubRepos/repos.gop:25:1
+ return
+ }()
+//line tutorial/02-GithubRepos/repos.gop:26:1
+ forks := func() (_gop_ret int) {
+//line tutorial/02-GithubRepos/repos.gop:26:1
+ var _gop_err error
+//line tutorial/02-GithubRepos/repos.gop:26:1
+ _gop_ret, _gop_err = root.Any().A().Attr__1("href", repo+"/network/members").Int__0()
+//line tutorial/02-GithubRepos/repos.gop:26:1
+ if _gop_err != nil {
+//line tutorial/02-GithubRepos/repos.gop:26:1
+ return 0
+ }
+//line tutorial/02-GithubRepos/repos.gop:26:1
+ return
+ }()
+//line tutorial/02-GithubRepos/repos.gop:27:1
+ return Repo{Repo: repo, ForkedFrom: forkedFrom, Title: title, Language: language, UpdateTime: updateTime, Forks: forks}
+}
+//line tutorial/02-GithubRepos/repos.gop:44:1
+func New(doc hdq.NodeSet) Result {
+//line tutorial/02-GithubRepos/repos.gop:45:1
+ divRepos := doc.Any().Div().Id("user-repositories-list").One()
+//line tutorial/02-GithubRepos/repos.gop:46:1
+ repoList := divRepos.Child().Ul().One()
+//line tutorial/02-GithubRepos/repos.gop:47:1
+ repos := func() (_gop_ret []Repo) {
+//line tutorial/02-GithubRepos/repos.gop:47:1
+ repoList.Child().Li().Gop_Enum(func(x hdq.NodeSet) {
+//line tutorial/02-GithubRepos/repos.gop:47:1
+ _gop_ret = append(_gop_ret, newRepo(x))
+ })
+//line tutorial/02-GithubRepos/repos.gop:47:1
+ return
+ }()
+//line tutorial/02-GithubRepos/repos.gop:48:1
+ next := func() (_gop_ret string) {
+//line tutorial/02-GithubRepos/repos.gop:48:1
+ var _gop_err error
+//line tutorial/02-GithubRepos/repos.gop:48:1
+ _gop_ret, _gop_err = doc.Any().Div().Class("paginate-container").One().Any().A().ChildEqualText("Next").Href__0()
+//line tutorial/02-GithubRepos/repos.gop:48:1
+ if _gop_err != nil {
+//line tutorial/02-GithubRepos/repos.gop:48:1
+ return ""
+ }
+//line tutorial/02-GithubRepos/repos.gop:48:1
+ return
+ }()
+//line tutorial/02-GithubRepos/repos.gop:49:1
+ return Result{Repos: repos, Next: next}
+}
diff --git a/tutorial/02-GithubRepos/gop_autogen_test.go b/tutorial/02-GithubRepos/gop_autogen_test.go
new file mode 100644
index 0000000..1820925
--- /dev/null
+++ b/tutorial/02-GithubRepos/gop_autogen_test.go
@@ -0,0 +1,276 @@
+// Code generated by gop (Go+); DO NOT EDIT.
+
+package repos
+
+import (
+ "encoding/json"
+ hdq1 "github.com/goplus/hdq"
+ "testing"
+)
+
+const outTestNew = `{
+ "Repos": [
+ {
+ "Repo": "/xushiwei/linguist",
+ "ForkedFrom": "/github/linguist",
+ "Title": "Language Savant. If your repository's language is being reported incorrectly, send us a pull request!\n",
+ "Language": "Ruby",
+ "UpdateTime": "2021-08-08T17:39:30Z",
+ "Forks": 3221
+ },
+ {
+ "Repo": "/xushiwei/x",
+ "ForkedFrom": "/qiniu/x",
+ "Title": "Extension of go standard library\n",
+ "Language": "Go",
+ "UpdateTime": "2021-08-04T16:37:08Z",
+ "Forks": 16
+ },
+ {
+ "Repo": "/xushiwei/fyne",
+ "ForkedFrom": "/fyne-io/fyne",
+ "Title": "Cross platform GUI in Go based on Material Design\n",
+ "Language": "Go",
+ "UpdateTime": "2021-07-27T11:26:17Z",
+ "Forks": 726
+ },
+ {
+ "Repo": "/xushiwei/qlang",
+ "ForkedFrom": "/goplus/gop",
+ "Title": "Q Language - A script language for Go\n",
+ "Language": "Go",
+ "UpdateTime": "2021-07-20T22:00:43Z",
+ "Forks": 384
+ },
+ {
+ "Repo": "/xushiwei/winfsp",
+ "ForkedFrom": "/billziss-gh/winfsp",
+ "Title": "Windows File System Proxy - FUSE for Windows\n",
+ "Language": "C",
+ "UpdateTime": "2021-02-03T00:51:42Z",
+ "Forks": 320
+ },
+ {
+ "Repo": "/xushiwei/embeddedgo",
+ "ForkedFrom": "/embeddedgo/go",
+ "Title": "The Go programming language with support for bare-matal programing\n",
+ "Language": "Go",
+ "UpdateTime": "2020-12-31T16:37:34Z",
+ "Forks": 13037
+ },
+ {
+ "Repo": "/xushiwei/oak",
+ "ForkedFrom": "/oakmound/oak",
+ "Title": "A pure Go game engine\n",
+ "Language": "Go",
+ "UpdateTime": "2020-08-04T01:28:32Z",
+ "Forks": 58
+ },
+ {
+ "Repo": "/xushiwei/GhostDB",
+ "ForkedFrom": "/jakekgrog/GhostDB",
+ "Title": "GhostDB is a distributed, in-memory, general purpose key-value data store that delivers microsecond performance at any scale.\n",
+ "Language": "Go",
+ "UpdateTime": "2020-08-01T10:58:55Z",
+ "Forks": 35
+ },
+ {
+ "Repo": "/xushiwei/DeepLearning-500-questions",
+ "ForkedFrom": "/scutan90/DeepLearning-500-questions",
+ "Title": "深度学习500问,以问答形式对常用的概率知识、线性代数、机器学习、深度学习、计算机视觉等热点问题进行阐述,以帮助自己及有需要的读者。 全书分为18个章节,50余万字。由于水平有限,书中不妥之处恳请广大读者批评指正。 未完待续............ 如有意合作,联系scutjy2015@163.com 版权所有,违权必究 Tan 2018.06\n",
+ "Language": "",
+ "UpdateTime": "2020-07-20T12:06:41Z",
+ "Forks": 14227
+ },
+ {
+ "Repo": "/xushiwei/simdjson-go",
+ "ForkedFrom": "/minio/simdjson-go",
+ "Title": "Golang port of simdjson: parsing gigabytes of JSON per second\n",
+ "Language": "Go",
+ "UpdateTime": "2020-06-26T22:23:56Z",
+ "Forks": 59
+ },
+ {
+ "Repo": "/xushiwei/Paddle",
+ "ForkedFrom": "/PaddlePaddle/Paddle",
+ "Title": "PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习\u0026机器学习高性能单机、分布式训练和跨平台部署)\n",
+ "Language": "C++",
+ "UpdateTime": "2020-06-21T15:35:31Z",
+ "Forks": 3953
+ },
+ {
+ "Repo": "/xushiwei/gorgonia",
+ "ForkedFrom": "/gorgonia/gorgonia",
+ "Title": "Gorgonia is a library that helps facilitate machine learning in Go.\n",
+ "Language": "Go",
+ "UpdateTime": "2020-06-20T08:32:36Z",
+ "Forks": 359
+ },
+ {
+ "Repo": "/xushiwei/caire",
+ "ForkedFrom": "/esimov/caire",
+ "Title": "Content aware image resize library\n",
+ "Language": "Go",
+ "UpdateTime": "2020-06-18T08:10:21Z",
+ "Forks": 360
+ },
+ {
+ "Repo": "/xushiwei/goplus-play",
+ "ForkedFrom": "/visualfc/goplus-play",
+ "Title": "Playground of the Go+ language\n",
+ "Language": "JavaScript",
+ "UpdateTime": "2020-06-17T15:40:34Z",
+ "Forks": 2
+ },
+ {
+ "Repo": "/xushiwei/bpl",
+ "ForkedFrom": "/qiniu/bpl",
+ "Title": "Binary Processing Language\n",
+ "Language": "Go",
+ "UpdateTime": "2020-06-07T14:40:37Z",
+ "Forks": 28
+ },
+ {
+ "Repo": "/xushiwei/c2goasm",
+ "ForkedFrom": "/minio/c2goasm",
+ "Title": "C to Go Assembly\n",
+ "Language": "Go",
+ "UpdateTime": "2020-06-04T02:52:47Z",
+ "Forks": 92
+ },
+ {
+ "Repo": "/xushiwei/asm2plan9s",
+ "ForkedFrom": "/minio/asm2plan9s",
+ "Title": "Tool to generate BYTE sequences for Go assembly as generated by YASM\n",
+ "Language": "Go",
+ "UpdateTime": "2020-06-04T00:32:38Z",
+ "Forks": 31
+ },
+ {
+ "Repo": "/xushiwei/scipy",
+ "ForkedFrom": "/scipy/scipy",
+ "Title": "Scipy library main repository\n",
+ "Language": "Python",
+ "UpdateTime": "2020-05-24T16:58:25Z",
+ "Forks": 3826
+ },
+ {
+ "Repo": "/xushiwei/sympy",
+ "ForkedFrom": "/sympy/sympy",
+ "Title": "A computer algebra system written in pure Python\n",
+ "Language": "Python",
+ "UpdateTime": "2020-05-24T12:35:57Z",
+ "Forks": 3435
+ },
+ {
+ "Repo": "/xushiwei/matplotlib",
+ "ForkedFrom": "/matplotlib/matplotlib",
+ "Title": "matplotlib: plotting with Python\n",
+ "Language": "Python",
+ "UpdateTime": "2020-05-24T00:49:40Z",
+ "Forks": 5961
+ },
+ {
+ "Repo": "/xushiwei/notebook",
+ "ForkedFrom": "/jupyter/notebook",
+ "Title": "Jupyter Interactive Notebook\n",
+ "Language": "JavaScript",
+ "UpdateTime": "2020-05-23T00:20:16Z",
+ "Forks": 3473
+ },
+ {
+ "Repo": "/xushiwei/jax",
+ "ForkedFrom": "/google/jax",
+ "Title": "Composable transformations of Python+NumPy programs: differentiate, vectorize, JIT to GPU/TPU, and more\n",
+ "Language": "Python",
+ "UpdateTime": "2020-05-22T06:56:01Z",
+ "Forks": 1288
+ },
+ {
+ "Repo": "/xushiwei/flax",
+ "ForkedFrom": "/google/flax",
+ "Title": "Flax is a neural network library for JAX that is designed for flexibility.\n",
+ "Language": "Python",
+ "UpdateTime": "2020-05-21T22:57:17Z",
+ "Forks": 249
+ },
+ {
+ "Repo": "/xushiwei/liner",
+ "ForkedFrom": "/peterh/liner",
+ "Title": "Pure Go line editor with history, inspired by linenoise\n",
+ "Language": "Go",
+ "UpdateTime": "2020-05-16T16:24:21Z",
+ "Forks": 105
+ },
+ {
+ "Repo": "/xushiwei/query",
+ "ForkedFrom": "/couchbase/query",
+ "Title": "Query engine.\n",
+ "Language": "Go",
+ "UpdateTime": "2020-05-15T23:14:38Z",
+ "Forks": 41
+ },
+ {
+ "Repo": "/xushiwei/pandas",
+ "ForkedFrom": "/pandas-dev/pandas",
+ "Title": "Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more\n",
+ "Language": "Python",
+ "UpdateTime": "2020-05-13T20:43:46Z",
+ "Forks": 12866
+ },
+ {
+ "Repo": "/xushiwei/hugo",
+ "ForkedFrom": "/gohugoio/hugo",
+ "Title": "The world’s fastest framework for building websites.\n",
+ "Language": "Go",
+ "UpdateTime": "2020-05-13T19:44:45Z",
+ "Forks": 6086
+ },
+ {
+ "Repo": "/xushiwei/netlify-cms",
+ "ForkedFrom": "/netlify/netlify-cms",
+ "Title": "A Git-based CMS for Static Site Generators\n",
+ "Language": "JavaScript",
+ "UpdateTime": "2020-05-13T16:47:59Z",
+ "Forks": 2446
+ },
+ {
+ "Repo": "/xushiwei/presto",
+ "ForkedFrom": "/prestodb/presto",
+ "Title": "The official home of the Presto distributed SQL query engine for big data\n",
+ "Language": "Java",
+ "UpdateTime": "2020-05-13T01:19:32Z",
+ "Forks": 4234
+ },
+ {
+ "Repo": "/xushiwei/gonum",
+ "ForkedFrom": "/gonum/gonum",
+ "Title": "Gonum is a set of numeric libraries for the Go programming language. It contains libraries for matrices, statistics, optimization, and more\n",
+ "Language": "Go",
+ "UpdateTime": "2020-05-12T11:15:37Z",
+ "Forks": 409
+ }
+ ],
+ "Next": "https://github.com/xushiwei?after=Y3Vyc29yOnYyOpK0MjAyMC0wNS0xMlQxMToxNTozN1rOD7hDgA%3D%3D\u0026tab=repositories"
+}`
+//line tutorial/02-GithubRepos/repos_test.gop:256:1
+func TestNew(t *testing.T) {
+//line tutorial/02-GithubRepos/repos_test.gop:257:1
+ doc := hdq1.Source("zip://data.zip#index.htm")
+//line tutorial/02-GithubRepos/repos_test.gop:258:1
+ ret := New(doc)
+//line tutorial/02-GithubRepos/repos_test.gop:259:1
+ b, err := json.MarshalIndent(ret, "", "\t")
+//line tutorial/02-GithubRepos/repos_test.gop:260:1
+ if err != nil {
+//line tutorial/02-GithubRepos/repos_test.gop:261:1
+ t.Fatal("json.MarshalIndent:", err)
+ }
+//line tutorial/02-GithubRepos/repos_test.gop:263:1
+ out := string(b)
+//line tutorial/02-GithubRepos/repos_test.gop:264:1
+ if out != outTestNew {
+//line tutorial/02-GithubRepos/repos_test.gop:265:1
+ t.Fatal("TestNew failed:", out)
+ }
+}