Highlighting regular expression literals in JavaScript code

View: New views
4 Messages — Rating Filter:   Alert me  

Highlighting regular expression literals in JavaScript code

by gnombat :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Source-highlight currently does not highlight JavaScript regular
expression literals.

http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:RegExp

I am wondering what would be the best way to highlight these?  This is
what I came up with:

include "c_comment.lang"

#
# Pattern for matching regular expression literals:
# The negative lookahead at the end protects against cases like this:
#   var foo = a / b;  /* foo is the quotient */
# Still fooled by things like this:
#   var foo = a / b / c;
#   var foo = a / f('foo/bar');
#
regexp = '/(\\.|[^\\/])+/(?![*/])'

include "number.lang"

include "c_string.lang"

keyword =
"abstract|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|final|finally|for|function|goto|if|implements|in|instanceof|interface|native|new|null|private|protected|prototype|public|return|static|super|switch|synchronized|throw|throws|this|transient|true|try|typeof|var|volatile|while|with"

include "symbols.lang"

cbracket = "{|}"

include "function.lang"


_______________________________________________
Help-source-highlight mailing list
Help-source-highlight@...
http://lists.gnu.org/mailman/listinfo/help-source-highlight

Re: Highlighting regular expression literals in JavaScript code

by Lorenzo Bettini :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

gnombat@... wrote:

> Source-highlight currently does not highlight JavaScript regular
> expression literals.
>
> http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:RegExp 
>
>
> I am wondering what would be the best way to highlight these?  This is
> what I came up with:
>
> include "c_comment.lang"
>
> #
> # Pattern for matching regular expression literals:
> # The negative lookahead at the end protects against cases like this:
> #   var foo = a / b;  /* foo is the quotient */
> # Still fooled by things like this:
> #   var foo = a / b / c;
> #   var foo = a / f('foo/bar');
> #
> regexp = '/(\\.|[^\\/])+/(?![*/])'
>
> include "number.lang"
>
> include "c_string.lang"
>
> keyword =
> "abstract|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|final|finally|for|function|goto|if|implements|in|instanceof|interface|native|new|null|private|protected|prototype|public|return|static|super|switch|synchronized|throw|throws|this|transient|true|try|typeof|var|volatile|while|with"
>
>
> include "symbols.lang"
>
> cbracket = "{|}"
>
> include "function.lang"
>

sorry for my late answer on this issue! :-)

I'll try to take a look at this problem, probably your solution should
be fine :-)

cheers
        Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


_______________________________________________
Help-source-highlight mailing list
Help-source-highlight@...
http://lists.gnu.org/mailman/listinfo/help-source-highlight

Re: Highlighting regular expression literals in JavaScript code

by gnombat :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Lorenzo Bettini wrote:

> gnombat@... wrote:
>> Source-highlight currently does not highlight JavaScript regular
>> expression literals.
>>
>> http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:RegExp 
>>
>>
>> I am wondering what would be the best way to highlight these?  This is
>> what I came up with:
>>
>> include "c_comment.lang"
>>
>> #
>> # Pattern for matching regular expression literals:
>> # The negative lookahead at the end protects against cases like this:
>> #   var foo = a / b;  /* foo is the quotient */
>> # Still fooled by things like this:
>> #   var foo = a / b / c;
>> #   var foo = a / f('foo/bar');
>> #
>> regexp = '/(\\.|[^\\/])+/(?![*/])'
>>
>> include "number.lang"
>>
>> include "c_string.lang"
>>
>> keyword =
>> "abstract|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|final|finally|for|function|goto|if|implements|in|instanceof|interface|native|new|null|private|protected|prototype|public|return|static|super|switch|synchronized|throw|throws|this|transient|true|try|typeof|var|volatile|while|with"
>>
>>
>> include "symbols.lang"
>>
>> cbracket = "{|}"
>>
>> include "function.lang"
>>
>
> sorry for my late answer on this issue! :-)
>
> I'll try to take a look at this problem, probably your solution should
> be fine :-)
>
> cheers
>     Lorenzo
>

