Move tools out of src.

This commit is contained in:
Stephen Chung
2023-03-17 07:09:56 +08:00
parent 95e7ec46ce
commit 7cda806b53
4 changed files with 0 additions and 1 deletions

7
tools/README.md Normal file
View File

@@ -0,0 +1,7 @@
Build Tools
===========
| File | Description |
| -------------- | ------------------------------------------- |
| `keywords.txt` | Input file for GNU gperf for the tokenizer. |
| `reserved.txt` | Input file for GNU gperf for the tokenizer. |

102
tools/keywords.txt Normal file
View File

@@ -0,0 +1,102 @@
// This file holds a list of keywords/symbols for the Rhai language, with mapping to
// an appropriate `Token` variant.
//
// Generate the output table via:
// ```bash
// gperf -t keywords.txt
// ```
//
// Since GNU gperf does not produce Rust output, the ANSI-C output must be hand-edited and
// manually spliced into `tokenizer.rs`.
//
// This includes:
// * Rewrite the C hashing program (especially since it uses a `switch` statement with fall-through)
// into equivalent Rust as the function `lookup_symbol_from_syntax`.
// * Update the values for the `???_KEYWORD_???` constants.
// * Copy the `asso_values` array into `KEYWORD_ASSOC_VALUES`.
// * Copy the `wordlist` array into `KEYWORDS_LIST` with the following modifications:
// - Remove the `#line` comments
// - Change the entry wrapping `{ .. }` into tuples `( .. )`
// - Replace all entries `("")` by `("", Token::EOF)`
// - Put feature flags on the appropriate lines, and duplicating lines that maps to `Token::EOF`
// for the opposite feature flags
//
struct keyword;
%%
"{", Token::LeftBrace
"}", Token::RightBrace
"(", Token::LeftParen
")", Token::RightParen
"[", Token::LeftBracket
"]", Token::RightBracket
"()", Token::Unit
"+", Token::Plus
"-", Token::Minus
"*", Token::Multiply
"/", Token::Divide
";", Token::SemiColon
":", Token::Colon
"::", Token::DoubleColon
"=>", Token::DoubleArrow
"_", Token::Underscore
",", Token::Comma
".", Token::Period
"?.", Token::Elvis
"??", Token::DoubleQuestion
"?[", Token::QuestionBracket
"..", Token::ExclusiveRange
"..=", Token::InclusiveRange
"#{", Token::MapStart
"=", Token::Equals
"true", Token::True
"false", Token::False
"let", Token::Let
"const", Token::Const
"if", Token::If
"else", Token::Else
"switch", Token::Switch
"do", Token::Do
"while", Token::While
"until", Token::Until
"loop", Token::Loop
"for", Token::For
"in", Token::In
"!in", Token::NotIn
"<", Token::LessThan
">", Token::GreaterThan
"<=", Token::LessThanEqualsTo
">=", Token::GreaterThanEqualsTo
"==", Token::EqualsTo
"!=", Token::NotEqualsTo
"!", Token::Bang
"|", Token::Pipe
"||", Token::Or
"&", Token::Ampersand
"&&", Token::And
"continue", Token::Continue
"break", Token::Break
"return", Token::Return
"throw", Token::Throw
"try", Token::Try
"catch", Token::Catch
"+=", Token::PlusAssign
"-=", Token::MinusAssign
"*=", Token::MultiplyAssign
"/=", Token::DivideAssign
"<<=", Token::LeftShiftAssign
">>=", Token::RightShiftAssign
"&=", Token::AndAssign
"|=", Token::OrAssign
"^=", Token::XOrAssign
"<<", Token::LeftShift
">>", Token::RightShift
"^", Token::XOr
"%", Token::Modulo
"%=", Token::ModuloAssign
"**", Token::PowerOf
"**=", Token::PowerOfAssign
"fn", Token::Fn
"private", Token::Private
"import", Token::Import
"export", Token::Export
"as", Token::As

93
tools/reserved.txt Normal file
View File

@@ -0,0 +1,93 @@
// This file holds a list of reserved symbols for the Rhai language.
//
// The mapped attributes are:
// - is this a reserved symbol? (bool)
// - can this keyword be called normally as a function? (bool)
// - can this keyword be called in method-call style? (bool)
//
// Generate the output table via:
// ```bash
// gperf -t reserved.txt
// ```
//
// Since GNU gperf does not produce Rust output, the ANSI-C output must be hand-edited and
// manually spliced into `tokenizer.rs`.
//
// This includes:
// * Rewrite the C hashing program (especially since it uses a `switch` statement with fall-through)
// into equivalent Rust as the function `is_reserved_keyword_or_symbol`.
// * Update the values for the `???_RESERVED_???` constants.
// * Copy the `asso_values` array into `RESERVED_ASSOC_VALUES`.
// * Copy the `wordlist` array into `RESERVED_LIST` with the following modifications:
// - Remove the `#line` comments
// - Change the entry wrapping `{ .. }` into tuples `( .. )`
// - Replace all entries `("")` by `("", false, false, false)`
// - Feature flags can be incorporated directly into the output via the `cfg!` macro
//
struct reserved;
%%
"?.", cfg!(feature = "no_object"), false, false
"?[", cfg!(feature = "no_index"), false, false
"fn", cfg!(feature = "no_function"), false, false
"private", cfg!(feature = "no_function"), false, false
"import", cfg!(feature = "no_module"), false, false
"export", cfg!(feature = "no_module"), false, false
"as", cfg!(feature = "no_module"), false, false
"===", true, false, false
"!==", true, false, false
"->", true, false, false
"<-", true, false, false
"?", true, false, false
":=", true, false, false
":;", true, false, false
"~", true, false, false
"!.", true, false, false
"::<", true, false, false
"(*", true, false, false
"*)", true, false, false
"#", true, false, false
"#!", true, false, false
"@", true, false, false
"$", true, false, false
"++", true, false, false
"--", true, false, false
"...", true, false, false
"<|", true, false, false
"|>", true, false, false
"public", true, false, false
"protected", true, false, false
"super", true, false, false
"new", true, false, false
"use", true, false, false
"module", true, false, false
"package", true, false, false
"var", true, false, false
"static", true, false, false
"shared", true, false, false
"with", true, false, false
"is", true, false, false
"goto", true, false, false
"exit", true, false, false
"match", true, false, false
"case", true, false, false
"default", true, false, false
"void", true, false, false
"null", true, false, false
"nil", true, false, false
"spawn", true, false, false
"thread", true, false, false
"go", true, false, false
"sync", true, false, false
"async", true, false, false
"await", true, false, false
"yield", true, false, false
"print", true, true, false
"debug", true, true, false
"type_of", true, true, true
"eval", true, true, false
"Fn", true, true, false
"call", true, true, true
"curry", true, true, true
"this", true, false, false
"is_def_var", true, true, false
"is_def_fn", cfg!(not(feature = "no_function")), true, false