Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/golang.org/x/net-0.23.0
Browse files Browse the repository at this point in the history
  • Loading branch information
paulsmith authored Oct 11, 2024
2 parents 9198ac5 + 530852a commit 5bee330
Show file tree
Hide file tree
Showing 19 changed files with 551 additions and 105 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golang-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.23"
check-latest: true

- name: golangci-lint
Expand Down
1 change: 1 addition & 0 deletions ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ type nodeElement struct {
startTagNodes []node
children []node
pos span
selfClosing bool
}

func (e nodeElement) Pos() span { return e.pos }
Expand Down
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
description = "Pushup is a new web framework for Go";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

outputs = { self, nixpkgs }:
let
Expand Down Expand Up @@ -46,25 +46,30 @@
};

in {
default = pkgs.buildGoModule rec {
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/go/module.nix
default = pkgs.buildGoModule.override {
go = pkgs.go_1_23;
} rec {
inherit pname version src vendorHash subPackages CGO_ENABLED meta;
};

withGo = pkgs.buildGoModule rec {
withGo = pkgs.buildGoModule.override {
go = pkgs.go_1_23;
} rec {
inherit pname version src vendorHash subPackages CGO_ENABLED meta;
nativeBuildInputs = with pkgs; [ makeWrapper ];
allowGoReference = true;
postInstall = ''
wrapProgram $out/bin/${pname} --prefix PATH : ${
pkgs.lib.makeBinPath (with pkgs; [ go ])
pkgs.lib.makeBinPath (with pkgs; [ go_1_23 ])
}
'';
};
});

devShells = forEachSystem ({ pkgs, ... }: {
default =
pkgs.mkShell { buildInputs = with pkgs; [ go_1_20 gotools gopls ]; };
pkgs.mkShell { buildInputs = with pkgs; [ go_1_23 gotools gopls ]; };
});
};
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/adhocteam/pushup

go 1.20
go 1.23

require (
github.com/fsnotify/fsnotify v1.5.4
github.com/google/go-cmp v0.5.8
golang.org/x/mod v0.7.0
golang.org/x/net v0.23.0
golang.org/x/mod v0.21.0
golang.org/x/net v0.17.0
golang.org/x/sync v0.1.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func setBuildFlags(flags *flag.FlagSet, b *buildCmd) {
flags.StringVar(&b.outDir, "out-dir", "./build", "path to output build directory. Defaults to ./build")
flags.StringVar(&b.outFile, "out-file", "", "path to output application binary. Defaults to ./build/bin/projectName")
flags.BoolVar(&b.embedSource, "embed-source", true, "embed the source .up files in executable")
flags.Var(&b.pages, "page", "path to a Pushup page. mulitple can be given")
flags.Var(&b.pages, "page", "path to a Pushup page. multiple can be given")
flags.BoolVar(&b.verbose, "verbose", false, "output verbose information")
}

Expand Down
62 changes: 45 additions & 17 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,23 +420,35 @@ func newTag(tagname []byte, attrs []*attr) tag {
return tag{name: string(tagname), attrs: attrs}
}

func (p *htmlParser) match(typ html.TokenType) bool {
return p.toktyp == typ
func (p *htmlParser) match(types ...html.TokenType) bool {
for _, typ := range types {
if p.toktyp == typ {
return true
}
}
return false
}

func (p *htmlParser) parseElement() node {
var result *nodeElement

// FIXME(paulsmith): handle self-closing elements
if !p.match(html.StartTagToken) {
p.errorf("expected an HTML element start tag, got %s", p.toktyp)
if !p.match(html.StartTagToken, html.SelfClosingTagToken) {
p.errorf("expected an HTML element start or self-closing tag, got %s", p.toktyp)
}

result = new(nodeElement)
result.tag = newTag(p.tagname, p.attrs)
result.pos.start = p.parser.offset - len(p.raw)
result.pos.end = p.parser.offset
if p.match(html.SelfClosingTagToken) {
result.selfClosing = true
}
result.startTagNodes = p.parseStartTag()

if isVoidElement(result.tag.name) {
return result
}

p.advance()

result.children = p.parseChildren()
Expand All @@ -462,31 +474,28 @@ func (p *htmlParser) parseChildren() []node {
var elemStack []*nodeElement
loop:
for {
switch p.toktyp {
switch tt := p.toktyp; tt {
case html.ErrorToken:
if p.err == io.EOF {
break loop
} else {
p.errorf("HTML tokenizer: %w", p.err)
}
case html.SelfClosingTagToken:
elem := new(nodeElement)
elem.tag = newTag(p.tagname, p.attrs)
elem.pos.start = p.parser.offset - len(p.raw)
elem.pos.end = p.parser.offset
elem.startTagNodes = p.parseStartTag()
p.advance()
result = append(result, elem)
case html.StartTagToken:
case html.StartTagToken, html.SelfClosingTagToken:
elem := new(nodeElement)
elem.tag = newTag(p.tagname, p.attrs)
elem.pos.start = p.parser.offset - len(p.raw)
elem.pos.end = p.parser.offset
elem.startTagNodes = p.parseStartTag()
if tt == html.SelfClosingTagToken {
elem.selfClosing = true
}
p.advance()
elem.children = p.parseChildren()
if !isVoidElement(elem.tag.name) {
elem.children = p.parseChildren()
elemStack = append(elemStack, elem)
}
result = append(result, elem)
elemStack = append(elemStack, elem)
case html.EndTagToken:
if len(elemStack) == 0 {
return result
Expand Down Expand Up @@ -534,6 +543,25 @@ loop:
return result
}

func isVoidElement(tagname string) bool {
// Per spec: https://html.spec.whatwg.org/multipage/syntax.html#void-elements
voidElements := map[string]bool{"area": true,
"base": true,
"br": true,
"col": true,
"embed": true,
"hr": true,
"img": true,
"input": true,
"link": true,
"meta": true,
"source": true,
"track": true,
"wbr": true,
}
return voidElements[tagname]
}

type Optional[T any] struct {
value *T
}
Expand Down
23 changes: 22 additions & 1 deletion parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,27 @@ func TestParse(t *testing.T) {
},
},
},
{
`^if true { <br/> }`,
&syntaxTree{
nodes: []node{
&nodeIf{
cond: &nodeGoStrExpr{expr: "true", pos: span{start: 4, end: 8}},
then: &nodeBlock{
nodes: []node{
&nodeLiteral{str: " ", pos: span{10, 11}},
&nodeElement{
tag: tag{name: "br"},
startTagNodes: []node{&nodeLiteral{str: "<br/>", pos: span{start: 11, end: 16}}},
pos: span{11, 16},
selfClosing: true,
},
},
},
},
},
},
},
}
opts := cmp.AllowUnexported(unexported...)
for _, test := range tests {
Expand Down Expand Up @@ -450,7 +471,7 @@ func TestParseSyntaxErrors(t *testing.T) {
{
`^if true {
<illegal />
}`, 2, 13,
}`, 3, 2,
},
// FIXME(paulsmith): add more syntax errors
}
Expand Down
4 changes: 2 additions & 2 deletions vendor/golang.org/x/mod/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/golang.org/x/mod/internal/lazyregexp/lazyre.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions vendor/golang.org/x/mod/modfile/print.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions vendor/golang.org/x/mod/modfile/read.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5bee330

Please sign in to comment.