Skip to content

Commit

Permalink
[GLSL] store white spaces in channel hidden, [GLSL,Verilog] fix forma…
Browse files Browse the repository at this point in the history
…tting
  • Loading branch information
msagca committed Sep 19, 2024
1 parent e23fa83 commit 1490c78
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 267 deletions.
167 changes: 82 additions & 85 deletions glsl/GLSLLexer.g4
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
/*
MIT License
Copyright (c) 2022 Mustafa Said Ağca
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
MIT License
Copyright (c) 2022 Mustafa Said Ağca
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

// $antlr-format alignTrailingComments true, columnLimit 150, maxEmptyLinesToKeep 1, reflowComments false, useTab false
// $antlr-format allowShortRulesOnASingleLine true, allowShortBlocksOnASingleLine true, minEmptyLines 0, alignSemicolons ownLine
Expand Down Expand Up @@ -262,7 +259,7 @@ LEFT_PAREN : '(';
MOD_ASSIGN : '%=';
MUL_ASSIGN : '*=';
NE_OP : '!=';
NUMBER_SIGN : '#' -> channel (DIRECTIVES), pushMode (DIRECTIVE_MODE);
NUMBER_SIGN : '#' -> channel(DIRECTIVES), pushMode(DIRECTIVE_MODE);
OR_ASSIGN : '|=';
OR_OP : '||';
PERCENT : '%';
Expand Down Expand Up @@ -293,100 +290,100 @@ FLOATCONSTANT:
;
INTCONSTANT : DECIMAL_CONSTANT | HEX_CONSTANT | OCTAL_CONSTANT;
UINTCONSTANT : INTCONSTANT INTEGER_SUFFIX;
BLOCK_COMMENT : '/*' .*? '*/' -> channel (COMMENTS);
LINE_COMMENT : '//' (~ [\r\n\\] | '\\' (NEWLINE | .))* -> channel (COMMENTS);
LINE_CONTINUATION : '\\' NEWLINE -> channel (HIDDEN);
BLOCK_COMMENT : '/*' .*? '*/' -> channel(COMMENTS);
LINE_COMMENT : '//' (~ [\r\n\\] | '\\' (NEWLINE | .))* -> channel(COMMENTS);
LINE_CONTINUATION : '\\' NEWLINE -> channel(HIDDEN);
IDENTIFIER : [a-zA-Z_] [a-zA-Z0-9_]*;
WHITE_SPACE : [ \t\r\n]+ -> channel (HIDDEN);
WHITE_SPACE : [ \t\r\n]+ -> channel(HIDDEN);

