diff --git a/README.md b/README.md index 28210bc..1e249ef 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,30 @@ Benvenuto! Welcome to Trallalelo Lang, the most whimsical and brain-tickling programming language inspired by the finest Italian-flavored brainrot. -## Documentation +## Getting Started -(Coming soon) +To run a Trallalelo program, you need to have Rust installed. Then, you can use the following command: -## Ciao! +```bash +cargo run -- .tralla +``` + +## Syntax + +A Trallalelo program must start with `Tralalero Tralala` and end with `Bombardiro Crocodilo`. + +## Keywords + +### `Tralalero Tralala` + +This is the entry point of the program. It must be the first line of your code. + +### `Bombardiro Crocodilo` + +This is the exit point of the program. It must be the last line of your code. + +### `Matteeeo bambini gusini ""` + +This command prints a message to the console. The message must be enclosed in double quotes. + +## Ciao! \ No newline at end of file diff --git a/hello_world.tralla b/hello_world.tralla new file mode 100644 index 0000000..19eebb6 --- /dev/null +++ b/hello_world.tralla @@ -0,0 +1,3 @@ +Tralalero Tralala +Matteeeo bambini gusini "Hello, World!" +Bombardiro Crocodilo diff --git a/src/main.rs b/src/main.rs index e7a11a9..c793cf2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,42 @@ +use std::env; +use std::fs; + fn main() { - println!("Hello, world!"); + let args: Vec = env::args().collect(); + if args.len() < 2 { + println!("Please provide a file to run"); + return; + } + + let file_path = &args[1]; + let content = fs::read_to_string(file_path).expect("Could not read the file"); + + let lines: Vec<&str> = content.lines().collect(); + + if lines.is_empty() || lines[0] != "Tralalero Tralala" { + println!("The program must start with 'Tralalero Tralala'"); + return; + } + + if lines.last() != Some(&"Bombardiro Crocodilo") { + println!("The program must end with 'Bombardiro Crocodilo'"); + return; + } + + for line in lines.iter().skip(1).rev().skip(1).rev() { + parse_and_execute(line); + } +} + +fn parse_and_execute(line: &str) { + if line.starts_with("Matteeeo bambini gusini") { + let parts: Vec<&str> = line.splitn(2, ' ').collect(); + if parts.len() > 1 { + let string_to_print = parts[1] + .trim_start_matches("bambini gusini") + .trim() + .trim_matches('"'); + println!("{}", string_to_print); + } + } }