From de9e10dff077af0a155d66c5f965e23197b27c17 Mon Sep 17 00:00:00 2001 From: Aleksey Yakovlev Date: Wed, 10 Jul 2024 23:54:31 +0700 Subject: [PATCH] - proper new line in grammar - logger logs errors red --- Cargo.toml | 2 +- grammar.pest | 23 ++++++++++++++++------- sample.hexo | 3 ++- src/compiler/rst/compiler.rs | 3 +-- src/util/logger.rs | 2 +- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 89037b1..bf185dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/grammar.pest b/grammar.pest index 1feed8d..50b2609 100644 --- a/grammar.pest +++ b/grammar.pest @@ -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 ~ "}" } @@ -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 } diff --git a/sample.hexo b/sample.hexo index 8ce030a..c6087ad 100644 --- a/sample.hexo +++ b/sample.hexo @@ -1 +1,2 @@ -> #eval(#read_file('samples/java_object/input.hexo')) \ No newline at end of file +> #eval(#read_file('samples/java_object/input.hex')) + diff --git a/src/compiler/rst/compiler.rs b/src/compiler/rst/compiler.rs index 0633ae9..ba23cb8 100644 --- a/src/compiler/rst/compiler.rs +++ b/src/compiler/rst/compiler.rs @@ -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); } diff --git a/src/util/logger.rs b/src/util/logger.rs index b1d0212..314e4c6 100644 --- a/src/util/logger.rs +++ b/src/util/logger.rs @@ -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) {