Skip to content

Commit

Permalink
- proper new line in grammar
Browse files Browse the repository at this point in the history
- logger logs errors red
  • Loading branch information
lexa-diky committed Jul 10, 2024
1 parent dfc100a commit de9e10d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hexo"
version = "0.9.1"
version = "0.9.2"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/lexa-diky/hexo"
Expand Down
23 changes: 16 additions & 7 deletions grammar.pest
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
// default symbols
WHITESPACE = _{ " "+ }
COMMENT = _{ "//" ~ (!"\n" ~ ANY)+ }

// language custom symbols
GL_EMIT = _{ ">" }
GL_CONST = _{ "$" }
GL_FN = _{ "#" }
SY_BRO = _{ "(" }
SY_BRC = _{ ")" }
SY_UNDERSCORE = _{ "_" }

// IDENTIFIER
identifier = _{ (ASCII_ALPHANUMERIC | "_")+ }
identifier = _{ (ASCII_ALPHANUMERIC | SY_UNDERSCORE)+ }


file = _{ SOI ~ body ~ EOI }
body = _{ "\n"* ~ (statement ~ "\n"+) * ~ statement? }
body = _{ NEWLINE* ~ (statement ~ NEWLINE+) * ~ statement? }

statement = _{ const_statement | emit_statement | fn_statement }
emit_statement = { ">" ~ atomic_strip }
const_statement = { "$" ~ const_statement_name ~ atomic_strip }
emit_statement = { GL_EMIT ~ atomic_strip }
const_statement = { GL_CONST ~ const_statement_name ~ atomic_strip }
const_statement_name = @{ identifier }
fn_statement = { "#" ~ fn_statement_name ~ fn_statement_body }
fn_statement = { GL_FN ~ fn_statement_name ~ fn_statement_body }
fn_statement_name = @{ identifier }
fn_statement_body = { "{" ~ body ~ "}" }

Expand All @@ -27,9 +36,9 @@ atom = _{ atom_body ~ WHITESPACE? }
atom_utf8 = { ( "''" | (!"'" ~ ANY) )* }
atom_utf8_decor = _{ "'" ~ atom_utf8 ~ "'" }
atom_const = @{ identifier }
atom_const_decor = _{ "$" ~ atom_const }
atom_const_decor = _{ GL_CONST ~ atom_const }

atom_fn = { "#" ~ atom_fn_name ~ "(" ~ atom_fn_params? ~ ")" }
atom_fn = { GL_FN ~ atom_fn_name ~ SY_BRO ~ atom_fn_params? ~ SY_BRC }
atom_fn_name = { identifier }
atom_fn_params = { (atom_fn_param ~ ",")* ~ atom_fn_param }
atom_fn_param_identifier = { identifier }
Expand Down
3 changes: 2 additions & 1 deletion sample.hexo
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
> #eval(#read_file('samples/java_object/input.hexo'))
> #eval(#read_file('samples/java_object/input.hex'))

3 changes: 1 addition & 2 deletions src/compiler/rst/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ impl RstCompiler<'_> {

for param in params {
let mut param_buffer = ByteBuffer::default();
self.build_bytes_into(context_id, context, param.value(), &mut param_buffer)
.unwrap();
self.build_bytes_into(context_id, context, param.value(), &mut param_buffer)?;

params_buffer.insert(param.name().to_string(), param_buffer);
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl HexoLogger {
}

pub(crate) fn error(&self, message: &str) {
eprintln!("{message}");
eprintln!("{}", style(message).red());
}

pub(crate) fn info(&self, message: &str) {
Expand Down

0 comments on commit de9e10d

Please sign in to comment.