mode DIRECTIVE_MODE;
DEFINE_DIRECTIVE : 'define' -> channel (DIRECTIVES), mode (DEFINE_DIRECTIVE_MODE);
ELIF_DIRECTIVE : 'elif' -> channel (DIRECTIVES), popMode, mode (ELIF_DIRECTIVE_MODE);
ELSE_DIRECTIVE : 'else' -> channel (DIRECTIVES), popMode, mode (PROGRAM_TEXT_MODE);
ENDIF_DIRECTIVE : 'endif' -> channel (DIRECTIVES), popMode, popMode, popMode;
ERROR_DIRECTIVE : 'error' -> channel (DIRECTIVES), mode (ERROR_DIRECTIVE_MODE);
EXTENSION_DIRECTIVE : 'extension' -> channel (DIRECTIVES), mode (EXTENSION_DIRECTIVE_MODE);
IF_DIRECTIVE : 'if' -> channel (DIRECTIVES), mode (IF_DIRECTIVE_MODE);
IFDEF_DIRECTIVE : 'ifdef' -> channel (DIRECTIVES), mode (IFDEF_DIRECTIVE_MODE);
IFNDEF_DIRECTIVE : 'ifndef' -> channel (DIRECTIVES), mode (IFDEF_DIRECTIVE_MODE);
LINE_DIRECTIVE : 'line' -> channel (DIRECTIVES), mode (LINE_DIRECTIVE_MODE);
PRAGMA_DIRECTIVE : 'pragma' -> channel (DIRECTIVES), mode (PRAGMA_DIRECTIVE_MODE);
UNDEF_DIRECTIVE : 'undef' -> channel (DIRECTIVES), mode (UNDEF_DIRECTIVE_MODE);
VERSION_DIRECTIVE : 'version' -> channel (DIRECTIVES), mode (VERSION_DIRECTIVE_MODE);
SPACE_TAB_0 : SPACE_TAB -> skip;
NEWLINE_0 : NEWLINE -> skip, popMode;
DEFINE_DIRECTIVE : 'define' -> channel(DIRECTIVES), mode(DEFINE_DIRECTIVE_MODE);
ELIF_DIRECTIVE : 'elif' -> channel(DIRECTIVES), popMode, mode(ELIF_DIRECTIVE_MODE);
ELSE_DIRECTIVE : 'else' -> channel(DIRECTIVES), popMode, mode(PROGRAM_TEXT_MODE);
ENDIF_DIRECTIVE : 'endif' -> channel(DIRECTIVES), popMode, popMode, popMode;
ERROR_DIRECTIVE : 'error' -> channel(DIRECTIVES), mode(ERROR_DIRECTIVE_MODE);
EXTENSION_DIRECTIVE : 'extension' -> channel(DIRECTIVES), mode(EXTENSION_DIRECTIVE_MODE);
IF_DIRECTIVE : 'if' -> channel(DIRECTIVES), mode(IF_DIRECTIVE_MODE);
IFDEF_DIRECTIVE : 'ifdef' -> channel(DIRECTIVES), mode(IFDEF_DIRECTIVE_MODE);
IFNDEF_DIRECTIVE : 'ifndef' -> channel(DIRECTIVES), mode(IFDEF_DIRECTIVE_MODE);
LINE_DIRECTIVE : 'line' -> channel(DIRECTIVES), mode(LINE_DIRECTIVE_MODE);
PRAGMA_DIRECTIVE : 'pragma' -> channel(DIRECTIVES), mode(PRAGMA_DIRECTIVE_MODE);
UNDEF_DIRECTIVE : 'undef' -> channel(DIRECTIVES), mode(UNDEF_DIRECTIVE_MODE);
VERSION_DIRECTIVE : 'version' -> channel(DIRECTIVES), mode(VERSION_DIRECTIVE_MODE);
SPACE_TAB_0 : SPACE_TAB -> channel(HIDDEN), type(WHITE_SPACE);
NEWLINE_0 : NEWLINE -> channel(HIDDEN), type(WHITE_SPACE), popMode;

mode DEFINE_DIRECTIVE_MODE;
MACRO_NAME : IDENTIFIER MACRO_ARGS? -> channel (DIRECTIVES), mode (MACRO_TEXT_MODE);
NEWLINE_1 : NEWLINE -> skip, popMode;
SPACE_TAB_1 : SPACE_TAB -> skip;
MACRO_NAME : IDENTIFIER MACRO_ARGS? -> channel(DIRECTIVES), mode(MACRO_TEXT_MODE);
NEWLINE_1 : NEWLINE -> channel(HIDDEN), type(WHITE_SPACE), popMode;
SPACE_TAB_1 : SPACE_TAB -> channel(HIDDEN), type(WHITE_SPACE);

mode ELIF_DIRECTIVE_MODE;
CONSTANT_EXPRESSION : ~ [\r\n]+ -> channel (DIRECTIVES);
NEWLINE_2 : NEWLINE -> skip, mode (PROGRAM_TEXT_MODE);
CONSTANT_EXPRESSION : ~ [\r\n]+ -> channel(DIRECTIVES);
NEWLINE_2 : NEWLINE -> channel(HIDDEN), type(WHITE_SPACE), mode(PROGRAM_TEXT_MODE);

mode ERROR_DIRECTIVE_MODE;
ERROR_MESSAGE : ~ [\r\n]+ -> channel (DIRECTIVES);
NEWLINE_3 : NEWLINE -> skip, popMode;
ERROR_MESSAGE : ~ [\r\n]+ -> channel(DIRECTIVES);
NEWLINE_3 : NEWLINE -> channel(HIDDEN), type(WHITE_SPACE), popMode;

