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

Fix #11. Improve preprocessor parsing #32

Merged
merged 2 commits into from
Apr 23, 2015
Merged

Fix #11. Improve preprocessor parsing #32

merged 2 commits into from
Apr 23, 2015

Conversation

AbigailBuccaneer
Copy link
Collaborator

Now preprocessor directives are lexed properly. The parser just adds all tokens after a preprocessor directive until the next newline to the PSI element.

Currently parsed and highlighted correctly:

#version \
300 \
es

#if !defined(__GLSL__)
#error Uh-oh!
#endif

void f() {
    int x = 3
    #ifdef FOO
    + 4
    #else
    * 5
    #endif
    ;
}

Not yet implemented:

  • Associating #if/#ifdef/#ifndef with the matching #else/#end. They're currently just parsed as two independent directives.
  • Error highlighting when a directive is not the first non-whitespace token on a line. I tried to do it in the parser, but it doesn't play nice with other whitespace, so I think a better approach will probably be an error annotator. (Interestingly, CLion doesn't highlight errors about this for C/C++.)
  • Handling the contents of the directives. We would probably want:
    • #version and #extension to set properties on the GLSLFile, to be used for error annotation and autocompletion
    • #define to actually define tokens, which are then inserted into the token stream when coming across them in advanceLexer
    • #if/#ifdef/#ifndef to be evaluated properly (this would require some constant expression analysis).

It's not 100% in-line with the C++ preprocessor spec - which involves
odd things like using a different definition for preprocessor number
tokens and compiler number tokens - but this should be adequate for the
vast majority of preprocessor parsing.
Currently after every lexer advance (and at the very beginning), the
parser will check for a preprocessor begin. Currently the parser just
eats the entire directive without handling it.

The compound statement element had to be modified as these directives
can exist inside a compound statement, but previously they asserted on
finding anything other than a statement or comment.
@AbigailBuccaneer AbigailBuccaneer changed the title Improve preprocessor parsing Fix #11. Improve preprocessor parsing Apr 22, 2015
@Darkyenus
Copy link
Owner

Looks good

Darkyenus added a commit that referenced this pull request Apr 23, 2015
@Darkyenus Darkyenus merged commit 8700a2a into Darkyenus:master Apr 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants