Files
filament/tools/beamsplitter/parse/ast.go
Philip Rideout c82ae6a3a7 beamsplitter: add recursive descent parser
This removes usage of regexps from the parsing phase and splits the
program into three sub-packages: parser, database, and emitters.

The parser now generates an AST according to the formal grammar
described in the README:

https://github.com/google/filament/blob/pr/beamsplitter_rewrite2/tools/beamsplitter/README.md#grammar

This allows for nice readable error messages. More importantly, it
permits the C++ syntax to be less restrictive and paves the way for
possible expansion of the tool beyond `Options.h`.

I looked at the C++ AST generated by clang but it is huge and unwieldy.
For our purposes this simplified AST is much easier to work with.

The new lexer is inspired by the following Rob Pike talk.
- https://www.youtube.com/watch?v=HxaD_trXwRE

Beamsplitter does not use the state machine described in the above
prezo, but it does use a Go channel for separating the parser from the
lexer. In our case, the lexer is actually a recursive descent parser
with simple lookahead functionality. This made it easy for the "real"
parser to create an ergonomic coarse-grained AST.

This is a big change but it is a no-op in terms of the generated code.
2022-05-23 09:36:29 -07:00

80 lines
1.5 KiB
Go

/*
* Copyright (C) 2022 The Android Open Source Project
*
* 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 parse
type Node interface{}
type RootNode struct {
Line int
Child *NamespaceNode
}
type NamespaceNode struct {
Line int
Name string
Children []Node
}
type ClassNode struct {
Line int
Name string
Members []Node
IsTemplate bool
}
type StructNode struct {
Line int
Name string
Members []Node
IsTemplate bool
}
type EnumNode struct {
Line int
Name string
Values []string
ValueLines []int // used to find docstring for each enum value
}
type UsingNode struct {
Line int
Name string
Rhs string
}
type AccessSpecifierNode struct {
Line int
Access string
}
type MethodNode struct {
Line int
Name string
ReturnType string
Arguments string
Body string
IsTemplate bool
}
type FieldNode struct {
Line int
Name string
Type string
Rhs string
ArrayLength int
}