Repository navigation
interpreter: implement RS regexp and blank-line record splitting - #133
Franklin-Qi wants to merge 1 commit into
Conversation
|
GNU awk testsuite comparison: |
|
GNU awk testsuite comparison: |
6440887 to
509fb42
Compare
|
GNU awk testsuite comparison: |
509fb42 to
35f7293
Compare
|
GNU awk testsuite comparison: |
|
Sorry about the delay, I'm in EuroRust this week. Let me get the PRs reviewed today or this weekend. |
@Alonely0 Wow, That’s great! Congratulations on attending the conference—please feel free to take care of this once you’re less busy. Btw, Europe is a great place, I was there just last year. Thanks again. |
|
a bunch of jobs are failing |
Alonely0
left a comment
There was a problem hiding this comment.
That's a lot of code hahah, github is going insane sobs. There's a bit more byte-slice indexing than I'd like, I'm slightly concerned we might split up UTF-8 codepoints.
Btw, Can you check the behavior is consistent with everything that's detailed here, especially about RS="" vs RS="\n\n+", and add tests for it? Thanks! https://www.gnu.org/software/gawk/manual/html_node/Multiple-Line.html#index-dark-corner-multiline-records
Also, I maintain the minrx & minrx-sys crates, so if there's a feature we could use there or something you'd like to see changed, lmk.
| /// Unconsumed input left after a regexp `RS` match; cleared on each new file. | ||
| rs_leftover: StdVec<u8>, | ||
| /// Cached regexp `RS` automaton (`pattern`, `regex`); invalidated on change. | ||
| rs_regex_cache: Option<(StdVec<u8>, minrx::Regex)>, |
There was a problem hiding this comment.
Let's try to drop rs_regex_cache-adjacent duplication. I'm afraid the TODO was partially stale, since I had been working to cache it at the type level (see vm/types.rs's AwkRegex struct). We should be able to do one of two things:
- Reuse the actual
RSin the symbols table by converting it to a regex, iff gawk does observably type-taint it to be a regex when matching (confirm by triggering at least one regex match w/ RS and doing aprint typeof(RS)). - Store a new regex
Valueinrs_regex_cache: Option<Value>.
Either of the two allow us to add/reuse the methods of Value, instead of re-implementing its layout and functionality (just expose the extra methods you may need, like minrx::find_iter() if it's not there).
|
|
||
| pub fn read_record_blank_lines(&mut self, mut _reader: impl BufRead) -> Result<bool> { | ||
| todo!() | ||
| fn find_delim(haystack: &[u8], delim: &[u8]) -> Option<usize> { |
There was a problem hiding this comment.
find_delim could use a one-line doc comment.
| fn find_delim(haystack: &[u8], delim: &[u8]) -> Option<usize> { | ||
| match delim { | ||
| [] => None, | ||
| [b] => haystack.iter().position(|x| x == b), |
There was a problem hiding this comment.
This can use memchr::memchr to optimize it further. In fact, we can add match arms up to memchr3.
| /// | ||
| /// Returns `(content_len, rt_len)` where `buf[..content_len]` is the record and | ||
| /// `buf[content_len..content_len + rt_len]` is the run of separator newlines. | ||
| fn blank_line_split(buf: &[u8]) -> Option<(usize, usize)> { |
There was a problem hiding this comment.
Would this be cleaner with iterators? I'm also kinda concerned about respecting UTF-8 character boundaries; even though we need to support invalid UTF-8, we still must respect those.
Sorry for putting it off. Let me get it addressed this week; should only require setting up the compiler on windows and patching minrx on wasm. |
|
sorry, needs to be rebased! |
Wire RT as a builtin and finish the missing RS modes (multi-char regexp and RS=""). Cache the RS automaton, keep reading when a match touches the buffer end, and consume rs_leftover when RS switches mid-file. Closes: uutils#124
35f7293 to
0ee7176
Compare
|
GNU awk testsuite comparison: |
Wire RT as a builtin and finish the missing RS modes (multi-char regexp and RS="") so record boundaries and RT match gawk.
Closes: #124