awk: a comment line next to a newline breaks the statement ("invalid statement start")

Ouverte
#164 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
76/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
awk, rust
Domaine
backend, compilers

Piste de recherche

Start by finding the parser code that reports “invalid statement start” and trace how it handles comments between statements, after an if condition, and inside function arguments. Use the three Rust tests in the issue as reproductions, then run them and confirm each succeeds with the expected output. The issue says the GNU awk suite has 31 tests affected; passing those cases is the completion criterion.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug gnu-compat good first issue

A # comment on a line of its own is rejected as a syntax error when it sits
between two statements that are separated by ; or by another comment line,
after if (...), after switch (...) {, or inside a function call argument
list. Real-world awk scripts are full of comment lines, so this is the most
frequent parse failure in the GNU test suite: 31 tests stop on it.

Reproduction

Rust (incorrect)

$ printf 'BEGIN {\n    x = 1;\n    # set y\n    y = 2\n    print x, y\n}\n' > c.awk
$ ./target/release/awk -f c.awk
Error: Syntax error
   ╭─[ c.awk:3:12 ]
 3 │     # set y
   │            ╰── Unexpected token: invalid statement start.

GNU (correct)

$ gawk -f c.awk
1 2

Other shapes that fail the same way:

BEGIN {
# first comment line
# second comment line
print 1 }

BEGIN { if (1)
    # comment
    print 2 }

BEGIN { printf("%s\n",
    # comment
    "x") }

Test

#[test]
fn comment_lines_between_statements() {
    ucmd()
        .arg("BEGIN {\n  x = 1;\n  # one\n  # two\n  y = 2\n  print x, y\n}")
        .succeeds()
        .stdout_only("1 2\n");
}

#[test]
fn comment_line_after_if_condition() {
    ucmd()
        .arg("BEGIN { if (1)\n  # why\n  print \"yes\" }")
        .succeeds()
        .stdout_only("yes\n");
}

#[test]
fn comment_line_in_argument_list() {
    ucmd()
        .arg("BEGIN { printf(\"%s-%s\\n\",\n  # first\n  \"a\",\n  # second\n  \"b\") }")
        .succeeds()
        .stdout_only("a-b\n");
}

Exposed by the GNU awk test suite: aadelete2, arrayind1, arrayind3, arynasty,
arynocls, close_status, clsflnam, delarpm2, fldterm, forcenum, forref, fpat1,
fpat4, gsubtst2, hsprint, indirectbuiltin, iolint, leaddig, lintindex, mdim3,
mdim8, nasty, profile10, profile11, profile14, profile17, regx8bit, sortglos,
strnum2, typeof6, wjposer1.

Langage dominant
Rust
Étoiles
31
Forks
13
Merge moyen
23 h 42 min
PR mergées (30 j)
29

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de uutils/awk

Toutes les issues de uutils/awk

Issues similaires

Plus d'issues Rust

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.