This repository has been archived by the owner on Jan 4, 2024. It is now read-only.
-
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.
Move rust into a package, details of template making to be worked out later. Refactor reader to something sensible. Finish standard_whitespace, and start tests for identical_whitespace.
- Loading branch information
Showing
16 changed files
with
440 additions
and
158 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.pyc | ||
__pycache__/ | ||
.venv | ||
target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 @@ | ||
[package] | ||
name = "dmoj_rust_utils" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
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,28 @@ | ||
mod codes { | ||
pub const AC: i32 = 0; | ||
pub const WA: i32 = 1; | ||
pub const PE: i32 = 2; | ||
pub const IE: i32 = 3; | ||
pub const PARTIAL: i32 = 7; | ||
} | ||
|
||
use std::process; | ||
|
||
pub fn assert_or_code(cond: bool, code: i32) { | ||
if !cond { | ||
exit(code); | ||
} | ||
} | ||
|
||
pub fn assert_or_wa(cond: bool) { | ||
assert_or_code(cond, codes::WA); | ||
} | ||
|
||
pub fn assert_or_pe(cond: bool) { | ||
assert_or_code(cond, codes::PE); | ||
} | ||
|
||
pub fn exit(code: i32) -> ! { | ||
super::pre_error(); | ||
process::exit(code); | ||
} |
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,68 @@ | ||
use super::reader::{ | ||
self, AsciiStream, ExactWhitespaceTokenizer, Tokenizer, TokenizerResult, WRONG_WHITESPACE, | ||
}; | ||
use std::io::BufRead; | ||
|
||
pub struct Handler<S: AsciiStream> { | ||
src: S, | ||
} | ||
pub fn new(src: impl BufRead) -> Handler<impl AsciiStream> { | ||
Handler { | ||
src: reader::to_ascii_stream(src), | ||
} | ||
} | ||
|
||
impl<S> Tokenizer for Handler<S> | ||
where | ||
S: AsciiStream, | ||
{ | ||
fn init(&mut self) -> TokenizerResult<()> { | ||
Ok(()) | ||
} | ||
fn expect_space(&mut self) -> TokenizerResult<()> { | ||
match self.src.next() { | ||
Some(' ') => Ok(()), | ||
_ => Err(WRONG_WHITESPACE), | ||
} | ||
} | ||
fn expect_newline(&mut self) -> TokenizerResult<()> { | ||
match self.src.next() { | ||
Some('\n') => Ok(()), | ||
_ => Err(WRONG_WHITESPACE), | ||
} | ||
} | ||
fn expect_eof(&mut self) -> TokenizerResult<()> { | ||
match self.src.next() { | ||
None => Ok(()), | ||
_ => Err(WRONG_WHITESPACE), | ||
} | ||
} | ||
fn read_token(&mut self) -> TokenizerResult<String> { | ||
let mut token = String::new(); | ||
while self.src.peek().map_or(false, |c| !c.is_ascii_whitespace()) { | ||
token.push(self.src.next().unwrap()); | ||
} | ||
if token.len() == 0 { | ||
Err(WRONG_WHITESPACE) | ||
} else { | ||
Ok(token) | ||
} | ||
} | ||
} | ||
|
||
impl<S> ExactWhitespaceTokenizer for Handler<S> | ||
where | ||
S: AsciiStream, | ||
{ | ||
fn read_line(&mut self) -> TokenizerResult<String> { | ||
let mut line = String::new(); | ||
while self.src.peek().map_or(false, |c| *c != '\n') { | ||
line.push(self.src.next().unwrap()); | ||
} | ||
if self.src.next().is_none() { | ||
Err(WRONG_WHITESPACE) | ||
} else { | ||
Ok(line) | ||
} | ||
} | ||
} |
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,8 @@ | ||
mod checker; | ||
mod identical_whitespace; | ||
mod panic_error_handler; | ||
mod reader; | ||
mod standard_whitespace; | ||
mod validating_reader; | ||
|
||
fn pre_error() {} |
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,18 @@ | ||
use super::reader::ErrorHandler; | ||
|
||
pub struct Handler; | ||
|
||
impl ErrorHandler for Handler { | ||
fn new() -> Self { | ||
Self {} | ||
} | ||
fn out_of_range(&self) -> ! { | ||
panic!("out of range") | ||
} | ||
fn parse_error(&self) -> ! { | ||
panic!("parse error") | ||
} | ||
fn wrong_whitespace(&self) -> ! { | ||
panic!("wrong whitespace") | ||
} | ||
} |
Oops, something went wrong.