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

Adding top level program type #37

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,12 @@ and `#extension` have no effect, and can be fully preserved as part of parsing.

## Deviations from the Khronos Grammar

- The parser allows for programs to contain top level preprocessor statements,
like `#define X`, as a convenience to avoid preprocessing some programs, and
for simple programs lets you preserve preprocessor lines in the AST if you
want to do something specific with them. However, preprocessor statements at
any other part of the program are not allowed. The Khronos grammar does not
include preprocessor statements.
- `selection_statement` is renamed to `if_statement`
- The grammar specifies `declaration` itself ends with a semicolon. I moved the
semicolon into the `declaration_statement` rule.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"engines": {
"node": ">=16"
},
"version": "5.2.0",
"version": "5.3.0",
"type": "module",
"description": "A GLSL ES 1.0 and 3.0 parser and preprocessor that can preserve whitespace and comments",
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion src/ast/ast-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@

import { Scope } from '../parser/scope.js';

// Valid top level program lines
export type ProgramStatement =
| PreprocessorNode
| DeclarationStatementNode
| FunctionNode;

// The overall result of parsing, which incldues the AST and scopes
export interface Program {
type: 'program';
program: (PreprocessorNode | DeclarationStatementNode | FunctionNode)[];
program: ProgramStatement[];
scopes: Scope[];
wsStart?: string;
wsEnd?: string;
Expand Down
Loading