Re: regexp in javascript.lang (3rd try!)
[email protected] Sun, 21 Dec 2008 15:40:49 -0600
| Newsgroups | gmane.comp.gnu.source-highlight.general |
|---|---|
| Message-ID | <[email protected]> |
Lorenzo Bettini wrote: > [email protected] wrote: >> include "c_comment.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" >> >> >> (symbol,normal,symbol) = `(\+\+|--|\)|\])(\s*)(/=?(?![*/]))` >> (number,normal,symbol) = >> `(0x[[:xdigit:]]+|(?:[[:digit:]]*\.)?[[:digit:]]+(?:[eE][+-]?[[:digit:]]+)?)(\s*)(/(?![*/]))` >> >> (normal,symbol) = `([[:alpha:]$_][[:alnum:]$_]*\s*)(/=?(?![*/]))` >> >> regexp = '/(\\.|[^*\\/])(\\.|[^\\/])*/[gim]*' >> >> include "number.lang" >> >> include "c_string.lang" >> >> include "symbols.lang" >> >> cbracket = "{|}" >> >> include "function.lang" >> > > Actually it works also this way, and it reuses most of java.lang (see > the attached file); > > what do you think? The keyword definition has to occur before the definitions with the division operator in order to correctly match things like this: /* unusual, but valid JavaScript */ throw /foo/; /* this is more likely to occur in practice */ function f() { return /foo/; } /* or this */ function g(bar) { return /foo/.test(bar); }