NAME

Regexp::Common::comment -- provide regexes for comments.

SYNOPSIS

use Regexp::Common qw /comment/;

while (<>) {
    /$RE{comment}{C}/       and  print "Contains a C comment\n";
    /$RE{comment}{C++}/     and  print "Contains a C++ comment\n";
    /$RE{comment}{PHP}/     and  print "Contains a PHP comment\n";
    /$RE{comment}{Java}/    and  print "Contains a Java comment\n";
    /$RE{comment}{Perl}/    and  print "Contains a Perl comment\n";
    /$RE{comment}{awk}/     and  print "Contains an awk comment\n";
    /$RE{comment}{HTML}/    and  print "Contains an HTML comment\n";
}

use Regexp::Common qw /comment RE_comment_HTML/;

while (<>) {
    $_ =~ RE_comment_HTML() and  print "Contains an HTML comment\n";
}

DESCRIPTION

Please consult the manual of Regexp::Common for a general description of the works of this interface.

Do not use this module directly, but load it via Regexp::Common.

This modules gives you regular expressions for comments in various languages.

Available languages are:

$RE{comment}{Ada}
$RE{comment}{ALPACA}
$RE{comment}{awk}
$RE{comment}{'beta-Juliet'}
$RE{comment}{Beatnik}        # Require at least Perl 5.8.0
$RE{comment}{'Befunge-98'}
$RE{comment}{Brainfuck}
$RE{comment}{C}
$RE{comment}{'C++'}
$RE{comment}{Dylan}          # Require at least Perl 5.6.0.
$RE{comment}{Eiffel}
$RE{comment}{'Funge-98'}
$RE{comment}{Haifu}
$RE{comment}{Haskell}        # Require at least Perl 5.6.0.
$RE{comment}{HTML}
$RE{comment}{Hugo}           # Require at least Perl 5.6.0.
$RE{comment}{ILLGOL}
$RE{comment}{Java}
$RE{comment}{LaTeX}
$RE{comment}{LOGO}
$RE{comment}{LPC}
$RE{comment}{Perl}
$RE{comment}{PHP}
$RE{comment}{Portia}
$RE{comment}{Python}
$RE{comment}{REBOL}
$RE{comment}{Ruby}
$RE{comment}{shell}
$RE{comment}{Shelta}
$RE{comment}{Smalltalk}
$RE{comment}{SMITH}
$RE{comment}{SQL}
$RE{comment}{SQL}{MySQL}
$RE{comment}{Tcl}
$RE{comment}{TeX}
$RE{comment}{troff}
$RE{comment}{vi}
$RE{comment}{'*W'}
$RE{comment}{zonefile}

$RE{comment}{vi} is a regular expression matching comments used in vi's startup file .exrc, while $RE{comment}{zonefile} is a regular expression matching comments in zonefiles for bind.

For HTML, the regular expression captures what's known in SGML as a comment declaration. It starts with a <!, ends with a > and contains zero or more comments. Each comment starts and end with --. See also [Go 90].

Note that Beatnik uses capturing parenthesis, even if {-keep} is not used.

If we are using C{-keep} (See Regexp::Common):

For Ada, ALPACA, awk, beta-Juliet, Befunge-98, C, Eiffel, Funge-98, Haifu, ILLGOL, LaTeX, LOGO, LPC, Perl, Portia, Python, REBOL, Ruby, shell, Shelta, Smalltalk, SMITH, SQL, TeX, Tcl, troff, vi, *W, and zonefile:
$1

captures the entire match

$2

captures the opening comment marker

$3

captures the contents of the comment

$4

captures the closing comment marker

For Beatnik, Brainfuck, C++, Dylan, Haskell, Hugo, Java, PHP, and SQL_MySQL:
$1

captures the entire match

For HTML
$1

captures the entire match

$2

captures the MDO (<!).

$3

captures the content between the MDO and the MDC.

$4

captures the (last) comment, without the COMs (--).

$5

captures the MDC (>).

REFERENCES

[Go 90]

Charles F. Goldfarb: The SGML Handbook. Oxford: Oxford University Press. 1990. ISBN 0-19-853737-9. Ch. 10.3, pp 390-391.

HISTORY

$Log: comment.pm,v $
Revision 1.16  2002/08/27 16:50:50  abigail
Patterns for Beatnik, Befunge-98, Funge-98 and W*.

Revision 1.15  2002/08/22 17:04:03  abigail
SMITH added

Revision 1.14  2002/08/22 16:41:25  abigail
+ Added function 'id' and 'from_to' with associated data.
+ Added function 'combine' for languages having multiple syntaxes.
+ Added 'Shelta'

Revision 1.13  2002/08/21 16:00:32  abigail
beta-Juliet, Portia, ILLGOL and Brainfuck.

Revision 1.12  2002/08/20 17:40:37  abigail
- Created a 'nested' function (simplified version from
  Regexp::Common::balanced).
- Comments that use 'from' to eol or balanced (nested) delimiters
  are now generated from a data array.
- Added Hugo and Haifu.

Revision 1.11  2002/08/05 12:16:58  abigail
Fixed 'Regex::' and 'Rexexp::' typos to 'Regexp::'
(Found my Mike Castle).

Revision 1.10  2002/07/31 23:33:16  abigail
Documented that Haskell and Dylan comments need at least 5.6.0.

Revision 1.9  2002/07/31 23:12:29  abigail
Dylan and Haskell comments can be nested, hence version 5.6.0 of Perl
is needed to be able to make a regex matching them.

Revision 1.8  2002/07/31 14:48:16  abigail
Added LOGO (to please petdance)

Revision 1.7  2002/07/31 13:06:41  abigail
Dealt with -keep for Haskell and Dylan.

Revision 1.6  2002/07/31 00:54:00  abigail
Added comments for Haskell, Dylan, Smalltalk and MySQL.

Revision 1.5  2002/07/30 16:38:23  abigail
Added support for the languages: LaTeX, Tcl, TeX and troff.

Revision 1.4  2002/07/26 16:48:12  abigail
Simplied datastructure for the languages that use single line comments.

Revision 1.3  2002/07/26 16:37:20  abigail
Added new languages: Ada, awk, Eiffel, Java, LPC, PHP, Python,
REBOL, Ruby, vi and zonefile.

Revision 1.2  2002/07/25 22:37:44  abigail
Added 'use strict'.
Added 'no_defaults' to 'use Regex::Common' to prevent loaded of all
defaults.

Revision 1.1  2002/07/25 19:56:07  abigail
Modularizing Regexp::Common.

SEE ALSO

Regexp::Common for a general description of how to use this interface.

AUTHOR

Damian Conway (damian@conway.org)

MAINTAINANCE

This package is maintained by Abigail (regexp-common@abigail.nl).

BUGS AND IRRITATIONS

Bound to be plenty.

For a start, there are many common regexes missing. Send them in to regexp-common@abigail.nl.

COPYRIGHT

Copyright (c) 2001 - 2002, Damian Conway. All Rights Reserved.
  This module is free software. It may be used, redistributed
 and/or modified under the terms of the Perl Artistic License
       (see http://www.perl.com/perl/misc/Artistic.html)