Skip to content

Highlightjs not respecting parent regex of a sub mode #2238

@algomaster99

Description

@algomaster99

I need to write a lexer which highlights my command-line tool commands properly.

$ dvc add file.csv
$ dvc pipeline list

So the command starts with dvc and it may have one or two subcommands - add or pipeline list respectively.

Therefore, it should highlight dvc add and dvc pipeline list in first and second case respectively.

contains: [
  {
    begin: /^\s*\$\s(dvc|git) [a-z-]+/,
    returnBegin: true,
    contains: [
      {
        begin: /dvc [a-z-]+ ?/,
        lexemes: '[a-z-]+',
        keywords: {
          built_in:
             'dvc'
          },
          contains: [
            {
              begin: /\w+(?![\S])/,
              keywords: {
                built_in: 'list'
              }
            }
          ],
          className: 'strong'
        }
      ]
    }
 ]

It matches $ dvc pipeline list even though the parent regex i.e. /^\s*\$\s(dvc|git) [a-z-]+/ and should only match till $ dvc pipeline. How is it exactly functioning?

How does /dvc [a-z-]+ ?/ override it and continues matching the expression?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions