Skip to content

Behavior on conflicting flags #553

Open

Description

@Commelina

Some flags, like

  • --string-token and --text-token for the Haskell backend
  • --jlex and --antlr4 for the Java backend

should not be used together. Currently, bnfc always silently takes the first (leftmost) one. Not sure what the best practice is, but this behavior should at least be noticed in docs.

Activity

  1. added this to the 2.9.7 milestone on Mar 13, 2026
  2. andreasabel commented on Mar 14, 2026

    @andreasabel
    Member

    I think taking the last (rightmost) is what most command-line tools do.

    Nowadays, when I design a new command-line tool, I add a --dry-run mode that explains what the tool would do. This includes a description of what it understood it should do, in particular, which options it is using. So one can use this mode to check how the tool understands a specific invocation, e.g. one with conflicting options.

  3. Commelina commented on Mar 14, 2026

    @Commelina
    MemberAuthor

    Yes, --dry-run is very useful.

    Also, I checked some other tools and found it is common to take the last one of exclusive options:

    • GCC:

      • For optimization levels, it uses the last one. See Optimize-Options.

        If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.

      • For warning options, it also takes the last one if the options have the same specificity (although things become much more complex with different specificities). See Warning-Options.

        The combined effect of positive and negative forms is that more specific options have priority over less specific ones, independently of their position in the command line. For options of the same specificity, the last one takes effect.

    • GHC: It also takes the last one. See Using GHC.

      Note that command-line options are order-dependent, with arguments being evaluated from left-to-right.

    • Agda: There is an issue for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions