forked from amber-lang/amber
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
69 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use heraclitus_compiler::prelude::*; | ||
use crate::modules::expression::expr::Expr; | ||
use crate::translate::module::TranslateModule; | ||
use crate::docs::module::DocumentationModule; | ||
use crate::modules::types::{Type, Typed}; | ||
use crate::utils::{ParserMetadata, TranslateMetadata}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Len { | ||
value: Expr, | ||
} | ||
|
||
impl SyntaxModule<ParserMetadata> for Len { | ||
syntax_name!("Length"); | ||
|
||
fn new() -> Self { | ||
Len { | ||
value: Expr::new(), | ||
} | ||
} | ||
|
||
fn parse(&mut self, meta: &mut ParserMetadata) -> SyntaxResult { | ||
token(meta, "len")?; | ||
syntax(meta, &mut self.value)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl TranslateModule for Len { | ||
fn translate(&self, meta: &mut TranslateMetadata) -> String { | ||
let path_type = self.value.get_type(); | ||
let value = self.value.translate(meta); | ||
if path_type != Type::Text { | ||
format!("echo \"${{#{}}}\"", value).trim_end().to_string() | ||
} else { | ||
format!("echo \"${{#{}[@]}}\"", value).trim_end().to_string() | ||
} | ||
} | ||
} | ||
|
||
impl DocumentationModule for Len { | ||
fn document(&self, _meta: &ParserMetadata) -> String { | ||
"".to_string() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod echo; | |
pub mod mv; | ||
pub mod nameof; | ||
pub mod exit; | ||
pub mod len; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Output | ||
// 4 | ||
|
||
main { | ||
echo len [1, 2, 3, 4] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Output | ||
// 5 | ||
|
||
main { | ||
echo len "hello" | ||
} |