edited obfuscation-explorer/src/main/grammars/TSrg2Lexer.flex 
Open in IDE
KWkyle wood⁠ kyle wood: Fix ObfEx lexer generation
Copy Copy
        
  1. /*
  2. * Minecraft Development for IntelliJ
  3. *
  4. * https://mcdev.io/
  5. *
  6. * Copyright (C) 2025 minecraft-dev
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published
  10. * by the Free Software Foundation, version 3.0 only.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20.  
  21. package io.mcdev.obfex.formats.tsrg2.gen;
  22.  
  23. import com.intellij.lexer.*;
  24. import com.intellij.psi.tree.IElementType;
  25. import static io.mcdev.obfex.formats.tsrg2.gen.psi.TSrg2Types.*;
  26. import static com.intellij.psi.TokenType.*;
  27.  
  28. %%
  29.  
  30. %{
  31. public TSrg2Lexer() {
  32. this((java.io.Reader)null);
  33. }
  34. %}
  35.  
  36. %public
  37. %class TSrg2Lexer
  38. %implements FlexLexer
  39. %function advance
  40. %type IElementType
  41.  
  42. %s HEADER
  43. %s CORE
  44. %s SIGNATURE
  45.  
  46. %unicode
  47.  
  48. // Name element is used for all parts of an identifier name
  49. // 1. The parts of the package
  50. // 2. The class name
  51. // 3. The member name
  52. NAME_ELEMENT=[\p{L}_\p{Sc}][\p{L}\p{N}_\p{Sc}]*
  53.  
  54. PRIMITIVE=[ZBCSIFDJV]
  55. CLASS_TYPE=(\[+[ZBCSIFDJ]|\[*L[^;\s]+;)
  56.  
  57. COMMENT=\s*#.*
  58.  
  59. TAB=\t
  60. WHITE_SPACE=\s
  61. CRLF=\r\n|\n|\r
  62. NAMESPACE=\w
  63. DIGIT=\d
  64.  
  65. %%
  66.  
  67. <YYINITIAL> {
  68. "tsrg2" { yybegin(HEADER); return TSRG2_KEY; }
  69. }
  70.  
  71. <HEADER> {
  72. {NAMESPACE}+ { return NAMESPACE_KEY; }
  73. {CRLF} { yybegin(CORE); return CRLF; }
  74. }
  75.  
  76. <CORE> {
  77. "(" { yybegin(SIGNATURE); return OPEN_PAREN; }
  78. "/" { return SLASH; }
  79. {PRIMITIVE} {WHITE_SPACE}? { zzMarkedPos = zzStartRead + 1; return PRIMITIVE; }
  80. "<init>" { return INIT; }
  81. "<clinit>" { return CLINIT; }
  82. "static" { return STATIC; }
  83. "package-info" { return NAME_ELEMENT; }
  84. {DIGIT}+ { return DIGIT; }
  85. {CLASS_TYPE} { return CLASS_TYPE; }
  86. {NAME_ELEMENT} { return NAME_ELEMENT; }
  87. {TAB} { return TAB; }
  88. }
  89.  
  90. <SIGNATURE> {
  91. ")" { return CLOSE_PAREN; }
  92. {PRIMITIVE} { return PRIMITIVE; }
  93. {CLASS_TYPE} { return CLASS_TYPE; }
  94. {CRLF} { yybegin(CORE); return CRLF; }
  95. {WHITE_SPACE} { yybegin(CORE); return WHITE_SPACE; }
  96. }
  97.  
  98. {COMMENT} { return COMMENT; }
  99. {CRLF} { yybegin(CORE); return CRLF; }
  100. {WHITE_SPACE} { return WHITE_SPACE; }
  101. [^] { return BAD_CHARACTER; }
        
  1. /*
  2. * Minecraft Development for IntelliJ
  3. *
  4. * https://mcdev.io/
  5. *
  6. * Copyright (C) 2025 minecraft-dev
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published
  10. * by the Free Software Foundation, version 3.0 only.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20.  
  21. package io.mcdev.obfex.formats.tsrg2.gen.lexer;
  22.  
  23. import com.intellij.lexer.*;
  24. import com.intellij.psi.tree.IElementType;
  25. import static io.mcdev.obfex.formats.tsrg2.gen.psi.TSrg2Types.*;
  26. import static com.intellij.psi.TokenType.*;
  27.  
  28. %%
  29.  
  30. %{
  31. public TSrg2Lexer() {
  32. this((java.io.Reader)null);
  33. }
  34. %}
  35.  
  36. %public
  37. %class TSrg2Lexer
  38. %implements FlexLexer
  39. %function advance
  40. %type IElementType
  41.  
  42. %s HEADER
  43. %s CORE
  44. %s SIGNATURE
  45.  
  46. %unicode
  47.  
  48. // Name element is used for all parts of an identifier name
  49. // 1. The parts of the package
  50. // 2. The class name
  51. // 3. The member name
  52. NAME_ELEMENT=[\p{L}_\p{Sc}][\p{L}\p{N}_\p{Sc}]*
  53.  
  54. PRIMITIVE=[ZBCSIFDJV]
  55. CLASS_TYPE=(\[+[ZBCSIFDJ]|\[*L[^;\s]+;)
  56.  
  57. COMMENT=\s*#.*
  58.  
  59. TAB=\t
  60. WHITE_SPACE=\s
  61. CRLF=\r\n|\n|\r
  62. NAMESPACE=\w
  63. DIGIT=\d
  64.  
  65. %%
  66.  
  67. <YYINITIAL> {
  68. "tsrg2" { yybegin(HEADER); return TSRG2_KEY; }
  69. }
  70.  
  71. <HEADER> {
  72. {NAMESPACE}+ { return NAMESPACE_KEY; }
  73. {CRLF} { yybegin(CORE); return CRLF; }
  74. }
  75.  
  76. <CORE> {
  77. "(" { yybegin(SIGNATURE); return OPEN_PAREN; }
  78. "/" { return SLASH; }
  79. {PRIMITIVE} {WHITE_SPACE}? { zzMarkedPos = zzStartRead + 1; return PRIMITIVE; }
  80. "<init>" { return INIT; }
  81. "<clinit>" { return CLINIT; }
  82. "static" { return STATIC; }
  83. "package-info" { return NAME_ELEMENT; }
  84. {DIGIT}+ { return DIGIT; }
  85. {CLASS_TYPE} { return CLASS_TYPE; }
  86. {NAME_ELEMENT} { return NAME_ELEMENT; }
  87. {TAB} { return TAB; }
  88. }
  89.  
  90. <SIGNATURE> {
  91. ")" { return CLOSE_PAREN; }
  92. {PRIMITIVE} { return PRIMITIVE; }
  93. {CLASS_TYPE} { return CLASS_TYPE; }
  94. {CRLF} { yybegin(CORE); return CRLF; }
  95. {WHITE_SPACE} { yybegin(CORE); return WHITE_SPACE; }
  96. }
  97.  
  98. {COMMENT} { return COMMENT; }
  99. {CRLF} { yybegin(CORE); return CRLF; }
  100. {WHITE_SPACE} { return WHITE_SPACE; }
  101. [^] { return BAD_CHARACTER; }
×

Add build comment

Cancel
×

Mute test

×

×

Server communication failure

Server is unavailable

Server stopped or communication with the server is not possible due to network failure.

Server shutdown started.

Please relogin to continue your work.

×

Run Custom Build

×

TODO

Loading related builds...
Cancel
×

Responsibility

×

Edit tags

Cancel
×

Loading...

×

Are you sure?

Cancel
×

Please type to confirm.
Cancel