diff --git a/lexers/embedded/hare.xml b/lexers/embedded/hare.xml index 424cf7638..a1f110312 100644 --- a/lexers/embedded/hare.xml +++ b/lexers/embedded/hare.xml @@ -7,17 +7,11 @@ - - + + - - - - - - - + @@ -64,6 +58,9 @@ + + + diff --git a/lexers/testdata/hare.actual b/lexers/testdata/hare.actual new file mode 100644 index 000000000..f15054ebc --- /dev/null +++ b/lexers/testdata/hare.actual @@ -0,0 +1,66 @@ +use bufio; +use fmt; +use io; +use linux::timerfd; +use os; +use os::exec; +use time; +use unix::poll; + +type period = struct { + comment: str, + duration: time::duration, +}; + +const periods: [_]period = [ + period { comment = "Time to start working!", duration = 25 * time::MINUTE }, + period { comment = "Time to start resting!", duration = 5 * time::MINUTE }, + period { comment = "Time to start working!", duration = 25 * time::MINUTE }, + period { comment = "Time to start resting!", duration = 5 * time::MINUTE }, + period { comment = "Time to start working!", duration = 25 * time::MINUTE }, + period { comment = "Time to start resting!", duration = 5 * time::MINUTE }, + period { comment = "Time to start working!", duration = 25 * time::MINUTE }, + period { comment = "Time to take a nap!" , duration = 15 * time::MINUTE }, +]; + +export fn main() void = { + for (let i = 0z, paused = false; true; i = (i + 1) % len(periods)) { + let period = periods[i]; + + let cmd = exec::cmd("notify-send", "--", "theo", period.comment)!; + exec::start(&cmd)!; + + let tfd = timerfd::new(time::clock::MONOTONIC, timerfd::new_flag::NONE)!; + defer { + timerfd::unset(tfd)!; + io::close(tfd)!; + }; + timerfd::set(tfd, time::SECOND: timerfd::interval, timerfd::set_flag::NONE)!; + + let fds = [poll::pollfd { fd = tfd, events = poll::event::POLLIN, ... }, poll::pollfd { fd = os::stdin_file, events = poll::event::POLLIN, ... }]; + + for (let remaining = period.duration; remaining >= 0; poll::poll(fds, poll::INDEF)!) { + if (fds[1].revents != 0) { + match (bufio::read_line(os::stdin_file)) { + case let arr: []u8 => free(arr); + case => void; + }; + + paused = !paused; + }; + + if (paused) { + // TODO: just disable timer instead of sleeping. + time::sleep(time::SECOND); + continue; + }; + + if (fds[0].revents != 0) { + timerfd::read(tfd)!; + remaining -= time::SECOND; + let remaining_secs = remaining / time::SECOND; + fmt::printfln("{} ({:02}:{:02} remaining)", period.comment, remaining_secs / 60, remaining_secs % 60)!; + }; + }; + }; +}; diff --git a/lexers/testdata/hare.expected b/lexers/testdata/hare.expected new file mode 100644 index 000000000..dc7f75075 --- /dev/null +++ b/lexers/testdata/hare.expected @@ -0,0 +1,747 @@ +[ + {"type":"KeywordNamespace","value":"use"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"bufio"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordNamespace","value":"use"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"fmt"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordNamespace","value":"use"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"io"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordNamespace","value":"use"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"linux"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"timerfd"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordNamespace","value":"use"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"os"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordNamespace","value":"use"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"os"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"exec"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordNamespace","value":"use"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordNamespace","value":"use"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"unix"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"poll"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Keyword","value":"type"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"period"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"struct"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"comment"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"str"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"duration"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"duration"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"};"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Keyword","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"periods"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"["}, + {"type":"Keyword","value":"_"}, + {"type":"Punctuation","value":"]"}, + {"type":"Name","value":"period"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"["}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"period"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"comment"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"Time to start working!\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"duration"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"25"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"*"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"MINUTE"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"},"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"period"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"comment"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"Time to start resting!\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"duration"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"5"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"*"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"MINUTE"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"},"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"period"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"comment"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"Time to start working!\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"duration"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"25"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"*"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"MINUTE"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"},"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"period"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"comment"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"Time to start resting!\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"duration"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"5"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"*"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"MINUTE"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"},"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"period"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"comment"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"Time to start working!\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"duration"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"25"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"*"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"MINUTE"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"},"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"period"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"comment"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"Time to start resting!\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"duration"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"5"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"*"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"MINUTE"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"},"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"period"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"comment"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"Time to start working!\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"duration"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"25"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"*"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"MINUTE"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"},"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"period"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"comment"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"Time to take a nap!\""}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"duration"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"15"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"*"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"MINUTE"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"},"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"];"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Keyword","value":"export"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"fn"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"main"}, + {"type":"Punctuation","value":"()"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"void"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Keyword","value":"for"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"("}, + {"type":"Keyword","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"i"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"0z"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"paused"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameBuiltin","value":"false"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameBuiltin","value":"true"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"i"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"i"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"+"}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"1"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"%"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"len"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"periods"}, + {"type":"Punctuation","value":"))"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Keyword","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"period"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"periods"}, + {"type":"Punctuation","value":"["}, + {"type":"Name","value":"i"}, + {"type":"Punctuation","value":"];"}, + {"type":"TextWhitespace","value":"\n\n\t\t"}, + {"type":"Keyword","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"cmd"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"exec"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"cmd"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\"notify-send\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"--\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"theo\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"period"}, + {"type":"Punctuation","value":"."}, + {"type":"Name","value":"comment"}, + {"type":"Punctuation","value":")"}, + {"type":"Operator","value":"!"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Name","value":"exec"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"start"}, + {"type":"Punctuation","value":"("}, + {"type":"Operator","value":"\u0026"}, + {"type":"Name","value":"cmd"}, + {"type":"Punctuation","value":")"}, + {"type":"Operator","value":"!"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\n\t\t"}, + {"type":"Keyword","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"tfd"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"timerfd"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"new"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"clock"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"MONOTONIC"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"timerfd"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"new_flag"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"NONE"}, + {"type":"Punctuation","value":")"}, + {"type":"Operator","value":"!"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Keyword","value":"defer"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t\t\t"}, + {"type":"Name","value":"timerfd"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"unset"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"tfd"}, + {"type":"Punctuation","value":")"}, + {"type":"Operator","value":"!"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\t\t\t"}, + {"type":"Name","value":"io"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"close"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"tfd"}, + {"type":"Punctuation","value":")"}, + {"type":"Operator","value":"!"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Punctuation","value":"};"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Name","value":"timerfd"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"set"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"tfd"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"SECOND"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"timerfd"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"interval"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"timerfd"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"set_flag"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"NONE"}, + {"type":"Punctuation","value":")"}, + {"type":"Operator","value":"!"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\n\t\t"}, + {"type":"Keyword","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"fds"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"["}, + {"type":"Name","value":"poll"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"pollfd"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"fd"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"tfd"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"events"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"poll"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"event"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"POLLIN"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"..."}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"},"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"poll"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"pollfd"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"fd"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"os"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"stdin_file"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"events"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"poll"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"event"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"POLLIN"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"..."}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"}];"}, + {"type":"TextWhitespace","value":"\n\n\t\t"}, + {"type":"Keyword","value":"for"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"("}, + {"type":"Keyword","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"remaining"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"period"}, + {"type":"Punctuation","value":"."}, + {"type":"Name","value":"duration"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"remaining"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"\u003e="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"0"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"poll"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"poll"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"fds"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"poll"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"INDEF"}, + {"type":"Punctuation","value":")"}, + {"type":"Operator","value":"!"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t\t\t"}, + {"type":"Keyword","value":"if"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"fds"}, + {"type":"Punctuation","value":"["}, + {"type":"LiteralNumberInteger","value":"1"}, + {"type":"Punctuation","value":"]."}, + {"type":"Name","value":"revents"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"!="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"0"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"Keyword","value":"match"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"bufio"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"read_line"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"os"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"stdin_file"}, + {"type":"Punctuation","value":"))"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t\t"}, + {"type":"Keyword","value":"case"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"arr"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"[]"}, + {"type":"KeywordType","value":"u8"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"=\u003e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"free"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"arr"}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t\t"}, + {"type":"Keyword","value":"case"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"=\u003e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"void"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"Punctuation","value":"};"}, + {"type":"TextWhitespace","value":"\n\n\t\t\t\t"}, + {"type":"Name","value":"paused"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"!"}, + {"type":"Name","value":"paused"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\t\t\t"}, + {"type":"Punctuation","value":"};"}, + {"type":"TextWhitespace","value":"\n\n\t\t\t"}, + {"type":"Keyword","value":"if"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"paused"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"CommentSingle","value":"// TODO: just disable timer instead of sleeping.\n"}, + {"type":"TextWhitespace","value":"\t\t\t\t"}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"sleep"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"SECOND"}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"Keyword","value":"continue"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\t\t\t"}, + {"type":"Punctuation","value":"};"}, + {"type":"TextWhitespace","value":"\n\n\t\t\t"}, + {"type":"Keyword","value":"if"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"fds"}, + {"type":"Punctuation","value":"["}, + {"type":"LiteralNumberInteger","value":"0"}, + {"type":"Punctuation","value":"]."}, + {"type":"Name","value":"revents"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"!="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"0"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"Name","value":"timerfd"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"read"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"tfd"}, + {"type":"Punctuation","value":")"}, + {"type":"Operator","value":"!"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"Name","value":"remaining"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"-="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"SECOND"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"Keyword","value":"let"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"remaining_secs"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"remaining"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"/"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"time"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"SECOND"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"Name","value":"fmt"}, + {"type":"Operator","value":"::"}, + {"type":"Name","value":"printfln"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\"{} ({:02}:{:02} remaining)\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"period"}, + {"type":"Punctuation","value":"."}, + {"type":"Name","value":"comment"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"remaining_secs"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"/"}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"60"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"remaining_secs"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"%"}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"60"}, + {"type":"Punctuation","value":")"}, + {"type":"Operator","value":"!"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\t\t\t"}, + {"type":"Punctuation","value":"};"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Punctuation","value":"};"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Punctuation","value":"};"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"};"}, + {"type":"TextWhitespace","value":"\n"} +]