By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 1,944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

Javascript RegEx problem

P: n/a
I am working on modifying a syntax highlighter written in
javascript and it uses several regexes. I need to add a
language to the avail highlighters and need the following regexes
modified to parse the new language, Delphi/Pascal. Source to the
highlighter is avail here:
http://www.dreamprojections.com/Synt...r/Default.aspx
**********************************************
COMMENTS
**********************************************
regex = new RegExp('//.*$|/\\*[^\\*]*(.)*?\\*/', 'gm');
Matches- single line comment: '// ' until end of line
multi line comment '{' until closing '}'
Example:

// This is a Comment

{
This is
a multiline comment
}

**********************************************
STRINGS
**********************************************
regex = new RegExp('"(?:\\.|[^\\""])*"', 'g');
Matches - any text enclosed in single quotes
if the string contains single quotes it will be
escaped like this:
'isn''t that grand'
Example:

'this is a string'

**********************************************
DIRECTIVES/REGIONS
**********************************************
regex = new RegExp('^\\s*{/$.*', 'gm');
Matches - '{' followed by '$' followed by 1+ Alpha chars
closed with '}'
Example:

{$IFDEF YAHOO} // this is a directive
{$ELSE YAHOO} // this is a directive
{$ENDDEF YAHOO} // this is a directive

{$R *.res} // this is a directive

**********************************************
NUMBERS
**********************************************
regex = new RegExp('/[^\d]/gi', 'g');
Matches - integer = numeric chars only
float = numerics and decimal only, no commas
hex = '$' foloewd by any combination of 'A'-'F'
and/or 0-9
Example:

x := x + 1234; // example of a number
y := y + 1.0; // example of a float number
z := $FFAA; // example of a hex number
for instance, in the first example:
regex = new RegExp('//.*$|/\\*[^\\*]*(.)*?\\*/', 'gm');
Matches - single line comment: '// ' until end of line
multi line comment '{' until closing '}'
Example:

// This is a Comment

{
This is
a multiline comment
}
the line:
regex = new RegExp('//.*$|/\\*[^\\*]*(.)*?\\*/', 'gm');

is the current regex.

the line(s):
- single line comment: '// ' until end of line
multi line comment '{' until closing '}'

spell out what I want the regex to match

and this:
Example:

// This is a Comment

{
This is
a multiline comment
}
Here is another one that I can't figure out.

Source:
asm
MOV AX,1234H
MOV Number,AX
end;

Need to match everything between the 'asm' and 'end;'
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
JRS: In article <1107269716.711be950c458361567b8868ee0225138@teran ews>,
dated Tue, 1 Feb 2005 08:55:14, seen in news:comp.lang.javascript, Mr.
Clean <mrclean@p&g.com> posted :
I am working on modifying a syntax highlighter written in
javascript and it uses several regexes. I need to add a
language to the avail highlighters and need the following regexes
modified to parse the new language, Delphi/Pascal. Source to the
highlighter is avail here:
http://www.dreamprojections.com/Synt...r/Default.aspx
**********************************************
COMMENTS
**********************************************
regex = new RegExp('//.*$|/\\*[^\\*]*(.)*?\\*/', 'gm');
Matches- single line comment: '// ' until end of line
multi line comment '{' until closing '}'
Needs also to support comment (* ... *).
One type of comment can contain the opening symbol for another.

**********************************************
DIRECTIVES/REGIONS
**********************************************
regex = new RegExp('^\\s*{/$.*', 'gm');
Matches - '{' followed by '$' followed by 1+ Alpha chars
closed with '}'
Also (*$ ... *)

**********************************************
NUMBERS
**********************************************
regex = new RegExp('/[^\d]/gi', 'g');
Matches - integer = numeric chars only
float = numerics and decimal only, no commas
hex = '$' foloewd by any combination of 'A'-'F'
and/or 0-9


Also needs to handle such as 3.5e4 6.99E-07 .

Note that, to aid Continentals, (. and .) can be used for [ and ] -
there may be others similar that I have forgotten.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
Jul 23 '05 #2

P: n/a
<SNIP>
Also needs to handle such as 3.5e4 6.99E-07 .

Note that, to aid Continentals, (. and .) can be used for [ and ] -
there may be others similar that I have forgotten.


You know John, I forgot that you hangout here, too.
I am not even familiar with regex expressions. This is
a mod to allow a highlighter, noted below, to highlight Delphi
code.

The author was familiar with Delphi and got one working but
a few things were left out. The things you noted above and
asm blocks. I know that a parser will probably need to be
written to do the asm block kind of like how he did XML.

I know you know Delphi so would you be kind enough to help out?

http://www.dreamprojections.com/Synt...r/Default.aspx
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.