Skip to content
Draft
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
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Tools and IntelliSense for GLSL and WGSL.
- [Identifier](#identifier)
- [Literal](#literal)
- [ArraySpecifier](#arrayspecifier)
- [TypeSpecifier](#typespecifier)
- [Program](#program)
- Statements
- [ExpressionStatement](#expressionstatement)
Expand Down Expand Up @@ -252,19 +253,19 @@ minify(`#version 300 es\nin vec2 c;out vec4 data[gl_MaxDrawBuffers];void main(){

## Parse

Parses a string of GLSL (WGSL is WIP) code into an [AST](#ast).
Parses a string of GLSL or WGSL code into an [AST](#ast).

```ts
const ast: Program = parse(code: string)
```

## Generate

Generates a string of GLSL (WGSL is WIP) code from an [AST](#ast).
Generates a string of GLSL or WGSL code from an [AST](#ast).

```ts
const code: string = generate(program: Program, {
target: 'GLSL' // | 'WGSL'
target: 'GLSL' | 'WGSL'
})
```

Expand Down Expand Up @@ -341,6 +342,18 @@ interface ArraySpecifier extends Node {
}
```

### TypeSpecifier

A type specifier and optional shader layout.

```ts
interface TypeSpecifier extends Node {
type: 'TypeSpecifier'
typeSpecifier: Identifier | ArraySpecifier
layout: Record<string, string | boolean> | null
}
```

### Program

Represents the root of an AST.
Expand Down Expand Up @@ -544,9 +557,9 @@ A function declaration. `body` is null for overloads.
```ts
interface FunctionDeclaration extends Node {
type: 'FunctionDeclaration'
id: Identifier
id: TypeSpecifier
qualifiers: PrecisionQualifier[]
typeSpecifier: Identifier | ArraySpecifier
typeSpecifier: TypeSpecifier
params: FunctionParameter[]
body: BlockStatement | null
}
Expand All @@ -559,9 +572,9 @@ A function parameter within a function declaration.
```ts
interface FunctionParameter extends Node {
type: 'FunctionParameter'
id: Identifier | null
id: TypeSpecifier | null
qualifiers: (ConstantQualifier | ParameterQualifier | PrecisionQualifier)[]
typeSpecifier: Identifier | ArraySpecifier
typeSpecifier: TypeSpecifier
}
```

Expand All @@ -583,10 +596,9 @@ A variable declarator within a variable declaration.
```ts
interface VariableDeclarator extends Node {
type: 'VariableDeclarator'
id: Identifier
id: TypeSpecifier
qualifiers: (ConstantQualifier | InterpolationQualifier | StorageQualifier | PrecisionQualifier)[]
typeSpecifier: Identifier | ArraySpecifier
layout: Record<string, string | boolean> | null
typeSpecifier: TypeSpecifier
init: Expression | null
}
```
Expand All @@ -600,8 +612,7 @@ interface StructuredBufferDeclaration extends Node {
type: 'StructuredBufferDeclaration'
id: Identifier | null
qualifiers: (InterfaceStorageQualifier | MemoryQualifier | LayoutQualifier)[]
typeSpecifier: Identifier | ArraySpecifier
layout: Record<string, string | boolean> | null
typeSpecifier: TypeSpecifier
members: VariableDeclaration[]
}
```
Expand Down
27 changes: 18 additions & 9 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ export interface ArraySpecifier extends Node {
dimensions: (Literal | Identifier | null)[]
}

/**
* A type specifier and optional shader layout.
*/
export interface TypeSpecifier extends Node {
type: 'TypeSpecifier'
typeSpecifier: Identifier | ArraySpecifier
layout: Record<string, string | boolean> | null
}

/**
* An array initialization expression.
*/
Expand Down Expand Up @@ -287,9 +296,9 @@ export type PrecisionQualifier = 'highp' | 'mediump' | 'lowp'
*/
export interface FunctionDeclaration extends Node {
type: 'FunctionDeclaration'
id: Identifier
id: TypeSpecifier
qualifiers: PrecisionQualifier[]
typeSpecifier: Identifier | ArraySpecifier
typeSpecifier: TypeSpecifier | null
params: FunctionParameter[]
body: BlockStatement | null
}
Expand All @@ -299,9 +308,9 @@ export interface FunctionDeclaration extends Node {
*/
export interface FunctionParameter extends Node {
type: 'FunctionParameter'
id: Identifier | null
id: TypeSpecifier | null
qualifiers: (ConstantQualifier | ParameterQualifier | PrecisionQualifier)[]
typeSpecifier: Identifier | ArraySpecifier
typeSpecifier: TypeSpecifier
}

/**
Expand All @@ -317,10 +326,9 @@ export interface VariableDeclaration extends Node {
*/
export interface VariableDeclarator extends Node {
type: 'VariableDeclarator'
id: Identifier
id: TypeSpecifier
qualifiers: (ConstantQualifier | InterpolationQualifier | StorageQualifier | PrecisionQualifier)[]
typeSpecifier: Identifier | ArraySpecifier
layout: Record<string, string | boolean> | null
typeSpecifier: TypeSpecifier | null
init: Expression | null
}

Expand All @@ -331,8 +339,7 @@ export interface StructuredBufferDeclaration extends Node {
type: 'StructuredBufferDeclaration'
id: Identifier | null
qualifiers: (InterfaceStorageQualifier | MemoryQualifier | LayoutQualifier)[]
typeSpecifier: Identifier | ArraySpecifier
layout: Record<string, string | boolean> | null
typeSpecifier: TypeSpecifier
members: VariableDeclaration[]
}

Expand Down Expand Up @@ -383,7 +390,9 @@ export interface LayoutQualifierStatement extends Node {
export type Expression =
| Literal
| Identifier
| ArraySpecifier
| ArrayExpression
| TypeSpecifier
| UnaryExpression
| UpdateExpression
| BinaryExpression
Expand Down
Loading
Loading