Giter Site home page Giter Site logo

tree-sitter-glsl's Introduction

tree-sitter-glsl's People

Contributors

thehamsta avatar web-flow avatar github-actions[bot] avatar coadon avatar greenerfield avatar

Stargazers

 avatar Jan avatar George Kontridze avatar Yehia Mohamed Yehia  avatar Jakub Pawlowski avatar Andy Li avatar Vsevolod Dolgopolov (aka Seva) avatar chirsz avatar  avatar Emirhan B. Demir avatar  avatar  avatar огромный avatar  avatar _nel avatar Nerijus avatar AngTsusiong avatar Andy Shevchenko avatar Suraj avatar Access avatar Armand Burger avatar Nils Martens avatar Lucas Payne avatar Jakub (Kuba) Antosik avatar James Edward Lewis II avatar Noah S-C avatar JongChan Choi (Rieul) avatar  avatar Marius Ungureanu avatar  avatar Alex Frederiksen avatar kuator avatar

Watchers

James Cloos avatar  avatar  avatar

tree-sitter-glsl's Issues

bug: Parser Error in Array of SSBOs Declarations

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

tree-sitter 0.21.0

Describe the bug

I've been using this grammar for a bit to teach myself a bit about tree-sitter and to eventually create a (possibly) better GLSL major-mode for Emacs (glsl-mode). That said, I think I encountered a minor error in the current grammar as an array of SSBO buffers with an unbounded field (see below) seems to generate errors:

layout(binding = 1, set = 0, std430) buffer GBuffer { GBuffer g[]; } rgbuf[NFRAMES];

Changing the #define to a constant seems to help, but there is still errors in the output parse-tree, as seen below:

Steps To Reproduce/Bad Parse Tree

Parse tree included here:

(translation_unit [0, 0] - [14, 0]
  (comment [0, 0] - [0, 27])
  (preproc_call [1, 0] - [2, 0]
    directive: (preproc_directive [1, 0] - [1, 8])
    argument: (preproc_arg [1, 9] - [1, 12]))
  (preproc_def [3, 0] - [4, 0]
    name: (identifier [3, 8] - [3, 15])
    value: (preproc_arg [3, 16] - [3, 19]))
  (declaration [5, 0] - [5, 73]
    (layout_specification [5, 0] - [5, 36]
      (layout_qualifiers [5, 6] - [5, 36]
        (qualifier [5, 7] - [5, 18]
          (identifier [5, 7] - [5, 14])
          (number_literal [5, 17] - [5, 18]))
        (qualifier [5, 20] - [5, 27]
          (identifier [5, 20] - [5, 23])
          (number_literal [5, 26] - [5, 27]))
        (qualifier [5, 29] - [5, 35]
          (identifier [5, 29] - [5, 35]))))
    (identifier [5, 44] - [5, 48])
    (field_declaration_list [5, 49] - [5, 67]
      (field_declaration [5, 51] - [5, 65]
        type: (type_identifier [5, 51] - [5, 56])
        declarator: (array_declarator [5, 57] - [5, 64]
          declarator: (field_identifier [5, 57] - [5, 62]))))
    (identifier [5, 68] - [5, 72]))
  (declaration [6, 0] - [6, 84]
    (layout_specification [6, 0] - [6, 36]
      (layout_qualifiers [6, 6] - [6, 36]
        (qualifier [6, 7] - [6, 18]
          (identifier [6, 7] - [6, 14])
          (number_literal [6, 17] - [6, 18]))
        (qualifier [6, 20] - [6, 27]
          (identifier [6, 20] - [6, 23])
          (number_literal [6, 26] - [6, 27]))
        (qualifier [6, 29] - [6, 35]
          (identifier [6, 29] - [6, 35]))))
    (identifier [6, 44] - [6, 51])
    (field_declaration_list [6, 52] - [6, 68]
      (field_declaration [6, 54] - [6, 66]
        type: (type_identifier [6, 54] - [6, 61])
        declarator: (array_declarator [6, 62] - [6, 65]
          declarator: (field_identifier [6, 62] - [6, 63]))))
    (ERROR [6, 69] - [6, 75]
      (identifier [6, 69] - [6, 74]))
    (identifier [6, 75] - [6, 82])
    (ERROR [6, 82] - [6, 83]))
  (function_definition [9, 0] - [11, 1]
    type: (primitive_type [9, 0] - [9, 4])
    declarator: (function_declarator [9, 5] - [9, 11]
      declarator: (identifier [9, 5] - [9, 9])
      parameters: (parameter_list [9, 9] - [9, 11]))
    body: (compound_statement [10, 0] - [11, 1])))
../glsl-mode/bug.glsl	   0.34 ms	   715 bytes/ms	(ERROR [6, 69] - [6, 75])

Expected Behavior/Parse Tree

Not entirely sure what parse tree I should be expecting, it looks mostly correct
already, but I guess the ERROR expressions should be replaced with something
more appropriate, perhaps:

(declaration
  (layout_specification ...)
  (identifier)
  (field_declaration_list ...)
  (array_declarator declarator: (field_identifier) [ size: (identifier) ]))

Which seems similar to a regular array declaration.

Repro

Below is a shader that can reproduce this error with the current grammar:

#version 460

#define NFRAMES (2)

layout(binding = 0, set = 0, std430) buffer PRNG { uvec4 state[]; } prng;
layout(binding = 1, set = 0, std430) buffer GBuffer { GBuffer g[]; } rgbuf[NFRAMES];


void main()
{
}

Add Highlight.scm

It should be pretty close to what's on the c version just remove some and add some more.

Filetypes frag and vert not recognized

image
[Left .frag shader and right the same code as .glsl]
The file extensions .frag and .vert are not recognized by tree-sitter-glsl.

I use

require'nvim-treesitter.configs'.setup {
  -- A list of parser names, or "all" (the five listed parsers should always be installed)
  ensure_installed = { "javascript", "typescript", "c", "lua", "vim", "vimdoc", "query", "cpp", "glsl"},

  -- Install parsers synchronously (only applied to `ensure_installed`)
  sync_install = false,

  -- Automatically install missing parsers when entering buffer
  -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
  auto_install = true,

  highlight = {
    enable = true,

    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },
}

feature: Grammar Support forthe `#extension` Directive

Did you check the tree-sitter docs?

Is your feature request related to a problem? Please describe.

I was messing around a bit with the grammar to add 'official' support for the #extension preprocessor directive since I couldn't seem to modify the preproc_call rule to do the correct code high-lighting that I wanted:

glsl_highlight

This is all implemented in this fork currently. I guess the question is, do you want me to open up a pull-request with this change, and if so is there anything else you want me to fix? I'm relatively new to the tree-sitter scene, so it's quite likely I've missed some details.

Describe the solution you'd like

I essentially 'fixed' this by adding two new rules and appending them to the
_top_level_items and _block_item rules:

        _top_level_item: ($, original) => choice(
            ...original.members.filter((member) => member.content?.name != '_old_style_function_definition'),
            $.preproc_extension,
        ),

        _block_item: ($, original) => choice(
            ...original.members.filter((member) => member.content?.name != '_old_style_function_definition'),
            $.preproc_extension,
        ),

        preproc_extension: $ => seq(
          field('directive', $.preproc_directive),
          field('extension', $.identifier),
          token.immediate(/[ \t]*:[ \t]*/),
          field('behavior', $.extension_behavior),
          token.immediate(/\r?\n/),
        ),

        extension_behavior: $ => choice("require", "enable", "warn", "disable"),

Describe alternatives you've considered

N/A

Additional context

The official documentation for all GLSL preprocessor directives can be found here: https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.html#preprocessor

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.