Any regex experts: I need help for nano syntax highlight rules

Discussion in 'Technical' started by mike_p, Jun 3, 2010.

  1. mike_p

    mike_p Member

    I use the nano editor for quick edits of php files on my server.

    The syntax highlighting is great apart from its ability to handle heredoc syntax for comments.

    The current 'rules' for syntax highlighting comments are:
    Code:
    color green "//.*"
    color green "#.*"
    color green start="/\*" end="\*/"
    Unfortunately the third rule causes any line starting '//*' to be seen as the start of a block of comment instead of a single line. This means that whole blocks of non-comment code get highlighted as comments. '//*' is often used by heredoc.

    I need the regex to change the third rule to accept '/*' but not '//*' for the start of a comment block.

    (I have tried various versions but my regex ability is rubbish!)

    Can anyone help. (Pretty lease!)
     
  2. mike_p

    mike_p Member

    attempts so far...

    I've tried specifying no '/' before: [^/]/\*
    - didn't work

    I've tried specifying whitespace before: \s/\*
    - that worked for spaces but not new lines
    - new lines I can easily handle as a separate case
    - but then needs to be expanded to allow whitespace as part of a character class so...

    I've tried specifying whitespace as a class before: [\s]/\*
    - didn't work !! so...

    I've tried specifying whitespace as a class (with a '*' multiplier) before: [\s]*/\*
    - didn't work !! so...

    I've tried specifying whitespace as a class (with a '+' multiplier) before: [\s]+/\*
    - didn't work !! so...

    I've tried specifying characters as a class before: [a-z]/\*
    - this works - but obviously I still need to allow whitespace etc

    I've tried specifying characters + whitespace as a class before: [a-z\s]/\*
    - works for characters, not for whitespace

    so the guesses continue...
    ------
    edited to say

    I think I've established that the nanorc regex doesn't allow for \s in character classes (ie in [] ), but will accept the posix [:space:] instead. However this still doesn't inlcude LF or CR so I need to handle the start of line separately.

    I have yet to work out how to do the simple version of saying NOT '/' before '/*', but have a useable implemenation of
    Code:
    color green start="(^/\*)|([[:alnum:][:space:].]+/\*)" end="\*/"
     
    Last edited: Jun 3, 2010
  3. cognitus

    cognitus New Member

    I know this is an old thread but I recently had this issue and found that the following fixes it.
    Code:
    color green start="(![^/])?(/\*)" end="\*/"
    The "[^/]" section indicates any character except for the forward slash. This is contained within "(!...)" signifying that the regex will not apply the syntax highlighting rule to this portion of the regex. The following "?" indicating that zero or one character, with the exception of the forward slash, can occur in front of the start of a C-style multiline comment but will not get highlighted.
     
    Last edited: Jan 28, 2019
    till likes this.

Share This Page