mode EXTENSION_DIRECTIVE_MODE;
BEHAVIOR : ('require' | 'enable' | 'warn' | 'disable') -> channel (DIRECTIVES);
COLON_0 : COLON -> channel (DIRECTIVES), type (COLON);
EXTENSION_NAME : IDENTIFIER -> channel (DIRECTIVES);
NEWLINE_4 : NEWLINE -> skip, popMode;
SPACE_TAB_2 : SPACE_TAB -> skip;
BEHAVIOR : ('require' | 'enable' | 'warn' | 'disable') -> channel(DIRECTIVES);
COLON_0 : COLON -> channel(DIRECTIVES), type(COLON);
EXTENSION_NAME : IDENTIFIER -> channel(DIRECTIVES);
NEWLINE_4 : NEWLINE -> channel(HIDDEN), type(WHITE_SPACE), popMode;
SPACE_TAB_2 : SPACE_TAB -> channel(HIDDEN), type(WHITE_SPACE);

mode IF_DIRECTIVE_MODE;
CONSTANT_EXPRESSION_0 : CONSTANT_EXPRESSION -> channel (DIRECTIVES), type (CONSTANT_EXPRESSION);
NEWLINE_5 : NEWLINE -> skip, pushMode (PROGRAM_TEXT_MODE);
CONSTANT_EXPRESSION_0 : CONSTANT_EXPRESSION -> channel(DIRECTIVES), type(CONSTANT_EXPRESSION);
NEWLINE_5 : NEWLINE -> channel(HIDDEN), type(WHITE_SPACE), pushMode(PROGRAM_TEXT_MODE);

mode IFDEF_DIRECTIVE_MODE;
MACRO_IDENTIFIER : IDENTIFIER -> channel (DIRECTIVES);
NEWLINE_6 : NEWLINE -> skip, pushMode (PROGRAM_TEXT_MODE);
SPACE_TAB_3 : SPACE_TAB -> skip;
MACRO_IDENTIFIER : IDENTIFIER -> channel(DIRECTIVES);
NEWLINE_6 : NEWLINE -> channel(HIDDEN), type(WHITE_SPACE), pushMode(PROGRAM_TEXT_MODE);
SPACE_TAB_3 : SPACE_TAB -> channel(HIDDEN), type(WHITE_SPACE);

mode LINE_DIRECTIVE_MODE;
LINE_EXPRESSION : ~ [\r\n]+ -> channel (DIRECTIVES);
NEWLINE_7 : NEWLINE -> skip, mode (PROGRAM_TEXT_MODE);
LINE_EXPRESSION : ~ [\r\n]+ -> channel(DIRECTIVES);
NEWLINE_7 : NEWLINE -> channel(HIDDEN), type(WHITE_SPACE), mode(PROGRAM_TEXT_MODE);

mode MACRO_TEXT_MODE;
BLOCK_COMMENT_0 : BLOCK_COMMENT -> channel (COMMENTS), type(BLOCK_COMMENT);
BLOCK_COMMENT_0 : BLOCK_COMMENT -> channel(COMMENTS), type(BLOCK_COMMENT);
MACRO_ESC_NEWLINE : '\\' NEWLINE -> channel(DIRECTIVES);
MACRO_ESC_SEQUENCE : '\\' . -> channel(DIRECTIVES), type (MACRO_TEXT);
MACRO_TEXT : ~ [/\r\n\\]+ -> channel (DIRECTIVES);
NEWLINE_8 : NEWLINE -> skip, popMode;
MACRO_ESC_SEQUENCE : '\\' . -> channel(DIRECTIVES), type(MACRO_TEXT);
MACRO_TEXT : ~ [/\r\n\\]+ -> channel(DIRECTIVES);
NEWLINE_8 : NEWLINE -> channel(HIDDEN), type(WHITE_SPACE), popMode;
SLASH_0 : SLASH -> more;

