LuaLanguage.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include "Value.h"
  17. /**
  18. * Provides formatters and keywords for the LUA language.
  19. */
  20. class LuaLanguage{
  21. public:
  22. enum CONTEXT{
  23. /**
  24. * End of if/elseif block and about to start a final else.
  25. */
  26. TO_ELSE_BLOCK,
  27. /**
  28. * Begin of else block.
  29. */
  30. BEGIN_ELSE,
  31. /**
  32. * End of if block.
  33. */
  34. END_OF_IF,
  35. /**
  36. * End of while block.
  37. */
  38. END_OF_WHILE,
  39. /**
  40. * End of an if/elseif/else block.
  41. */
  42. END_OF_IF_ELSE_CHAIN,
  43. /**
  44. * Begin of a while block.
  45. */
  46. BEGIN_WHILE,
  47. /**
  48. * End of a while block.
  49. */
  50. END_WHILE
  51. };
  52. /**
  53. * The Lua "break" keyword.
  54. *
  55. * @return "break".
  56. */
  57. virtual const std::string LoopBreak();
  58. /**
  59. * The Lua "continue" keyword.
  60. *
  61. * Continue is not implemented in Lua.
  62. *
  63. * @return A commented string.
  64. */
  65. virtual const std::string LoopContinue();
  66. /**
  67. * A Lua "goto" instruction.
  68. *
  69. * @param target[in] A memory address label.
  70. * @return "goto label_0x<target>X".
  71. */
  72. virtual std::string Goto(uint32 target);
  73. /**
  74. * The Lua "repeat" keyword.
  75. *
  76. * @return "repeat".
  77. */
  78. virtual const std::string DoLoopHeader();
  79. /**
  80. * The Lua parts of a do-loop footer
  81. *
  82. * @param before_expr[in] True to fetch the initial part of the
  83. * footer, false for the ending part.
  84. * @return "until (" if before_expr is true, ")" if not.
  85. */
  86. virtual std::string DoLoopFooter(bool before_expr);
  87. /**
  88. * The Lua parts of a if control sentence
  89. *
  90. * @param before_expr[in] True to fetch the initial part of the
  91. * sentence, false for the ending part.
  92. * @return "if (" if before_expr is true, ") then" if not.
  93. */
  94. virtual std::string If(bool before_expr);
  95. /**
  96. * The Lua parts of a while control sentence
  97. *
  98. * @param before_expr[in] True to fetch the initial part of the
  99. * sentence, false for the ending part.
  100. * @return "while (" if before_expr is true, ") do" if not.
  101. */
  102. virtual std::string WhileHeader(bool before_expr);
  103. /**
  104. * The Lua argument separator.
  105. *
  106. * @return ",".
  107. */
  108. virtual const std::string FunctionCallArgumentSeperator();
  109. /**
  110. * The Lua function argument list opener.
  111. *
  112. * @return "(".
  113. */
  114. virtual const std::string FunctionCallBegin();
  115. /**
  116. * The Lua function argument list closer.
  117. *
  118. * @return ")".
  119. */
  120. virtual const std::string FunctionCallEnd();
  121. /**
  122. * Generates a Lua label to use with goto.
  123. *
  124. * @param addr[in] Target address label.
  125. * @return "::label_0x<target>X::"
  126. */
  127. virtual std::string Label(uint32 addr);
  128. /**
  129. * The Lua "else" keyword.
  130. *
  131. * @return "else".
  132. */
  133. virtual const std::string Else();
  134. /**
  135. * The Lua block starter (none).
  136. *
  137. * @param context[in] Unused.
  138. * @return An empty string.
  139. */
  140. virtual std::string StartBlock(CONTEXT context);
  141. /**
  142. * A Lua block ender.
  143. *
  144. * @param context[in] The current context.
  145. * @return "end", unles the current context is {@see TO_ELSE_BLOCK},
  146. * in which case it will return an empty string, because "end" is not
  147. * needed before an else.
  148. */
  149. virtual std::string EndBlock(CONTEXT context);
  150. /**
  151. * The Lua line terminator (none).
  152. *
  153. * @return An empty string.
  154. */
  155. virtual const std::string LineTerminator();
  156. };