pub struct Clue { /* private fields */ }Expand description
The main Clue library API This is the API that you will use to interact with Clue for most use cases It’s recommended to use this API instead of the lower level APIs unless you need to
Implementations§
source§impl Clue
impl Clue
sourcepub fn tokens(&mut self, env_tokens: bool)
pub fn tokens(&mut self, env_tokens: bool)
Sets the tokens option
If tokens is true then then the tokens option will be enabled
If tokens is false then then the tokens option will be disabled
sourcepub fn env_struct(&mut self, env_struct: bool)
pub fn env_struct(&mut self, env_struct: bool)
Sets the struct option
If struct is true then then the struct option will be enabled
If struct is false then then the struct option will be disabled
sourcepub fn bitwise_mode(&mut self, mode: BitwiseMode)
pub fn bitwise_mode(&mut self, mode: BitwiseMode)
Sets the bitwise_mode option
The bitwise_mode option is used to set the bitwise mode
See BitwiseMode for the available bitwise modes
sourcepub fn continue_mode(&mut self, mode: ContinueMode)
pub fn continue_mode(&mut self, mode: ContinueMode)
Sets the continue_mode option
The continue_mode option is used to set the continue mode
See ContinueMode for the available continue modes
sourcepub fn rawsetglobals(&mut self, env_rawsetglobal: bool)
pub fn rawsetglobals(&mut self, env_rawsetglobal: bool)
Sets the rawsetglobals option
When the rawsetglobals option is enabled, Clue will rawset(_G, …) instead of simply x = … for globals
sourcepub fn debug(&mut self, env_debug: bool)
pub fn debug(&mut self, env_debug: bool)
Sets the debug option
When the debug option is enabled, debug mode will be enabled
sourcepub fn output(&mut self, output: bool)
pub fn output(&mut self, output: bool)
Sets the output option
When the output option is enabled, the output will be printed to the console
sourcepub fn expand(&mut self, expand: bool)
pub fn expand(&mut self, expand: bool)
Sets the expand option
When the expand option is enabled, the preprocessed file will be printed to the console
sourcepub fn target(&mut self, version: Option<LuaVersion>)
pub fn target(&mut self, version: Option<LuaVersion>)
Sets the target option
The target option is used to set the target Lua version
To enable the target Lua version, set version to the desired Lua version (e.g. Some(LuaVersion::Lua53))
To disable the target Lua version, set version to None
See LuaVersion for the available Lua versions
source§impl Clue
impl Clue
sourcepub fn preprocess_code(&self, code: String) -> Result<Code, String>
pub fn preprocess_code(&self, code: String) -> Result<Code, String>
Preprocesses the given code
Takes a String containing the code to preprocess
Returns a Result containing the preprocessed code
If the code was successfully preprocessed, the Result will return a Code containing the preprocessed code
Errors
If an error occurs while preprocessing the code, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let code = clue.preprocess_code("print(\"Hello World!\")".to_owned())?;
Ok(())
}sourcepub fn preprocess_file<P: AsRef<Path> + AsRef<OsStr> + Display>(
&self,
path: P
) -> Result<Code, String>
pub fn preprocess_file<P: AsRef<Path> + AsRef<OsStr> + Display>( &self, path: P ) -> Result<Code, String>
Preprocesses the given file
Takes any type that implements AsRef<Path> and AsRef<OsStr> and Display containing the path to the file to preprocess
Returns a Result containing the preprocessed code
If the code was successfully preprocessed, the Result will return a Code containing the preprocessed code
Errors
If an error occurs while preprocessing the code, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let code = clue.preprocess_file("../examples/fizzbuzz.clue")?;
Ok(())
}source§impl Clue
impl Clue
sourcepub fn scan_preprocessed_file<P: AsRef<Path> + AsRef<OsStr> + Display>(
&self,
code: Code,
path: P
) -> Result<Vec<Token>, String>
pub fn scan_preprocessed_file<P: AsRef<Path> + AsRef<OsStr> + Display>( &self, code: Code, path: P ) -> Result<Vec<Token>, String>
Scans the given preprocessed code for tokens also taking the filename
Takes a Code containing the preprocessed code to scan
and any type that implements AsRef<Path> and AsRef<OsStr> and Display containing the filename
Returns a Result containing the scanned tokens
If the code was successfully scanned, the Result will return a Vec<Token> containing the scanned tokens
Errors
If an error occurs while scanning the code, an Err containing a String with the error message will be returned
sourcepub fn scan_preprocessed(&self, code: Code) -> Result<Vec<Token>, String>
pub fn scan_preprocessed(&self, code: Code) -> Result<Vec<Token>, String>
Scans the given preprocessed code for tokens
Takes a Code containing the preprocessed code to scan
Returns a Result containing the scanned tokens
If the code was successfully scanned, the Result will return a Vec<Token> containing the scanned tokens
Errors
If an error occurs while scanning the code, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let code = clue.preprocess_code("print(\"Hello World!\")".to_owned())?;
let tokens = clue.scan_preprocessed(code)?;
Ok(())
}sourcepub fn scan_code(&self, code: String) -> Result<Vec<Token>, String>
pub fn scan_code(&self, code: String) -> Result<Vec<Token>, String>
Scans the given code for tokens
Takes a String containing the code to scan
Returns a Result containing the scanned tokens
If the code was successfully scanned, the Result will return a Vec<Token> containing the scanned tokens
Errors
If an error occurs while scanning the code, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let tokens = clue.scan_code("print(\"Hello World!\")".to_owned())?;
Ok(())
}sourcepub fn scan_file<P: AsRef<Path> + AsRef<OsStr> + Display>(
&self,
filename: P
) -> Result<Vec<Token>, String>
pub fn scan_file<P: AsRef<Path> + AsRef<OsStr> + Display>( &self, filename: P ) -> Result<Vec<Token>, String>
Scans the given file for tokens
Takes any type that implements AsRef<Path> and AsRef<OsStr> and Display containing the path to the file to scan
Returns a Result containing the scanned tokens
If the code was successfully scanned, the Result will return a Vec<Token> containing the scanned tokens
Errors
If an error occurs while scanning the file, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let tokens = clue.scan_file("../examples/fizzbuzz.clue")?;
Ok(())
}source§impl Clue
impl Clue
sourcepub fn parse_preprocessed(
&self,
code: Code
) -> Result<(Expression, String), String>
pub fn parse_preprocessed( &self, code: Code ) -> Result<(Expression, String), String>
Parses the given preprocessed code
Takes a Code containing the preprocessed code to parse
Returns a Result containing the parsed expression
If the code was successfully parsed, the Result will return a (Expression, String) containing the parsed expression and the static variables
Errors
If an error occurs while parsing the code, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let code = clue.preprocess_code("print(\"Hello World!\")".to_owned())?;
let (expression, statics) = clue.parse_preprocessed(code)?;
Ok(())
}sourcepub fn parse_tokens(
&self,
tokens: Vec<Token>
) -> Result<(Expression, String), String>
pub fn parse_tokens( &self, tokens: Vec<Token> ) -> Result<(Expression, String), String>
Parses the given Vec of Token
Takes a Vec<Token> containing the tokens to parse
Returns a Result containing the parsed expression
If the code was successfully parsed, the Result will return a (Expression, String) containing the parsed expression and the static variables
Errors
If an error occurs while parsing the code, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let tokens = clue.scan_code("print(\"Hello World!\")".to_owned())?;
let (expression, statics) = clue.parse_tokens(tokens)?;
Ok(())
}sourcepub fn parse_code(&self, code: String) -> Result<(Expression, String), String>
pub fn parse_code(&self, code: String) -> Result<(Expression, String), String>
Parses the given code
Takes a String containing the code to parse
Returns a Result containing the parsed expression
If the code was successfully parsed, the Result will return a (Expression, String) containing the parsed expression and the static variables
Errors
If an error occurs while parsing the code, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let (expression, statics) = clue.parse_code("print(\"Hello World!\")".to_owned())?;
Ok(())
}sourcepub fn parse_file<P: AsRef<Path> + AsRef<OsStr> + Display>(
&self,
path: P
) -> Result<(Expression, String), String>
pub fn parse_file<P: AsRef<Path> + AsRef<OsStr> + Display>( &self, path: P ) -> Result<(Expression, String), String>
Parses the given file
Takes any type that implements AsRef<Path> and AsRef<OsStr> and Display containing the path to the file to parse
Returns a Result containing the parsed expression
If the code was successfully parsed, the Result will return a (Expression, String) containing the parsed expression and the static variables
Errors
If an error occurs while parsing the file, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let (expression, statics) = clue.parse_file("../examples/fizzbuzz.clue")?;
Ok(())
}source§impl Clue
impl Clue
sourcepub fn compile_tokens(&self, tokens: Vec<Token>) -> Result<String, String>
pub fn compile_tokens(&self, tokens: Vec<Token>) -> Result<String, String>
Compiles the given Vec of Token
Takes a Vec<Token> containing the tokens to compile
Returns a Result containing the compiled code
If the code was successfully compiled, the Result will return a String containing the compiled code
Errors
If an error occurs while compiling the code, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let tokens = clue.scan_code("print(\"Hello World!\")".to_owned())?;
let code = clue.compile_tokens(tokens)?;
Ok(())
}sourcepub fn compile_preprocessed(&self, code: Code) -> Result<String, String>
pub fn compile_preprocessed(&self, code: Code) -> Result<String, String>
Compiles the given preprocessed code
Takes a Code containing the preprocessed code to compile
Returns a Result containing the compiled code
If the code was successfully compiled, the Result will return a String containing the compiled code
Errors
If an error occurs while compiling the code, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let code = clue.preprocess_code("print(\"Hello World!\")".to_owned())?;
let compiled = clue.compile_preprocessed(code)?;
Ok(())
}sourcepub fn compile_ast(
&self,
(ctokens, statics): (Expression, String)
) -> Result<String, String>
pub fn compile_ast( &self, (ctokens, statics): (Expression, String) ) -> Result<String, String>
Compiles the given AST
Takes a [(Expression, String)] containing the AST to compile and the statics
Returns a Result containing the compiled code
If the code was successfully compiled, the Result will return a String containing the compiled code
Errors
If an error occurs while compiling the code, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let parse_result = clue.parse_code("print(\"Hello World!\")".to_owned())?;
let code = clue.compile_ast(parse_result)?;
Ok(())
}sourcepub fn compile_code(&self, code: String) -> Result<String, String>
pub fn compile_code(&self, code: String) -> Result<String, String>
Compiles the given code
Takes a String containing the code to compile
Returns a Result containing the compiled code
If the code was successfully compiled, the Result will return a String containing the compiled code
Errors
If an error occurs while compiling the code, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let code = clue.compile_code("print(\"Hello World!\")".to_owned())?;
Ok(())
}sourcepub fn compile_file<P: AsRef<Path> + AsRef<OsStr> + Display>(
&self,
path: P
) -> Result<String, String>
pub fn compile_file<P: AsRef<Path> + AsRef<OsStr> + Display>( &self, path: P ) -> Result<String, String>
Compiles the given file
Takes any type that implements AsRef<Path> and AsRef<OsStr> and Display containing the path to the file to compile
Returns a Result containing the compiled code
If the code was successfully compiled, the Result will return a String containing the compiled code
Errors
If an error occurs while compiling the code, an Err containing a String with the error message will be returned
Example
use clue_core::Clue;
fn main() -> Result<(), String> {
let clue = Clue::new();
let code = clue.compile_file("../examples/fizzbuzz.clue")?;
Ok(())
}