1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

[FunC] Support traditional // and /**/ comments

They work alongside Lisp-style ;; and {--}, without any #pragma.
Conceptually, a new syntax should be disabled by default
and activated using a special compiler option.
But now, we don't have an easy way to provide compiler options
in func-js, blueprint, etc.
Note, that introducing per-file #pragma is a wrong approach here,
since if we want to fire human-readable error on using '//' without pragma,
lexer should nevertheless work differently.
(this could be controlled by a launch option, but see above)
This commit is contained in:
Aleksandr Kirsanov 2024-04-30 20:32:07 +03:00
parent a174f858be
commit 30572c77d6
No known key found for this signature in database
GPG key ID: B758BBAA01FFB3D3
6 changed files with 105 additions and 27 deletions

View file

@ -65,12 +65,16 @@ struct Lexem {
static std::string lexem_name_str(int idx);
};
// todo this class (like all sources in /ton/crypto/parser) is shared between FunC and tlbc
// this "shareness" and "generalization" is weird and annoying rather than solves any problems
// later on, I'll get rid of this (parser/) folder, copying and adapting its sources to FunC and tlbc
class Lexer {
SourceReader& src;
bool eof;
Lexem lexem, peek_lexem;
unsigned char char_class[128];
std::array<int, 3> eol_cmt, cmt_op, cmt_cl;
std::array<int, 3> eol_cmt, cmt_op, cmt_cl; // for FunC < 0.5.0: ;; {- -}
std::array<int, 3> eol_cmt2, cmt_op2, cmt_cl2; // for FunC >= 0.5.0: // /* */
std::string multiline_quote;
enum cc { left_active = 2, right_active = 1, active = 3, allow_repeat = 4, quote_char = 8 };
@ -78,9 +82,13 @@ class Lexer {
bool eof_found() const {
return eof;
}
Lexer(SourceReader& _src, bool init = false, std::string active_chars = ";,() ~.", std::string eol_cmts = ";;",
std::string open_cmts = "{-", std::string close_cmts = "-}", std::string quote_chars = "\"",
std::string multiline_quote = "\"\"\"");
explicit Lexer(SourceReader& _src, std::string active_chars = ";,() ~.",
std::string quote_chars = "\"", std::string multiline_quote = "\"\"\"");
void set_comment_tokens(const std::string &eol_cmts, const std::string &open_cmts, const std::string &close_cmts);
void set_comment2_tokens(const std::string &eol_cmts2, const std::string &open_cmts2, const std::string &close_cmts2);
void start_parsing();
const Lexem& next();
const Lexem& cur() const {
return lexem;