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.
108 lines
2.9 KiB
Plaintext
108 lines
2.9 KiB
Plaintext
{{ define "JsBindingsHeader" }}// This file has been generated by beamsplitter
|
|
|
|
#include <emscripten.h>
|
|
#include <emscripten/bind.h>
|
|
|
|
#include <filament/View.h>
|
|
|
|
using namespace emscripten;
|
|
using namespace filament;
|
|
|
|
EMSCRIPTEN_BINDINGS(jsbindings_generated) {
|
|
{{end}}
|
|
|
|
{{define "JsBindingsStruct"}}
|
|
{{- $struct_name := .QualifiedName }}
|
|
value_object<{{ cprefix }}{{ $struct_name }}>("{{ jsprefix }}{{ qualifiedtype .QualifiedName }}")
|
|
{{- range $index, $field := .Fields}}
|
|
{{- if flag $field "skip_javascript" }}
|
|
// JavaScript binding for {{$field.Name}} is not yet supported, must use default value.
|
|
{{- else }}
|
|
.field("{{ $field.Name }}", &{{ cprefix }}{{ $struct_name }}::{{ $field.Name }})
|
|
{{- end }}
|
|
{{- end }}
|
|
;
|
|
{{end}}
|
|
|
|
{{define "JsBindingsFooter"}}
|
|
} // EMSCRIPTEN_BINDINGS
|
|
{{end}}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
{{define "JsEnumsHeader"}}// This file has been generated by beamsplitter
|
|
|
|
#include <emscripten.h>
|
|
#include <emscripten/bind.h>
|
|
|
|
#include <filament/View.h>
|
|
|
|
using namespace emscripten;
|
|
using namespace filament;
|
|
|
|
EMSCRIPTEN_BINDINGS(jsenums_generated) {
|
|
{{end}}
|
|
|
|
{{define "JsEnum"}}
|
|
{{- $enum_name := .QualifiedName }}
|
|
enum_<{{ cprefix }}{{ $enum_name }}>("{{ jsprefix }}{{ qualifiedtype .QualifiedName }}")
|
|
{{- range .Values}}
|
|
.value("{{ .Name }}", {{ cprefix }}{{ $enum_name }}::{{ .Name }})
|
|
{{- end }}
|
|
;
|
|
{{end}}
|
|
|
|
{{define "JsEnumsFooter"}}
|
|
} // EMSCRIPTEN_BINDINGS
|
|
{{end}}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
{{define "JsExtensionsHeader"}}// This file has been generated by beamsplitter
|
|
|
|
Filament.loadGeneratedExtensions = function() {
|
|
{{end}}
|
|
|
|
{{define "JsExtension"}}
|
|
Filament.{{ classprefix}}set{{ .BaseName }}Defaults = function(overrides) {
|
|
const options = {
|
|
{{- range $index, $field := .Fields}}
|
|
{{- if flag $field "skip_javascript" }}
|
|
// JavaScript binding for {{$field.Name}} is not yet supported, must use default value.
|
|
{{- else }}
|
|
{{$field.Name}}: {{qualifiedvalue $field.DefaultValue}},
|
|
{{- end }}
|
|
{{- end }}
|
|
};
|
|
return Object.assign(options, overrides);
|
|
};
|
|
{{end}}
|
|
|
|
{{define "JsExtensionsFooter"}}
|
|
};
|
|
{{end}}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
{{define "TsStruct"}}
|
|
{{- $struct_name := .QualifiedName }}
|
|
{{.Description}}export interface {{ jsprefix }}{{ qualifiedtype .QualifiedName }} {
|
|
{{- range $index, $field := .Fields}}
|
|
{{- if flag $field "skip_javascript" }}
|
|
// JavaScript binding for {{$field.Name}} is not yet supported, must use default value.
|
|
{{- else }}
|
|
{{ docblock $field 1 }}
|
|
{{- $field.Name }}?: {{ tstype $field.TypeString }};
|
|
{{- end }}
|
|
{{- end }}
|
|
}
|
|
{{end}}
|
|
|
|
{{define "TsEnum"}}
|
|
{{.Description}}export enum {{ jsprefix }}{{ qualifiedtype .QualifiedName }} {
|
|
{{- range .Values}}
|
|
{{ .Name }},{{if .Description}} // {{.Description}}{{end}}
|
|
{{- end }}
|
|
}
|
|
{{end}}
|