Skip to content

Commit

Permalink
feat(parser): add type_qualifier only in decls
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkie committed Nov 1, 2024
1 parent 222af29 commit 5213984
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lang-quote/src/tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,11 @@ fn tokenize_declaration(d: &ast::Declaration) -> TokenStream {
let ident = tokenize_identifier(ident);
quote! { glsl_lang::ast::DeclarationData::Invariant(#ident) }
}

ast::DeclarationData::TypeOnly(ref q) => {
let q = tokenize_type_qualifier(q);
quote! { glsl_lang::ast::DeclarationData::TypeOnly(#q) }
}
};

let span = tokenize_span(&d.span);
Expand Down
7 changes: 7 additions & 0 deletions lang-quote/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,10 @@ fn statement_var_decl() {
}
};
}

#[test]
fn typeonly_multiview_qualifier() {
let _ = glsl! {
layout (num_views = 2) in;
};
}
2 changes: 2 additions & 0 deletions lang-types/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ pub enum DeclarationData {
Block(Block),
/// Invariant declaration
Invariant(Identifier),
/// Type-only declaration
TypeOnly(TypeQualifier),
}

impl_node_content! {
Expand Down
1 change: 1 addition & 0 deletions lang/src/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ declaration: ast::Declaration = {
<l:@L> <p:precision_declaration> ";" <r:@R> => p.spanned(l, r),
<l:@L> <b:block_declaration> ";" <r:@R> => ast::DeclarationData::Block(b).spanned(l, r),
<l:@L> "invariant" <i:identifier> ";" <r:@R> => ast::DeclarationData::Invariant(i).spanned(l, r),
<l:@L> <q:type_qualifier> ";" <r:@R> => ast::DeclarationData::TypeOnly(q).spanned(l, r),
};

function_definition: ast::FunctionDefinition = {
Expand Down
3 changes: 3 additions & 0 deletions lang/src/transpiler/glsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,9 @@ where
f.write_char(' ')?;
show_identifier(f, ident, state)?;
}
ast::DeclarationData::TypeOnly(ref q) => {
show_type_qualifier(f, q, state)?;
}
}

state.write_declaration_terminator(f)
Expand Down
2 changes: 2 additions & 0 deletions lang/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ macro_rules! make_host_trait {
ast::DeclarationData::Block(block) => block.$mthd_name(visitor),

ast::DeclarationData::Invariant(ident) => ident.$mthd_name(visitor),

ast::DeclarationData::TypeOnly(q) => q.$mthd_name(visitor),
}
}
}
Expand Down

0 comments on commit 5213984

Please sign in to comment.