Skip to content

Commit

Permalink
Moved fully to static lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
KrosFire committed Sep 5, 2024
1 parent c38b650 commit dd3920d
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 726 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose --all-features
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose --all-features
run: cargo test --verbose
11 changes: 0 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ authors = ["[email protected]"]
keywords = ["heraclitus", "compiler", "parser"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["compiler"]

# Include the compiler and lexer
compiler = ["lexer_dynamic"]

# Include the lexer
lexer_dynamic = []

# Include the static lexer
lexer_static = []

[dependencies]
colored = "2.0.0"
Expand Down
27 changes: 12 additions & 15 deletions src/compiling/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,37 +65,36 @@ pub enum ScopingMode {
pub struct Compiler {
/// Name of your language
pub name: String,
/// Rules that describe your language
pub rules: Rules,
/// Source code in a form of string
pub code: Option<String>,
/// Path to the compiled file if exists
pub path: Option<String>,
/// Separator mode for this compiler
pub separator_mode: SeparatorMode,
/// Scoping mode for this compiler
pub scoping_mode: ScopingMode,
// Check if user wants to debug parser
debug: bool
debug: bool,
/// Lexer to tokenize the code
lexer: Lexer
}

impl Compiler {
/// Create a new compiler with provided rules of your language
pub fn new<T: AsRef<str>>(name: T, rules: Rules) -> Self {
Compiler {
name: String::from(name.as_ref()),
rules,
code: None,
path: None,
separator_mode: SeparatorMode::Manual,
scoping_mode: ScopingMode::Block,
debug: false
debug: false,
lexer: Lexer::new(rules)
}
}

/// Set the language to use indentations
pub fn use_indents(&mut self) {
self.scoping_mode = ScopingMode::Indent
self.lexer.scoping_mode = ScopingMode::Indent
}

/// Set the language separator mode
pub fn set_separator(&mut self, mode: SeparatorMode) {
self.lexer.separator_mode = mode
}

/// Load file from path
Expand All @@ -120,9 +119,7 @@ impl Compiler {

/// Run just lexer
pub fn tokenize(&self) -> Result<Vec<Token>, LexerError> {
let mut lexer = Lexer::new(self);
lexer.run()?;
Ok(lexer.lexem)
self.lexer.tokenize(&self.code.clone().unwrap())
}

/// Parser will display information about the call stack
Expand Down
Loading

0 comments on commit dd3920d

Please sign in to comment.