Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the legalizer #438

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8b3b7d7
PR #437
mcy Jan 29, 2025
c6e445e
add Span.Len
mcy Jan 29, 2025
5a0be56
add new iterator helpers
mcy Jan 29, 2025
5c50385
add classifier methods for predeclared.Name
mcy Jan 29, 2025
c9309db
add an enum for syntax/edition values
mcy Jan 29, 2025
8dd79ae
add some new taxa.Nouns
mcy Jan 29, 2025
f40ec3c
ast additions
mcy Jan 29, 2025
453be0c
fix brackets not being recorded for compact options
mcy Jan 29, 2025
79bf0e0
update import parsing to catch more nested imports
mcy Jan 29, 2025
a469395
track if we're in edition mode
mcy Jan 29, 2025
2893908
add diagnostics for use in the legalizer
mcy Jan 29, 2025
e56474d
add new testdata files for use with the legalizer
mcy Jan 29, 2025
198a8bc
skeletonize the legalizer
mcy Jan 29, 2025
4c4129e
legalize syntax
mcy Jan 29, 2025
02ac466
legalize package
mcy Jan 29, 2025
96efead
legalize imports
mcy Jan 29, 2025
8603323
legalize against bare braces
mcy Jan 29, 2025
ce87eb6
legalize ranges
mcy Jan 29, 2025
e138256
legalize parent relationships for defs
mcy Jan 29, 2025
35f4923
legalize messages and friends
mcy Jan 29, 2025
f796024
legalize fields
mcy Jan 29, 2025
0eb82c2
legalize options
mcy Jan 29, 2025
c7f6c7e
legalize methods
mcy Jan 29, 2025
6575e52
legalize types
mcy Jan 29, 2025
6929176
fix zero_test
mcy Jan 30, 2025
fc14e67
lint
mcy Jan 30, 2025
8086d1e
add comments
mcy Jan 30, 2025
119c667
cr for predeclared
mcy Feb 7, 2025
d72c0ad
add tests for the syntax package
mcy Feb 7, 2025
b1be12f
fix group types not being printed
mcy Feb 7, 2025
d74a61b
string helpers
mcy Feb 7, 2025
f3de41d
add span helpers
mcy Feb 7, 2025
dd7fdfb
cr
mcy Feb 7, 2025
f7e68d3
cr
mcy Feb 7, 2025
d94e883
fix a renderer quirk
mcy Feb 7, 2025
ae8f170
Merge remote-tracking branch 'origin/main' into mcy/legalize
mcy Feb 7, 2025
cddd440
lint
mcy Feb 7, 2025
e321aaa
suggestions for reserved names
mcy Feb 10, 2025
e8e6a03
add more context to bad-nest errors
mcy Feb 10, 2025
21f75e5
cr
mcy Feb 10, 2025
ca53838
be more precise about classifying single-element paths
mcy Feb 10, 2025
58ffdca
legalize option values
mcy Feb 11, 2025
da83bd5
improve span for incomplete signatures
mcy Feb 11, 2025
5bdfe90
add more validation for types
mcy Feb 11, 2025
5d3ddb3
move a var
mcy Feb 11, 2025
e3318a4
legalize extn ranges
mcy Feb 11, 2025
2c9bfc9
lint
mcy Feb 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions experimental/ast/syntax/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2020-2025 Buf Technologies, Inc.
//
// 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 syntax specifies all of the syntax pragmas (including editions)
// that Protocompile understands.
package syntax

//go:generate go run github.com/bufbuild/protocompile/internal/enum syntax.yaml
20 changes: 20 additions & 0 deletions experimental/ast/syntax/is_edition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2020-2025 Buf Technologies, Inc.
//
// 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 syntax

// IsEdition returns whether this represents an edition.
func (s Syntax) IsEdition() bool {
return s != Proto2 && s != Proto3
}
91 changes: 91 additions & 0 deletions experimental/ast/syntax/syntax.go

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

42 changes: 42 additions & 0 deletions experimental/ast/syntax/syntax.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2020-2024 Buf Technologies, Inc.
#
# 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.

- name: Syntax
type: int
docs: |
Syntax is a known syntax pragma.

Not only does this include "proto2" and "proto3", but also all of the
editions.
methods:
- kind: string
- kind: go-string
- kind: from-string
name: Lookup
docs: |
Lookup looks up a syntax pragma by name.

If name does not name a known pragma, returns [Unknown].
skip: [Unknown]
- kind: all
name: All
docs: |
All returns an iterator over all known [Syntax] values.
skip: [Unknown]
values:
- {name: Unknown, string: "<unknown>"}
- {name: Proto2, string: proto2}
- {name: Proto3, string: proto3}
- {name: Edition2023, string: "2023"}
mcy marked this conversation as resolved.
Show resolved Hide resolved