From 0385663af94575598bd0ae233a4eea5b7d7cdc7a Mon Sep 17 00:00:00 2001 From: Andy Ray Date: Sat, 5 Oct 2024 13:44:30 -0700 Subject: [PATCH] Adding top level program type --- README.md | 6 ++++++ package.json | 2 +- src/ast/ast-types.ts | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5756e64..a594d0d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/package.json b/package.json index 04fa0b2..04fc230 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/ast/ast-types.ts b/src/ast/ast-types.ts index fa96064..78e7bfa 100644 --- a/src/ast/ast-types.ts +++ b/src/ast/ast-types.ts @@ -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;