mode PRAGMA_DIRECTIVE_MODE;
DEBUG : 'debug' -> channel (DIRECTIVES);
LEFT_PAREN_0 : LEFT_PAREN -> channel (DIRECTIVES), type (LEFT_PAREN);
NEWLINE_9 : NEWLINE -> skip, popMode;
OFF : 'off' -> channel (DIRECTIVES);
ON : 'on' -> channel (DIRECTIVES);
OPTIMIZE : 'optimize' -> channel (DIRECTIVES);
RIGHT_PAREN_0 : RIGHT_PAREN -> channel (DIRECTIVES), type (RIGHT_PAREN);
SPACE_TAB_5 : SPACE_TAB -> skip;
STDGL : 'STDGL' -> channel (DIRECTIVES);
DEBUG : 'debug' -> channel(DIRECTIVES);
LEFT_PAREN_0 : LEFT_PAREN -> channel(DIRECTIVES), type(LEFT_PAREN);
NEWLINE_9 : NEWLINE -> channel(HIDDEN), type(WHITE_SPACE), popMode;
OFF : 'off' -> channel(DIRECTIVES);
ON : 'on' -> channel(DIRECTIVES);
OPTIMIZE : 'optimize' -> channel(DIRECTIVES);
RIGHT_PAREN_0 : RIGHT_PAREN -> channel(DIRECTIVES), type(RIGHT_PAREN);
SPACE_TAB_5 : SPACE_TAB -> channel(HIDDEN), type(WHITE_SPACE);
STDGL : 'STDGL' -> channel(DIRECTIVES);

mode PROGRAM_TEXT_MODE;
BLOCK_COMMENT_1 : BLOCK_COMMENT -> channel (COMMENTS), type (BLOCK_COMMENT);
LINE_COMMENT_0 : LINE_COMMENT -> channel (COMMENTS), type (LINE_COMMENT);
BLOCK_COMMENT_1 : BLOCK_COMMENT -> channel(COMMENTS), type(BLOCK_COMMENT);
LINE_COMMENT_0 : LINE_COMMENT -> channel(COMMENTS), type(LINE_COMMENT);
NUMBER_SIGN_0:
NUMBER_SIGN -> channel (DIRECTIVES), type (NUMBER_SIGN), pushMode (DIRECTIVE_MODE)
NUMBER_SIGN -> channel(DIRECTIVES), type(NUMBER_SIGN), pushMode(DIRECTIVE_MODE)
;
PROGRAM_TEXT : ~ [#/]+ -> channel (DIRECTIVES);
PROGRAM_TEXT : ~ [#/]+ -> channel(DIRECTIVES);
SLASH_1 : SLASH -> more;

mode UNDEF_DIRECTIVE_MODE;
MACRO_IDENTIFIER_0 : MACRO_IDENTIFIER -> channel (DIRECTIVES), type (MACRO_IDENTIFIER);
NEWLINE_10 : NEWLINE -> skip, popMode;
SPACE_TAB_6 : SPACE_TAB -> skip;
MACRO_IDENTIFIER_0 : MACRO_IDENTIFIER -> channel(DIRECTIVES), type(MACRO_IDENTIFIER);
NEWLINE_10 : NEWLINE -> channel(HIDDEN), type(WHITE_SPACE), popMode;
SPACE_TAB_6 : SPACE_TAB -> channel(HIDDEN), type(WHITE_SPACE);

mode VERSION_DIRECTIVE_MODE;
NEWLINE_11 : NEWLINE -> skip, popMode;
NUMBER : [0-9]+ -> channel (DIRECTIVES);
PROFILE : ('core' | 'compatibility' | 'es') -> channel (DIRECTIVES);
SPACE_TAB_7 : SPACE_TAB -> skip;
NEWLINE_11 : NEWLINE -> channel(HIDDEN), type(WHITE_SPACE), popMode;
NUMBER : [0-9]+ -> channel(DIRECTIVES);
PROFILE : ('core' | 'compatibility' | 'es') -> channel(DIRECTIVES);
SPACE_TAB_7 : SPACE_TAB -> channel(HIDDEN), type(WHITE_SPACE);

fragment DECIMAL_CONSTANT : [1-9] [0-9]*;
fragment DIGIT_SEQUENCE : [0-9]+;
Expand Down
41 changes: 19 additions & 22 deletions glsl/GLSLParser.g4
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
/*
MIT License
Copyright (c) 2022 Mustafa Said Ağca
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
MIT License
Copyright (c) 2022 Mustafa Said Ağca
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false
// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging
Expand Down
41 changes: 19 additions & 22 deletions glsl/GLSLPreParser.g4
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
/*
MIT License
Copyright (c) 2022 Mustafa Said Ağca
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
MIT License
Copyright (c) 2022 Mustafa Said Ağca
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false
// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging
Expand Down
Loading

0 comments on commit 1490c78

Please sign in to comment.