Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,47 +183,47 @@ pub enum Token<'a> {
Lshift,
#[token("rshift", |lex| parse_non_posix_keyword(lex, Token::Rshift))]
Rshift,
#[regex("(awk::)?NR", accept_expression)]
#[regex("(awk::)?NR", accept_operator)]
NrVariable,
#[regex("(awk::)?NF", accept_expression)]
#[regex("(awk::)?NF", accept_operator)]
NfVariable,
#[regex("(awk::)?FS", accept_expression)]
#[regex("(awk::)?FS", accept_operator)]
FsVariable,
#[regex("(awk::)?FPAT", accept_expression)]
#[regex("(awk::)?FPAT", accept_operator)]
FpatVariable,
#[regex("(awk::)?FIELDWIDTHS", accept_expression)]
#[regex("(awk::)?FIELDWIDTHS", accept_operator)]
FieldwidthsVariable,
#[regex("(awk::)?RS", accept_expression)]
#[regex("(awk::)?RS", accept_operator)]
RsVariable,
#[regex("(awk::)?OFS", accept_expression)]
#[regex("(awk::)?OFS", accept_operator)]
OfsVariable,
#[regex("(awk::)?ORS", accept_expression)]
#[regex("(awk::)?ORS", accept_operator)]
OrsVariable,
#[regex("(awk::)?FILENAME", accept_expression)]
#[regex("(awk::)?FILENAME", accept_operator)]
FilenameVariable,
#[regex("(awk::)?ARGC", accept_expression)]
#[regex("(awk::)?ARGC", accept_operator)]
ArgcVariable,
#[regex("(awk::)?ARGV", accept_expression)]
#[regex("(awk::)?ARGV", accept_operator)]
ArgvVariable,
#[regex("(awk::)?SUBSEP", accept_expression)]
#[regex("(awk::)?SUBSEP", accept_operator)]
SubsepVariable,
#[regex("(awk::)?FNR", accept_expression)]
#[regex("(awk::)?FNR", accept_operator)]
FnrVariable,
#[regex("(awk::)?ARGIND")]
#[regex("(awk::)?ARGIND", accept_operator)]
ArgindVariable,
#[regex("(awk::)?OFMT", accept_expression)]
#[regex("(awk::)?OFMT", accept_operator)]
OfmtVariable,
#[regex("(awk::)?RSTART", accept_expression)]
#[regex("(awk::)?RSTART", accept_operator)]
RstartVariable,
#[regex("(awk::)?RLENGTH", accept_expression)]
#[regex("(awk::)?RLENGTH", accept_operator)]
RlengthVariable,
#[regex("(awk::)?ENVIRON", accept_expression)]
#[regex("(awk::)?ENVIRON", accept_operator)]
EnvironVariable,
#[regex("(awk::)?PROCINFO", accept_expression)]
#[regex("(awk::)?PROCINFO", accept_operator)]
ProcinfoVariable,
#[regex("(awk::)?SYMTAB", accept_expression)]
#[regex("(awk::)?SYMTAB", accept_operator)]
SymtabVariable,
#[regex("(awk::)?FUNCTAB", accept_expression)]
#[regex("(awk::)?FUNCTAB", accept_operator)]
FunctabVariable,
#[regex("(?&identifier)", Identifier::parse::<0>)]
Identifier(Identifier<'a>),
Expand Down
5 changes: 4 additions & 1 deletion lexer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,16 @@ fn lexer_test_general_tokens() {
fn lexer_test_regex_ambiguity() {
let arena = Bump::new();
assert_eq!(
&lex(b"1/=1. a/=1", &arena, false, false),
&lex(b"1/=1. a/=1 NR/=1", &arena, false, false),
&[
Token::Integer(1),
Token::SlashAssign,
Token::Number(1.),
Token::Identifier(Identifier { literal: "a" }),
Token::SlashAssign,
Token::Integer(1),
Token::NrVariable,
Token::SlashAssign,
Token::Integer(1)
]
);
Expand Down
9 changes: 9 additions & 0 deletions tests/by-util/test_awk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,3 +899,12 @@ fn bare_regex_in_expression_matches_record() {
.succeeds()
.stdout_is("y 2\n2\n");
}

#[test]
fn slash_after_special_variable_divides() {
ucmd()
.arg("{ print NR / 2, NF/NR } END { RSTART = 8; print RSTART / 2 / 2; NR = 6; NR /= 2; print NR }")
.pipe_in("a b\nc d\n")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please also cover NR /= 2 here?
and maybe add NR/=1 to lexer_test_regex_ambiguity in lexer/src/tests.rs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added both in f15885c: NR /= 2 in slash_after_special_variable_divides, and NR/=1 in lexer_test_regex_ambiguity (it fails on main, where /=1 starts a regex). The test sets NR first (NR = 6; NR /= 2), because on main NR in END after a file is still 0 (#140), and gawk keeps NR an integer, so NR /= 2 in a main rule truncates there.

.succeeds()
.stdout_only("0.5 2\n1 1\n2\n3\n");
}
Loading