Skip to content

CypherLexer double forward slash in string is always a comment #1364

@edwardanderson

Description

@edwardanderson

Double forward slashes // used in a Cypher expression are tokenised as comments by the CypherLexer() no matter where they appear.

This blocks users from using URIs (for example) as parameter values.

from pygments.lexers import CypherLexer
lexer = CypherLexer()
s = '(p:Person {uri:"http://example.com/thing/1"})'
print(list(lexer.get_tokens(s)))

[(Token.Comment.Single, '(p:Person {uri="http://example.com/thing/1"})\n')]

I would like to be able to escape the slashes but have not had success with \/\/ or backticks. If character escaping cannot be used, perhaps the regular expression in the lexer could be modified? It could instead only capture comments which:

  • begin the line
  • appear anywhere but are preceded by whitespace

From:

        'comment': [
            (r'^.*//.*\n', Comment.Single),
        ]

To:

        'comment': [
            (r'(?:[\s^])(//.*)\n', Comment.Single),
        ]

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