I have been doing some additional work on it and made a few modifications:

include "c_comment.lang"

# highlight the flags    vvvvvv
regexp = '/(\\.|[^\\/])+/[gim]*(?![*/])'

include "number.lang"

include "c_string.lang"

keyword =
"abstract|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|final|finally|for|function|goto|if|implements|in|instanceof|interface|native|new|null|private|protected|prototype|public|return|static|super|switch|synchronized|throw|throws|this|transient|true|try|typeof|var|volatile|while|with"

# this was originally in the java.lang file, I removed it because I
# thought it was only for Java, but on further reflection all the
# words are reserved words in JavaScript (and "void" is an actual
# keyword), so it is best to leave it in
type = "int|byte|boolean|char|long|float|double|short|void"

include "symbols.lang"

cbracket = "{|}"

# in JavaScript, the '$' is valid in an identifier
vardef FUNCTION = '([[:alpha:]]|_|\$)[[:word:]\$]*[[:blank:]]*(?=\()'
function = $FUNCTION



_______________________________________________
Help-source-highlight mailing list
Help-source-highlight@...
http://lists.gnu.org/mailman/listinfo/help-source-highlight

Re: Highlighting regular expression literals in JavaScript code

by Lorenzo Bettini :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

gnombat@... wrote:

> Lorenzo Bettini wrote:
>> gnombat@... wrote:
>>> Source-highlight currently does not highlight JavaScript regular
>>> expression literals.
>>>
>>> http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:RegExp 
>>>
>>>
>>> I am wondering what would be the best way to highlight these?  This
>>> is what I came up with:
>>>
>>> include "c_comment.lang"
>>>
>>> #
>>> # Pattern for matching regular expression literals:
>>> # The negative lookahead at the end protects against cases like this:
>>> #   var foo = a / b;  /* foo is the quotient */
>>> # Still fooled by things like this:
>>> #   var foo = a / b / c;
>>> #   var foo = a / f('foo/bar');
>>> #
>>> regexp = '/(\\.|[^\\/])+/(?![*/])'
>>>
>>> include "number.lang"
>>>
>>> include "c_string.lang"
>>>
>>> keyword =
>>> "abstract|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|final|finally|for|function|goto|if|implements|in|instanceof|interface|native|new|null|private|protected|prototype|public|return|static|super|switch|synchronized|throw|throws|this|transient|true|try|typeof|var|volatile|while|with"
>>>
>>>
>>> include "symbols.lang"
>>>
>>> cbracket = "{|}"
>>>
>>> include "function.lang"
>>>
>>
>> sorry for my late answer on this issue! :-)
>>
>> I'll try to take a look at this problem, probably your solution should
>> be fine :-)
>>
>> cheers
>>     Lorenzo
>>
>
> I have been doing some additional work on it and made a few modifications:
>
> include "c_comment.lang"
>
> # highlight the flags    vvvvvv
> regexp = '/(\\.|[^\\/])+/[gim]*(?![*/])'
>
> include "number.lang"
>
> include "c_string.lang"
>
> keyword =
> "abstract|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|final|finally|for|function|goto|if|implements|in|instanceof|interface|native|new|null|private|protected|prototype|public|return|static|super|switch|synchronized|throw|throws|this|transient|true|try|typeof|var|volatile|while|with"
>
>
> # this was originally in the java.lang file, I removed it because I
> # thought it was only for Java, but on further reflection all the
> # words are reserved words in JavaScript (and "void" is an actual
> # keyword), so it is best to leave it in
> type = "int|byte|boolean|char|long|float|double|short|void"
>
> include "symbols.lang"
>
> cbracket = "{|}"
>
> # in JavaScript, the '$' is valid in an identifier
> vardef FUNCTION = '([[:alpha:]]|_|\$)[[:word:]\$]*[[:blank:]]*(?=\()'
> function = $FUNCTION
>

the new version (2.8) contains your changes :-)
thanks!

cheers
        Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


_______________________________________________
Help-source-highlight mailing list
Help-source-highlight@...
http://lists.gnu.org/mailman/listinfo/help-source-highlight