Skip to content

Positive lookahead isn't working #1550

@revosw

Description

@revosw

In my language definition, a function is defined by this
/\b[a-z]\w*(?=\()/

Word boundary, followed by a lowercase letter, followed by zero or more word characters, up to but not including the left parenthesis. However, the positive lookahead isn't working.

This is the result from the regex defined above, with the positive lookahead:
Pastebin

image

And this is for this regex: /\b[a-z]\w*(/
Basically the same, except up to but including the left parenthesis

image

My code looks like this:

function(hljs) {
  return {
    alias: ["e2", "wire_e2", "expression2", "exp2", "expr2"],
    keywords: 'if elseif else for foreach while break continue local switch case default function return',
    illegal: "'",
    contains: [
      {
        className: 'string',
        begin: /(")(\\[\s\S]|(?!\1)[^\\])*\1/g,
        relevance: 0
      },
      {
        className: 'ppcommand',
        begin: /#(include|ifdef|ifndef|else|endif)/,
        relevance: 10
      },
      hljs.COMMENT('#\\[', ']#'),
      hljs.HASH_COMMENT_MODE,
      {
        className: 'directive',
        begin: /@(name.*|model.*|inputs|outputs|persist|trigger|autoupdate)/,
        relevance: 10
      },
      {
        className: 'constant',
        begin: /\b_[A-Z0-9_]+/
      },
      {
        className: 'variable',
        begin: /\b[A-Z]\w*/,
        relevance: 0
      },
      {
        className: 'function',
        begin: /\b[a-z]\w*\(/,
        relevance: 0
      },
      {
        // (angle|array|bone|complex|entity|matrix[24]?|number|quaternion|ranger|string|table|vector[24]?|void|wirelink)
        className: 'type',
        begin: /\b(angle|array|bone|complex|entity|matrix[24]?|number|quaternion|ranger|string|table|vector[24]?|void|wirelink)(?!\()\b/g,
        illegal: "\\(",
        relevance: 0
      },
      {
        className: 'number',
        begin: /(-?)(\b0x[A-F0-9]+|\b0b[01]+|(\b\d+(\.\d*)?|\.\d+)(e[-+]?\d+)?)/,
        relevance: 0
      }
    ]
  }
}

If there are any workarounds to this, suggestions are gladly appreciated

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugenhancementAn enhancement or new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions