Struct clue_core::Clue

source ·
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

source

pub fn new() -> Self

Create a new Clue instance

source

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

source

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

source

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

source

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

source

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

source

pub fn debug(&mut self, env_debug: bool)

Sets the debug option When the debug option is enabled, debug mode will be enabled

source

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

source

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

source

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

pub fn target_os(&mut self, os: String)

Sets the target_os option The target_os option is used to set the target operating system See [std::env::const::OS] for specifying the operating system

source§

impl Clue

source

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(())
}
source

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

source

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

source

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(())
}
source

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(())
}
source

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

source

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(())
}
source

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(())
}
source

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(())
}
source

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

source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}

Trait Implementations§

source§

impl Default for Clue

Creates a new Clue instance with the default options

Example

use clue_core::Clue;

let clue = Clue::default();
source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Clue

§

impl Send for Clue

§

impl Sync for Clue

§

impl Unpin for Clue

§

impl UnwindSafe for Clue

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.