init [skip ci]
This commit is contained in:
commit
49754c51e1
16
.codecrafters/compile.sh
Executable file
16
.codecrafters/compile.sh
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script is used to compile your program on CodeCrafters
|
||||
#
|
||||
# This runs before .codecrafters/run.sh
|
||||
#
|
||||
# Learn more: https://codecrafters.io/program-interface
|
||||
|
||||
# Exit early if any commands fail
|
||||
set -e
|
||||
|
||||
cargo build \
|
||||
--quiet \
|
||||
--release \
|
||||
--target-dir=/tmp/codecrafters-interpreter-target \
|
||||
--manifest-path Cargo.toml
|
||||
9
.codecrafters/run.sh
Executable file
9
.codecrafters/run.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script is used to run your program on CodeCrafters
|
||||
#
|
||||
# This runs after .codecrafters/compile.sh
|
||||
#
|
||||
# Learn more: https://codecrafters.io/program-interface
|
||||
|
||||
exec /tmp/codecrafters-interpreter-target/release/interpreter-starter-rust "$@"
|
||||
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
* text=auto
|
||||
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
79
Cargo.lock
generated
Normal file
79
Cargo.lock
generated
Normal file
@ -0,0 +1,79 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"
|
||||
|
||||
[[package]]
|
||||
name = "interpreter-starter-rust"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.48"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
24
Cargo.toml
Normal file
24
Cargo.toml
Normal file
@ -0,0 +1,24 @@
|
||||
# DON'T EDIT THIS!
|
||||
#
|
||||
# Codecrafters relies on this file being intact to run tests successfully. Any changes
|
||||
# here will not reflect when CodeCrafters tests your code, and might even cause build
|
||||
# failures.
|
||||
#
|
||||
# DON'T EDIT THIS!
|
||||
[package]
|
||||
name = "interpreter-starter-rust"
|
||||
version = "0.1.0"
|
||||
authors = ["Codecrafters <hello@codecrafters.io>"]
|
||||
edition = "2021"
|
||||
|
||||
# DON'T EDIT THIS!
|
||||
#
|
||||
# Codecrafters relies on this file being intact to run tests successfully. Any changes
|
||||
# here will not reflect when CodeCrafters tests your code, and might even cause build
|
||||
# failures.
|
||||
#
|
||||
# DON'T EDIT THIS!
|
||||
[dependencies]
|
||||
anyhow = "1.0.68" # error handling
|
||||
bytes = "1.3.0" # helps manage buffers
|
||||
thiserror = "1.0.38" # error handling
|
||||
52
README.md
Normal file
52
README.md
Normal file
@ -0,0 +1,52 @@
|
||||
[](https://app.codecrafters.io/users/codecrafters-bot?r=2qF)
|
||||
|
||||
This is a starting point for Rust solutions to the
|
||||
["Build Your Own Build your own Interpreter" Challenge](https://app.codecrafters.io/courses/interpreter/overview).
|
||||
|
||||
This challenge follows the book
|
||||
[Crafting Interpreters](https://craftinginterpreters.com/) by Robert Nystrom.
|
||||
|
||||
In this challenge you'll build an interpreter for
|
||||
[Lox](https://craftinginterpreters.com/the-lox-language.html), a simple
|
||||
scripting language. Along the way, you'll learn about tokenization, ASTs,
|
||||
tree-walk interpreters and more.
|
||||
|
||||
Before starting this challenge, make sure you've read the "Welcome" part of the
|
||||
book that contains these chapters:
|
||||
|
||||
- [Introduction](https://craftinginterpreters.com/introduction.html) (chapter 1)
|
||||
- [A Map of the Territory](https://craftinginterpreters.com/a-map-of-the-territory.html)
|
||||
(chapter 2)
|
||||
- [The Lox Language](https://craftinginterpreters.com/the-lox-language.html)
|
||||
(chapter 3)
|
||||
|
||||
These chapters don't involve writing code, so they won't be covered in this
|
||||
challenge. This challenge will start from chapter 4,
|
||||
[Scanning](https://craftinginterpreters.com/scanning.html).
|
||||
|
||||
**Note**: If you're viewing this repo on GitHub, head over to
|
||||
[codecrafters.io](https://codecrafters.io) to try the challenge.
|
||||
|
||||
# Passing the first stage
|
||||
|
||||
The entry point for your program is in `src/main.rs`. Study and uncomment the
|
||||
relevant code, and push your changes to pass the first stage:
|
||||
|
||||
```sh
|
||||
git add .
|
||||
git commit -m "pass 1st stage" # any msg
|
||||
git push origin master
|
||||
```
|
||||
|
||||
Time to move on to the next stage!
|
||||
|
||||
# Stage 2 & beyond
|
||||
|
||||
Note: This section is for stages 2 and beyond.
|
||||
|
||||
1. Ensure you have `cargo (1.77)` installed locally
|
||||
2. Run `./your_program.sh` to run your program, which is implemented in
|
||||
`src/main.rs`. This command compiles your Rust project, so it might be slow
|
||||
the first time you run it. Subsequent runs will be fast.
|
||||
3. Commit your changes and run `git push origin master` to submit your solution
|
||||
to CodeCrafters. Test output will be streamed to your terminal.
|
||||
11
codecrafters.yml
Normal file
11
codecrafters.yml
Normal file
@ -0,0 +1,11 @@
|
||||
# Set this to true if you want debug logs.
|
||||
#
|
||||
# These can be VERY verbose, so we suggest turning them off
|
||||
# unless you really need them.
|
||||
debug: false
|
||||
|
||||
# Use this to change the Rust version used to run your code
|
||||
# on Codecrafters.
|
||||
#
|
||||
# Available versions: rust-1.77
|
||||
language_pack: rust-1.77
|
||||
37
src/main.rs
Normal file
37
src/main.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::{self, Write};
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if args.len() < 3 {
|
||||
writeln!(io::stderr(), "Usage: {} tokenize <filename>", args[0]).unwrap();
|
||||
return;
|
||||
}
|
||||
|
||||
let command = &args[1];
|
||||
let filename = &args[2];
|
||||
|
||||
match command.as_str() {
|
||||
"tokenize" => {
|
||||
// You can use print statements as follows for debugging, they'll be visible when running tests.
|
||||
writeln!(io::stderr(), "Logs from your program will appear here!").unwrap();
|
||||
|
||||
let file_contents = fs::read_to_string(filename).unwrap_or_else(|_| {
|
||||
writeln!(io::stderr(), "Failed to read file {}", filename).unwrap();
|
||||
String::new()
|
||||
});
|
||||
|
||||
// Uncomment this block to pass the first stage
|
||||
// if !file_contents.is_empty() {
|
||||
// panic!("Scanner not implemented");
|
||||
// } else {
|
||||
// println!("EOF null"); // Placeholder, remove this line when implementing the scanner
|
||||
// }
|
||||
}
|
||||
_ => {
|
||||
writeln!(io::stderr(), "Unknown command: {}", command).unwrap();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
your_program.sh
Executable file
28
your_program.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Use this script to run your program LOCALLY.
|
||||
#
|
||||
# Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
|
||||
#
|
||||
# Learn more: https://codecrafters.io/program-interface
|
||||
|
||||
set -e # Exit early if any commands fail
|
||||
|
||||
# Copied from .codecrafters/compile.sh
|
||||
#
|
||||
# - Edit this to change how your program compiles locally
|
||||
# - Edit .codecrafters/compile.sh to change how your program compiles remotely
|
||||
(
|
||||
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
|
||||
cargo build \
|
||||
--quiet \
|
||||
--release \
|
||||
--target-dir=/tmp/codecrafters-interpreter-target \
|
||||
--manifest-path Cargo.toml
|
||||
)
|
||||
|
||||
# Copied from .codecrafters/run.sh
|
||||
#
|
||||
# - Edit this to change how your program runs locally
|
||||
# - Edit .codecrafters/run.sh to change how your program runs remotely
|
||||
exec /tmp/codecrafters-interpreter-target/release/interpreter-starter-rust "$@"
|
||||
Loading…
x
Reference in New Issue
Block a user