g-string.adb, [...]: Replace GNAT.xxx by System.xxx when appropriate.
2007-04-20 Robert Dewar <dewar@adacore.com>
* g-string.adb, s-proinf-irix-athread.adb, s-gloloc-mingw.adb,
s-tfsetr-default.adb, gnatfind.adb, gnatxref.adb, gprep.adb,
g-regexp.adb, g-regexp.ads, g-regpat.ads, g-tasloc.adb, g-tasloc.ads,
output.adb, switch-m.ads, tree_in.ads, tree_io.ads, indepsw.ads,
g-utf_32.adb, g-utf_32.ads, a-wichun.adb, a-wichun.ads, a-zchuni.adb,
a-zchuni.ads: Replace GNAT.xxx by System.xxx when appropriate.
* s-utf_32.adb, s-utf_32.ads, s-os_lib.adb, s-os_lib.ads, s-regexp.adb,
s-regexp.ads, s-regpat.adb, s-regpat.ads, s-string.adb, s-string.ads,
s-tasloc.adb, s-tasloc.ads: New files.
From-SVN: r125360
2007-06-06 12:14:14 +02:00
|
|
|
------------------------------------------------------------------------------
|
|
|
|
-- --
|
|
|
|
-- GNAT LIBRARY COMPONENTS --
|
|
|
|
-- --
|
|
|
|
-- S Y S T E M . R E G P A T --
|
|
|
|
-- --
|
|
|
|
-- S p e c --
|
|
|
|
-- --
|
|
|
|
-- Copyright (C) 1986 by University of Toronto. --
|
2014-08-01 12:15:59 +02:00
|
|
|
-- Copyright (C) 1996-2014, AdaCore --
|
g-string.adb, [...]: Replace GNAT.xxx by System.xxx when appropriate.
2007-04-20 Robert Dewar <dewar@adacore.com>
* g-string.adb, s-proinf-irix-athread.adb, s-gloloc-mingw.adb,
s-tfsetr-default.adb, gnatfind.adb, gnatxref.adb, gprep.adb,
g-regexp.adb, g-regexp.ads, g-regpat.ads, g-tasloc.adb, g-tasloc.ads,
output.adb, switch-m.ads, tree_in.ads, tree_io.ads, indepsw.ads,
g-utf_32.adb, g-utf_32.ads, a-wichun.adb, a-wichun.ads, a-zchuni.adb,
a-zchuni.ads: Replace GNAT.xxx by System.xxx when appropriate.
* s-utf_32.adb, s-utf_32.ads, s-os_lib.adb, s-os_lib.ads, s-regexp.adb,
s-regexp.ads, s-regpat.adb, s-regpat.ads, s-string.adb, s-string.ads,
s-tasloc.adb, s-tasloc.ads: New files.
From-SVN: r125360
2007-06-06 12:14:14 +02:00
|
|
|
-- --
|
|
|
|
-- GNAT is free software; you can redistribute it and/or modify it under --
|
|
|
|
-- terms of the GNU General Public License as published by the Free Soft- --
|
[multiple changes]
2011-08-01 Arnaud Charlet <charlet@adacore.com>
* g-socket-dummy.adb, s-osinte-linux.ads, g-socket-dummy.ads,
g-debuti.adb, g-tasloc.adb, g-debuti.ads, g-tasloc.ads,
s-osinte-hpux.ads, g-sercom.adb, g-soliop-solaris.ads, g-sercom.ads,
g-sptain.ads, g-curexc.ads, s-tasloc.adb, s-tasloc.ads, s-tataat.adb,
g-ctrl_c.adb, a-reatim.adb, s-tataat.ads, g-dirope.adb, g-ctrl_c.ads,
g-dirope.ads, g-boubuf.adb, g-calend.adb, g-boubuf.ads, g-souinf.ads,
g-table.adb, g-bytswa-x86.adb, g-wispch.adb, g-io.adb, g-table.ads,
g-wispch.ads, g-io.ads, g-memdum.adb, g-memdum.ads, g-busorg.adb,
g-busorg.ads, g-regpat.adb, g-sothco-dummy.adb, g-encstr.adb,
g-regpat.ads, g-sothco-dummy.ads, s-osinte-aix.ads, g-encstr.ads,
g-sercom-mingw.adb, s-mastop-vms.adb, g-diopit.adb, g-diopit.ads,
s-vxwext.adb, g-dyntab.adb, g-dyntab.ads, g-crc32.adb,
g-sercom-linux.adb, g-crc32.ads, s-regpat.adb, g-flocon.ads,
s-regpat.ads, g-stheme.adb, g-sestin.ads, s-taspri-posix-noaltstack.ads,
g-soliop.ads, s-inmaop-posix.adb, g-locfil.ads, g-enblsp-vms-alpha.adb,
g-socthi-dummy.adb, g-socthi-dummy.ads, gnat.ads, g-moreex.adb,
g-moreex.ads, g-dynhta.adb, g-dynhta.ads, g-deutst.ads, g-htable.adb,
g-cgicoo.adb, g-htable.ads, g-cgicoo.ads, a-interr.adb,
g-socthi-vms.adb, g-socthi-vms.ads, g-hesora.adb, g-bubsor.adb,
g-hesora.ads, g-bubsor.ads, g-md5.adb, g-md5.ads, s-intman-irix.adb,
s-htable.adb, s-osinte-vms.adb, s-htable.ads, s-osinte-vms.ads,
s-taprob.adb, g-bytswa.adb, g-bytswa.ads, s-osinte-solaris-posix.ads,
a-suenco.adb, g-comver.adb, g-comver.ads, g-exctra.adb,
s-osinte-solaris.adb, g-exctra.ads, s-osinte-irix.ads,
s-osinte-solaris.ads, a-caldel-vms.adb, g-socthi-vxworks.adb,
g-expect.adb, g-socthi-vxworks.ads, g-expect.ads, g-comlin.ads,
g-heasor.adb, g-heasor.ads, g-traceb.adb, g-traceb.ads, g-decstr.adb,
g-spipat.adb, g-decstr.ads, g-spipat.ads, s-mastop-tru64.adb,
g-except.ads, g-thread.adb, g-hesorg.adb, g-thread.ads, g-hesorg.ads,
g-expect-vms.adb, a-stuten.ads, g-spchge.adb, g-spchge.ads,
g-u3spch.adb, g-u3spch.ads, g-spitbo.adb, g-spitbo.ads,
s-osinte-dummy.ads, s-osinte-posix.adb, g-pehage.adb, g-pehage.ads,
s-gloloc-mingw.adb, g-sha1.ads, s-traceb-hpux.adb,
g-trasym-unimplemented.adb, g-trasym-unimplemented.ads, g-io_aux.adb,
g-regexp.adb, g-io_aux.ads, g-socthi-mingw.adb, g-regexp.ads,
s-osinte-hpux-dce.adb, g-socthi-mingw.ads, g-cgi.adb,
s-osinte-hpux-dce.ads, g-cgi.ads, g-byorma.adb, g-boumai.ads,
g-byorma.ads, a-caldel.adb, s-regexp.adb, s-regexp.ads,
g-soliop-mingw.ads, g-sptavs.ads, s-osinte-tru64.ads, g-speche.adb,
g-speche.ads, g-socthi.adb, g-stsifd-sockets.adb, g-socthi.ads,
s-osinte-darwin.ads, i-vxwork-x86.ads, g-awk.adb, i-vxwork.ads,
g-awk.ads, g-zspche.adb, g-zspche.ads, g-socket.adb, g-sptabo.ads,
g-socket.ads, g-semaph.adb, g-semaph.ads, s-taspri-posix.ads,
g-enblsp-vms-ia64.adb, g-cgideb.adb, g-cgideb.ads, g-sothco.adb,
s-osinte-freebsd.ads, g-sothco.ads, g-catiio.adb, g-casuti.adb,
g-catiio.ads, g-casuti.ads, g-trasym.adb, g-trasym.ads, s-casuti.adb,
g-os_lib.adb, s-traceb-mastop.adb, g-busora.adb, s-interr-dummy.adb,
g-busora.ads, g-enutst.ads, s-os_lib.adb, a-tasatt.adb,
s-osinte-mingw.ads: Update to GPLv3 run-time license.
Use GNAT instead of GNARL.
2011-08-01 Bob Duff <duff@adacore.com>
* a-cdlili.ads, a-cihama.ads, a-coinve.ads, a-ciorse.ads, a-coorma.ads,
a-cidlli.ads, a-ciormu.ads, a-cihase.ads, a-cohama.ads, a-coorse.ads,
a-ciorma.ads, a-coormu.ads, a-convec.ads, a-cohase.ads: Minor
reformatting.
2011-08-01 Yannick Moy <moy@adacore.com>
* debug.adb (d.D) reverve flag for the SPARK mode
(d.E) reverve flag for SPARK generation mode
(d.F) reverve flag for Why generation mode
* opt.ads, opt.adb (ALFA_Mode, ALFA_Through_SPARK_Mode,
ALFA_Through_Why_Mode, Formal_Verification_Mode, SPARK_Mode): New
functions which return True when the corresponding modes are set
(Formal_Language): return "spark" or "alfa" when in formal verification
mode.
* sem_util.ads, sem_util.adb (Formal_Error_Msg): new wrapper on
Error_Msg to prefix the error message with a tag giving the formal
language
(Formal_Error_Msg_N): new wrapper on Error_Msg_N to prefix the error
message with a tag giving the formal language
* sem_ch5.adb (Analyze_Block_Statement): issue error in formal mode on
block statement
(Analyze_Case_Statement): issue error in formal mode on case statement
with a single "others" case alternative
(Analyze_Exit_Statement): issue errors in formal mode on exit
statements which do not respect SPARK restrictions
(Analyze_Goto_Statement): issue error in formal mode on goto statement
(Check_Unreachable_Code): always issue an error (not a warning) in
formal mode on unreachable code (concerns both code after an infinite
loop and after an unconditional jump, both not allowed in SPARK)
* sem_ch6.adb (Analyze_Return_Statement): add call to
Set_Return_Present for a procedure containing a return statement
(already done for functions in Analyze_Function_Return)
(Analyze_Function_Return): issue error in formal mode on extended
return or if return is not last statement in function
(Check_Missing_Return): issue error in formal mode if function does
not end with return or if procedure contains a return
* sem_ch8.ads, sem_ch8.adb (Has_Loop_In_Inner_Open_Scopes): new
function to detect if there is an inner scope of its parameter S which
is a loop.
2011-08-01 Thomas Quinot <quinot@adacore.com>
* sem_ch6.ads: Minor reformatting.
From-SVN: r177040
2011-08-01 17:05:02 +02:00
|
|
|
-- ware Foundation; either version 3, or (at your option) any later ver- --
|
g-string.adb, [...]: Replace GNAT.xxx by System.xxx when appropriate.
2007-04-20 Robert Dewar <dewar@adacore.com>
* g-string.adb, s-proinf-irix-athread.adb, s-gloloc-mingw.adb,
s-tfsetr-default.adb, gnatfind.adb, gnatxref.adb, gprep.adb,
g-regexp.adb, g-regexp.ads, g-regpat.ads, g-tasloc.adb, g-tasloc.ads,
output.adb, switch-m.ads, tree_in.ads, tree_io.ads, indepsw.ads,
g-utf_32.adb, g-utf_32.ads, a-wichun.adb, a-wichun.ads, a-zchuni.adb,
a-zchuni.ads: Replace GNAT.xxx by System.xxx when appropriate.
* s-utf_32.adb, s-utf_32.ads, s-os_lib.adb, s-os_lib.ads, s-regexp.adb,
s-regexp.ads, s-regpat.adb, s-regpat.ads, s-string.adb, s-string.ads,
s-tasloc.adb, s-tasloc.ads: New files.
From-SVN: r125360
2007-06-06 12:14:14 +02:00
|
|
|
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
|
|
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
[multiple changes]
2011-08-01 Arnaud Charlet <charlet@adacore.com>
* g-socket-dummy.adb, s-osinte-linux.ads, g-socket-dummy.ads,
g-debuti.adb, g-tasloc.adb, g-debuti.ads, g-tasloc.ads,
s-osinte-hpux.ads, g-sercom.adb, g-soliop-solaris.ads, g-sercom.ads,
g-sptain.ads, g-curexc.ads, s-tasloc.adb, s-tasloc.ads, s-tataat.adb,
g-ctrl_c.adb, a-reatim.adb, s-tataat.ads, g-dirope.adb, g-ctrl_c.ads,
g-dirope.ads, g-boubuf.adb, g-calend.adb, g-boubuf.ads, g-souinf.ads,
g-table.adb, g-bytswa-x86.adb, g-wispch.adb, g-io.adb, g-table.ads,
g-wispch.ads, g-io.ads, g-memdum.adb, g-memdum.ads, g-busorg.adb,
g-busorg.ads, g-regpat.adb, g-sothco-dummy.adb, g-encstr.adb,
g-regpat.ads, g-sothco-dummy.ads, s-osinte-aix.ads, g-encstr.ads,
g-sercom-mingw.adb, s-mastop-vms.adb, g-diopit.adb, g-diopit.ads,
s-vxwext.adb, g-dyntab.adb, g-dyntab.ads, g-crc32.adb,
g-sercom-linux.adb, g-crc32.ads, s-regpat.adb, g-flocon.ads,
s-regpat.ads, g-stheme.adb, g-sestin.ads, s-taspri-posix-noaltstack.ads,
g-soliop.ads, s-inmaop-posix.adb, g-locfil.ads, g-enblsp-vms-alpha.adb,
g-socthi-dummy.adb, g-socthi-dummy.ads, gnat.ads, g-moreex.adb,
g-moreex.ads, g-dynhta.adb, g-dynhta.ads, g-deutst.ads, g-htable.adb,
g-cgicoo.adb, g-htable.ads, g-cgicoo.ads, a-interr.adb,
g-socthi-vms.adb, g-socthi-vms.ads, g-hesora.adb, g-bubsor.adb,
g-hesora.ads, g-bubsor.ads, g-md5.adb, g-md5.ads, s-intman-irix.adb,
s-htable.adb, s-osinte-vms.adb, s-htable.ads, s-osinte-vms.ads,
s-taprob.adb, g-bytswa.adb, g-bytswa.ads, s-osinte-solaris-posix.ads,
a-suenco.adb, g-comver.adb, g-comver.ads, g-exctra.adb,
s-osinte-solaris.adb, g-exctra.ads, s-osinte-irix.ads,
s-osinte-solaris.ads, a-caldel-vms.adb, g-socthi-vxworks.adb,
g-expect.adb, g-socthi-vxworks.ads, g-expect.ads, g-comlin.ads,
g-heasor.adb, g-heasor.ads, g-traceb.adb, g-traceb.ads, g-decstr.adb,
g-spipat.adb, g-decstr.ads, g-spipat.ads, s-mastop-tru64.adb,
g-except.ads, g-thread.adb, g-hesorg.adb, g-thread.ads, g-hesorg.ads,
g-expect-vms.adb, a-stuten.ads, g-spchge.adb, g-spchge.ads,
g-u3spch.adb, g-u3spch.ads, g-spitbo.adb, g-spitbo.ads,
s-osinte-dummy.ads, s-osinte-posix.adb, g-pehage.adb, g-pehage.ads,
s-gloloc-mingw.adb, g-sha1.ads, s-traceb-hpux.adb,
g-trasym-unimplemented.adb, g-trasym-unimplemented.ads, g-io_aux.adb,
g-regexp.adb, g-io_aux.ads, g-socthi-mingw.adb, g-regexp.ads,
s-osinte-hpux-dce.adb, g-socthi-mingw.ads, g-cgi.adb,
s-osinte-hpux-dce.ads, g-cgi.ads, g-byorma.adb, g-boumai.ads,
g-byorma.ads, a-caldel.adb, s-regexp.adb, s-regexp.ads,
g-soliop-mingw.ads, g-sptavs.ads, s-osinte-tru64.ads, g-speche.adb,
g-speche.ads, g-socthi.adb, g-stsifd-sockets.adb, g-socthi.ads,
s-osinte-darwin.ads, i-vxwork-x86.ads, g-awk.adb, i-vxwork.ads,
g-awk.ads, g-zspche.adb, g-zspche.ads, g-socket.adb, g-sptabo.ads,
g-socket.ads, g-semaph.adb, g-semaph.ads, s-taspri-posix.ads,
g-enblsp-vms-ia64.adb, g-cgideb.adb, g-cgideb.ads, g-sothco.adb,
s-osinte-freebsd.ads, g-sothco.ads, g-catiio.adb, g-casuti.adb,
g-catiio.ads, g-casuti.ads, g-trasym.adb, g-trasym.ads, s-casuti.adb,
g-os_lib.adb, s-traceb-mastop.adb, g-busora.adb, s-interr-dummy.adb,
g-busora.ads, g-enutst.ads, s-os_lib.adb, a-tasatt.adb,
s-osinte-mingw.ads: Update to GPLv3 run-time license.
Use GNAT instead of GNARL.
2011-08-01 Bob Duff <duff@adacore.com>
* a-cdlili.ads, a-cihama.ads, a-coinve.ads, a-ciorse.ads, a-coorma.ads,
a-cidlli.ads, a-ciormu.ads, a-cihase.ads, a-cohama.ads, a-coorse.ads,
a-ciorma.ads, a-coormu.ads, a-convec.ads, a-cohase.ads: Minor
reformatting.
2011-08-01 Yannick Moy <moy@adacore.com>
* debug.adb (d.D) reverve flag for the SPARK mode
(d.E) reverve flag for SPARK generation mode
(d.F) reverve flag for Why generation mode
* opt.ads, opt.adb (ALFA_Mode, ALFA_Through_SPARK_Mode,
ALFA_Through_Why_Mode, Formal_Verification_Mode, SPARK_Mode): New
functions which return True when the corresponding modes are set
(Formal_Language): return "spark" or "alfa" when in formal verification
mode.
* sem_util.ads, sem_util.adb (Formal_Error_Msg): new wrapper on
Error_Msg to prefix the error message with a tag giving the formal
language
(Formal_Error_Msg_N): new wrapper on Error_Msg_N to prefix the error
message with a tag giving the formal language
* sem_ch5.adb (Analyze_Block_Statement): issue error in formal mode on
block statement
(Analyze_Case_Statement): issue error in formal mode on case statement
with a single "others" case alternative
(Analyze_Exit_Statement): issue errors in formal mode on exit
statements which do not respect SPARK restrictions
(Analyze_Goto_Statement): issue error in formal mode on goto statement
(Check_Unreachable_Code): always issue an error (not a warning) in
formal mode on unreachable code (concerns both code after an infinite
loop and after an unconditional jump, both not allowed in SPARK)
* sem_ch6.adb (Analyze_Return_Statement): add call to
Set_Return_Present for a procedure containing a return statement
(already done for functions in Analyze_Function_Return)
(Analyze_Function_Return): issue error in formal mode on extended
return or if return is not last statement in function
(Check_Missing_Return): issue error in formal mode if function does
not end with return or if procedure contains a return
* sem_ch8.ads, sem_ch8.adb (Has_Loop_In_Inner_Open_Scopes): new
function to detect if there is an inner scope of its parameter S which
is a loop.
2011-08-01 Thomas Quinot <quinot@adacore.com>
* sem_ch6.ads: Minor reformatting.
From-SVN: r177040
2011-08-01 17:05:02 +02:00
|
|
|
-- or FITNESS FOR A PARTICULAR PURPOSE. --
|
|
|
|
-- --
|
|
|
|
-- As a special exception under Section 7 of GPL version 3, you are granted --
|
|
|
|
-- additional permissions described in the GCC Runtime Library Exception, --
|
|
|
|
-- version 3.1, as published by the Free Software Foundation. --
|
|
|
|
-- --
|
|
|
|
-- You should have received a copy of the GNU General Public License and --
|
|
|
|
-- a copy of the GCC Runtime Library Exception along with this program; --
|
|
|
|
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
|
|
|
|
-- <http://www.gnu.org/licenses/>. --
|
g-string.adb, [...]: Replace GNAT.xxx by System.xxx when appropriate.
2007-04-20 Robert Dewar <dewar@adacore.com>
* g-string.adb, s-proinf-irix-athread.adb, s-gloloc-mingw.adb,
s-tfsetr-default.adb, gnatfind.adb, gnatxref.adb, gprep.adb,
g-regexp.adb, g-regexp.ads, g-regpat.ads, g-tasloc.adb, g-tasloc.ads,
output.adb, switch-m.ads, tree_in.ads, tree_io.ads, indepsw.ads,
g-utf_32.adb, g-utf_32.ads, a-wichun.adb, a-wichun.ads, a-zchuni.adb,
a-zchuni.ads: Replace GNAT.xxx by System.xxx when appropriate.
* s-utf_32.adb, s-utf_32.ads, s-os_lib.adb, s-os_lib.ads, s-regexp.adb,
s-regexp.ads, s-regpat.adb, s-regpat.ads, s-string.adb, s-string.ads,
s-tasloc.adb, s-tasloc.ads: New files.
From-SVN: r125360
2007-06-06 12:14:14 +02:00
|
|
|
-- --
|
|
|
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
|
|
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
|
|
|
-- --
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- This package implements roughly the same set of regular expressions as
|
|
|
|
-- are available in the Perl or Python programming languages.
|
|
|
|
|
|
|
|
-- This is an extension of the original V7 style regular expression library
|
|
|
|
-- written in C by Henry Spencer. Apart from the translation to Ada, the
|
|
|
|
-- interface has been considerably changed to use the Ada String type
|
|
|
|
-- instead of C-style nul-terminated strings.
|
|
|
|
|
|
|
|
-- Note: this package is in the System hierarchy so that it can be directly
|
|
|
|
-- be used by other predefined packages. User access to this package is via
|
|
|
|
-- a renaming of this package in GNAT.Regpat (file g-regpat.ads).
|
|
|
|
|
|
|
|
package System.Regpat is
|
|
|
|
pragma Preelaborate;
|
|
|
|
|
|
|
|
-- The grammar is the following:
|
|
|
|
|
|
|
|
-- regexp ::= expr
|
|
|
|
-- ::= ^ expr -- anchor at the beginning of string
|
|
|
|
-- ::= expr $ -- anchor at the end of string
|
|
|
|
|
|
|
|
-- expr ::= term
|
|
|
|
-- ::= term | term -- alternation (term or term ...)
|
|
|
|
|
|
|
|
-- term ::= item
|
|
|
|
-- ::= item item ... -- concatenation (item then item)
|
|
|
|
|
|
|
|
-- item ::= elmt -- match elmt
|
|
|
|
-- ::= elmt * -- zero or more elmt's
|
|
|
|
-- ::= elmt + -- one or more elmt's
|
|
|
|
-- ::= elmt ? -- matches elmt or nothing
|
|
|
|
-- ::= elmt *? -- zero or more times, minimum number
|
|
|
|
-- ::= elmt +? -- one or more times, minimum number
|
|
|
|
-- ::= elmt ?? -- zero or one time, minimum number
|
|
|
|
-- ::= elmt { num } -- matches elmt exactly num times
|
|
|
|
-- ::= elmt { num , } -- matches elmt at least num times
|
|
|
|
-- ::= elmt { num , num2 } -- matches between num and num2 times
|
|
|
|
-- ::= elmt { num }? -- matches elmt exactly num times
|
|
|
|
-- ::= elmt { num , }? -- matches elmt at least num times
|
|
|
|
-- non-greedy version
|
|
|
|
-- ::= elmt { num , num2 }? -- matches between num and num2 times
|
|
|
|
-- non-greedy version
|
|
|
|
|
|
|
|
-- elmt ::= nchr -- matches given character
|
|
|
|
-- ::= [range range ...] -- matches any character listed
|
|
|
|
-- ::= [^ range range ...] -- matches any character not listed
|
|
|
|
-- ::= . -- matches any single character
|
|
|
|
-- -- except newlines
|
2014-08-01 12:15:59 +02:00
|
|
|
-- ::= ( expr ) -- parenthesis used for grouping
|
|
|
|
-- ::= (?: expr ) -- non-capturing parenthesis
|
|
|
|
-- ::= \ num -- reference to num-th capturing
|
|
|
|
-- parenthesis
|
g-string.adb, [...]: Replace GNAT.xxx by System.xxx when appropriate.
2007-04-20 Robert Dewar <dewar@adacore.com>
* g-string.adb, s-proinf-irix-athread.adb, s-gloloc-mingw.adb,
s-tfsetr-default.adb, gnatfind.adb, gnatxref.adb, gprep.adb,
g-regexp.adb, g-regexp.ads, g-regpat.ads, g-tasloc.adb, g-tasloc.ads,
output.adb, switch-m.ads, tree_in.ads, tree_io.ads, indepsw.ads,
g-utf_32.adb, g-utf_32.ads, a-wichun.adb, a-wichun.ads, a-zchuni.adb,
a-zchuni.ads: Replace GNAT.xxx by System.xxx when appropriate.
* s-utf_32.adb, s-utf_32.ads, s-os_lib.adb, s-os_lib.ads, s-regexp.adb,
s-regexp.ads, s-regpat.adb, s-regpat.ads, s-string.adb, s-string.ads,
s-tasloc.adb, s-tasloc.ads: New files.
From-SVN: r125360
2007-06-06 12:14:14 +02:00
|
|
|
|
|
|
|
-- range ::= char - char -- matches chars in given range
|
|
|
|
-- ::= nchr
|
|
|
|
-- ::= [: posix :] -- any character in the POSIX range
|
|
|
|
-- ::= [:^ posix :] -- not in the POSIX range
|
|
|
|
|
|
|
|
-- posix ::= alnum -- alphanumeric characters
|
|
|
|
-- ::= alpha -- alphabetic characters
|
|
|
|
-- ::= ascii -- ascii characters (0 .. 127)
|
|
|
|
-- ::= cntrl -- control chars (0..31, 127..159)
|
|
|
|
-- ::= digit -- digits ('0' .. '9')
|
|
|
|
-- ::= graph -- graphic chars (32..126, 160..255)
|
|
|
|
-- ::= lower -- lower case characters
|
|
|
|
-- ::= print -- printable characters (32..127)
|
|
|
|
-- -- and whitespaces (9 .. 13)
|
|
|
|
-- ::= punct -- printable, except alphanumeric
|
|
|
|
-- ::= space -- space characters
|
|
|
|
-- ::= upper -- upper case characters
|
|
|
|
-- ::= word -- alphanumeric characters
|
|
|
|
-- ::= xdigit -- hexadecimal chars (0..9, a..f)
|
|
|
|
|
|
|
|
-- char ::= any character, including special characters
|
|
|
|
-- ASCII.NUL is not supported.
|
|
|
|
|
|
|
|
-- nchr ::= any character except \()[].*+?^ or \char to match char
|
|
|
|
-- \n means a newline (ASCII.LF)
|
|
|
|
-- \t means a tab (ASCII.HT)
|
|
|
|
-- \r means a return (ASCII.CR)
|
|
|
|
-- \b matches the empty string at the beginning or end of a
|
|
|
|
-- word. A word is defined as a set of alphanumerical
|
|
|
|
-- characters (see \w below).
|
|
|
|
-- \B matches the empty string only when *not* at the
|
|
|
|
-- beginning or end of a word.
|
|
|
|
-- \d matches any digit character ([0-9])
|
|
|
|
-- \D matches any non digit character ([^0-9])
|
|
|
|
-- \s matches any white space character. This is equivalent
|
|
|
|
-- to [ \t\n\r\f\v] (tab, form-feed, vertical-tab,...
|
|
|
|
-- \S matches any non-white space character.
|
|
|
|
-- \w matches any alphanumeric character or underscore.
|
|
|
|
-- This include accented letters, as defined in the
|
|
|
|
-- package Ada.Characters.Handling.
|
|
|
|
-- \W matches any non-alphanumeric character.
|
|
|
|
-- \A match the empty string only at the beginning of the
|
|
|
|
-- string, whatever flags are used for Compile (the
|
|
|
|
-- behavior of ^ can change, see Regexp_Flags below).
|
|
|
|
-- \G match the empty string only at the end of the
|
|
|
|
-- string, whatever flags are used for Compile (the
|
|
|
|
-- behavior of $ can change, see Regexp_Flags below).
|
|
|
|
-- ... ::= is used to indication repetition (one or more terms)
|
|
|
|
|
|
|
|
-- Embedded newlines are not matched by the ^ operator.
|
|
|
|
-- It is possible to retrieve the substring matched a parenthesis
|
|
|
|
-- expression. Although the depth of parenthesis is not limited in the
|
|
|
|
-- regexp, only the first 9 substrings can be retrieved.
|
|
|
|
|
|
|
|
-- The highest value possible for the arguments to the curly operator ({})
|
|
|
|
-- are given by the constant Max_Curly_Repeat below.
|
|
|
|
|
|
|
|
-- The operators '*', '+', '?' and '{}' always match the longest possible
|
|
|
|
-- substring. They all have a non-greedy version (with an extra ? after the
|
|
|
|
-- operator), which matches the shortest possible substring.
|
|
|
|
|
|
|
|
-- For instance:
|
|
|
|
-- regexp="<.*>" string="<h1>title</h1>" matches="<h1>title</h1>"
|
|
|
|
-- regexp="<.*?>" string="<h1>title</h1>" matches="<h1>"
|
|
|
|
--
|
|
|
|
-- '{' and '}' are only considered as special characters if they appear
|
|
|
|
-- in a substring that looks exactly like '{n}', '{n,m}' or '{n,}', where
|
|
|
|
-- n and m are digits. No space is allowed. In other contexts, the curly
|
|
|
|
-- braces will simply be treated as normal characters.
|
|
|
|
|
|
|
|
-- Compiling Regular Expressions
|
|
|
|
-- =============================
|
|
|
|
|
|
|
|
-- To use this package, you first need to compile the regular expression
|
|
|
|
-- (a string) into a byte-code program, in a Pattern_Matcher structure.
|
|
|
|
-- This first step checks that the regexp is valid, and optimizes the
|
|
|
|
-- matching algorithms of the second step.
|
|
|
|
|
|
|
|
-- Two versions of the Compile subprogram are given: one in which this
|
|
|
|
-- package will compute itself the best possible size to allocate for the
|
|
|
|
-- byte code; the other where you must allocate enough memory yourself. An
|
|
|
|
-- exception is raised if there is not enough memory.
|
|
|
|
|
|
|
|
-- declare
|
|
|
|
-- Regexp : String := "a|b";
|
|
|
|
|
|
|
|
-- Matcher : Pattern_Matcher := Compile (Regexp);
|
|
|
|
-- -- The size for matcher is automatically allocated
|
|
|
|
|
|
|
|
-- Matcher2 : Pattern_Matcher (1000);
|
|
|
|
-- -- Some space is allocated directly.
|
|
|
|
|
|
|
|
-- begin
|
|
|
|
-- Compile (Matcher2, Regexp);
|
|
|
|
-- ...
|
|
|
|
-- end;
|
|
|
|
|
|
|
|
-- Note that the second version is significantly faster, since with the
|
|
|
|
-- first version the regular expression has in fact to be compiled twice
|
|
|
|
-- (first to compute the size, then to generate the byte code).
|
|
|
|
|
|
|
|
-- Note also that you cannot use the function version of Compile if you
|
|
|
|
-- specify the size of the Pattern_Matcher, since the discriminants will
|
|
|
|
-- most probably be different and you will get a Constraint_Error
|
|
|
|
|
|
|
|
-- Matching Strings
|
|
|
|
-- ================
|
|
|
|
|
|
|
|
-- Once the regular expression has been compiled, you can use it as often
|
|
|
|
-- as needed to match strings.
|
|
|
|
|
|
|
|
-- Several versions of the Match subprogram are provided, with different
|
|
|
|
-- parameters and return results.
|
|
|
|
|
|
|
|
-- See the description under each of these subprograms
|
|
|
|
|
|
|
|
-- Here is a short example showing how to get the substring matched by
|
|
|
|
-- the first parenthesis pair.
|
|
|
|
|
|
|
|
-- declare
|
|
|
|
-- Matches : Match_Array (0 .. 1);
|
|
|
|
-- Regexp : String := "a(b|c)d";
|
|
|
|
-- Str : String := "gacdg";
|
|
|
|
|
|
|
|
-- begin
|
|
|
|
-- Match (Compile (Regexp), Str, Matches);
|
|
|
|
-- return Str (Matches (1).First .. Matches (1).Last);
|
|
|
|
-- -- returns 'c'
|
|
|
|
-- end;
|
|
|
|
|
|
|
|
-- Finding all occurrences
|
|
|
|
-- =======================
|
|
|
|
|
|
|
|
-- Finding all the occurrences of a regular expression in a string cannot
|
|
|
|
-- be done by simply passing a slice of the string. This wouldn't work for
|
|
|
|
-- anchored regular expressions (the ones starting with "^" or ending with
|
|
|
|
-- "$").
|
|
|
|
-- Instead, you need to use the last parameter to Match (Data_First), as in
|
|
|
|
-- the following loop:
|
|
|
|
|
|
|
|
-- declare
|
|
|
|
-- Str : String :=
|
|
|
|
-- "-- first line" & ASCII.LF & "-- second line";
|
|
|
|
-- Matches : Match_Array (0 .. 0);
|
|
|
|
-- Regexp : Pattern_Matcher := Compile ("^--", Multiple_Lines);
|
|
|
|
-- Current : Natural := Str'First;
|
|
|
|
-- begin
|
|
|
|
-- loop
|
|
|
|
-- Match (Regexp, Str, Matches, Current);
|
|
|
|
-- exit when Matches (0) = No_Match;
|
|
|
|
--
|
|
|
|
-- -- Process the match at position Matches (0).First
|
|
|
|
--
|
|
|
|
-- Current := Matches (0).Last + 1;
|
|
|
|
-- end loop;
|
|
|
|
-- end;
|
|
|
|
|
|
|
|
-- String Substitution
|
|
|
|
-- ===================
|
|
|
|
|
|
|
|
-- No subprogram is currently provided for string substitution.
|
|
|
|
-- However, this is easy to simulate with the parenthesis groups, as
|
|
|
|
-- shown below.
|
|
|
|
|
|
|
|
-- This example swaps the first two words of the string:
|
|
|
|
|
|
|
|
-- declare
|
|
|
|
-- Regexp : String := "([a-z]+) +([a-z]+)";
|
|
|
|
-- Str : String := " first second third ";
|
|
|
|
-- Matches : Match_Array (0 .. 2);
|
|
|
|
|
|
|
|
-- begin
|
|
|
|
-- Match (Compile (Regexp), Str, Matches);
|
|
|
|
-- return Str (Str'First .. Matches (1).First - 1)
|
|
|
|
-- & Str (Matches (2).First .. Matches (2).Last)
|
|
|
|
-- & " "
|
|
|
|
-- & Str (Matches (1).First .. Matches (1).Last)
|
|
|
|
-- & Str (Matches (2).Last + 1 .. Str'Last);
|
|
|
|
-- -- returns " second first third "
|
|
|
|
-- end;
|
|
|
|
|
|
|
|
---------------
|
|
|
|
-- Constants --
|
|
|
|
---------------
|
|
|
|
|
|
|
|
Expression_Error : exception;
|
|
|
|
-- This exception is raised when trying to compile an invalid regular
|
|
|
|
-- expression. All subprograms taking an expression as parameter may raise
|
|
|
|
-- Expression_Error.
|
|
|
|
|
|
|
|
Max_Paren_Count : constant := 255;
|
|
|
|
-- Maximum number of parenthesis in a regular expression. This is limited
|
|
|
|
-- by the size of a Character, as found in the byte-compiled version of
|
|
|
|
-- regular expressions.
|
|
|
|
|
|
|
|
Max_Curly_Repeat : constant := 32767;
|
|
|
|
-- Maximum number of repetition for the curly operator. The digits in the
|
|
|
|
-- {n}, {n,} and {n,m } operators cannot be higher than this constant,
|
|
|
|
-- since they have to fit on two characters in the byte-compiled version of
|
|
|
|
-- regular expressions.
|
|
|
|
|
|
|
|
Max_Program_Size : constant := 2**15 - 1;
|
|
|
|
-- Maximum size that can be allocated for a program
|
|
|
|
|
|
|
|
type Program_Size is range 0 .. Max_Program_Size;
|
|
|
|
for Program_Size'Size use 16;
|
|
|
|
-- Number of bytes allocated for the byte-compiled version of a regular
|
|
|
|
-- expression. The size required depends on the complexity of the regular
|
|
|
|
-- expression in a complex manner that is undocumented (other than in the
|
|
|
|
-- body of the Compile procedure). Normally the size is automatically set
|
|
|
|
-- and the programmer need not be concerned about it. There are two
|
|
|
|
-- exceptions to this. First in the calls to Match, it is possible to
|
|
|
|
-- specify a non-zero size that is known to be large enough. This can
|
|
|
|
-- slightly increase the efficiency by avoiding a copy. Second, in the case
|
|
|
|
-- of calling compile, it is possible using the procedural form of Compile
|
|
|
|
-- to use a single Pattern_Matcher variable for several different
|
|
|
|
-- expressions by setting its size sufficiently large.
|
|
|
|
|
|
|
|
Auto_Size : constant := 0;
|
|
|
|
-- Used in calls to Match to indicate that the Size should be set to
|
|
|
|
-- a value appropriate to the expression being used automatically.
|
|
|
|
|
|
|
|
type Regexp_Flags is mod 256;
|
|
|
|
for Regexp_Flags'Size use 8;
|
|
|
|
-- Flags that can be given at compile time to specify default
|
|
|
|
-- properties for the regular expression.
|
|
|
|
|
|
|
|
No_Flags : constant Regexp_Flags;
|
|
|
|
Case_Insensitive : constant Regexp_Flags;
|
|
|
|
-- The automaton is optimized so that the matching is done in a case
|
|
|
|
-- insensitive manner (upper case characters and lower case characters
|
|
|
|
-- are all treated the same way).
|
|
|
|
|
|
|
|
Single_Line : constant Regexp_Flags;
|
|
|
|
-- Treat the Data we are matching as a single line. This means that
|
|
|
|
-- ^ and $ will ignore \n (unless Multiple_Lines is also specified),
|
|
|
|
-- and that '.' will match \n.
|
|
|
|
|
|
|
|
Multiple_Lines : constant Regexp_Flags;
|
|
|
|
-- Treat the Data as multiple lines. This means that ^ and $ will also
|
|
|
|
-- match on internal newlines (ASCII.LF), in addition to the beginning
|
|
|
|
-- and end of the string.
|
|
|
|
--
|
|
|
|
-- This can be combined with Single_Line.
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
-- Match_Array --
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
subtype Match_Count is Natural range 0 .. Max_Paren_Count;
|
|
|
|
|
|
|
|
type Match_Location is record
|
|
|
|
First : Natural := 0;
|
|
|
|
Last : Natural := 0;
|
|
|
|
end record;
|
|
|
|
|
|
|
|
type Match_Array is array (Match_Count range <>) of Match_Location;
|
|
|
|
-- Used for regular expressions that can contain parenthesized
|
|
|
|
-- subexpressions. Certain Match subprograms below produce Matches of type
|
|
|
|
-- Match_Array. Each component of Matches is set to the subrange of the
|
|
|
|
-- matches substring, or to No_Match if no match. Matches (N) is for the
|
|
|
|
-- N'th parenthesized subexpressions; Matches (0) is for the whole
|
|
|
|
-- expression.
|
|
|
|
--
|
2014-08-01 12:15:59 +02:00
|
|
|
-- Non-capturing parenthesis (introduced with (?:...)) can not be
|
|
|
|
-- retrieved and do not count in the match array index.
|
|
|
|
--
|
g-string.adb, [...]: Replace GNAT.xxx by System.xxx when appropriate.
2007-04-20 Robert Dewar <dewar@adacore.com>
* g-string.adb, s-proinf-irix-athread.adb, s-gloloc-mingw.adb,
s-tfsetr-default.adb, gnatfind.adb, gnatxref.adb, gprep.adb,
g-regexp.adb, g-regexp.ads, g-regpat.ads, g-tasloc.adb, g-tasloc.ads,
output.adb, switch-m.ads, tree_in.ads, tree_io.ads, indepsw.ads,
g-utf_32.adb, g-utf_32.ads, a-wichun.adb, a-wichun.ads, a-zchuni.adb,
a-zchuni.ads: Replace GNAT.xxx by System.xxx when appropriate.
* s-utf_32.adb, s-utf_32.ads, s-os_lib.adb, s-os_lib.ads, s-regexp.adb,
s-regexp.ads, s-regpat.adb, s-regpat.ads, s-string.adb, s-string.ads,
s-tasloc.adb, s-tasloc.ads: New files.
From-SVN: r125360
2007-06-06 12:14:14 +02:00
|
|
|
-- For instance, if your regular expression is: "a((b*)c+)(d+)", then
|
|
|
|
-- 12 3
|
|
|
|
-- Matches (0) is for "a((b*)c+)(d+)" (the entire expression)
|
|
|
|
-- Matches (1) is for "(b*)c+"
|
2011-08-02 12:36:15 +02:00
|
|
|
-- Matches (2) is for "b*"
|
g-string.adb, [...]: Replace GNAT.xxx by System.xxx when appropriate.
2007-04-20 Robert Dewar <dewar@adacore.com>
* g-string.adb, s-proinf-irix-athread.adb, s-gloloc-mingw.adb,
s-tfsetr-default.adb, gnatfind.adb, gnatxref.adb, gprep.adb,
g-regexp.adb, g-regexp.ads, g-regpat.ads, g-tasloc.adb, g-tasloc.ads,
output.adb, switch-m.ads, tree_in.ads, tree_io.ads, indepsw.ads,
g-utf_32.adb, g-utf_32.ads, a-wichun.adb, a-wichun.ads, a-zchuni.adb,
a-zchuni.ads: Replace GNAT.xxx by System.xxx when appropriate.
* s-utf_32.adb, s-utf_32.ads, s-os_lib.adb, s-os_lib.ads, s-regexp.adb,
s-regexp.ads, s-regpat.adb, s-regpat.ads, s-string.adb, s-string.ads,
s-tasloc.adb, s-tasloc.ads: New files.
From-SVN: r125360
2007-06-06 12:14:14 +02:00
|
|
|
-- Matches (3) is for "d+"
|
|
|
|
--
|
|
|
|
-- The number of parenthesis groups that can be retrieved is limited only
|
|
|
|
-- by Max_Paren_Count.
|
|
|
|
--
|
|
|
|
-- Normally, the bounds of the Matches actual parameter will be
|
|
|
|
-- 0 .. Paren_Count (Regexp), to get all the matches. However, it is fine
|
|
|
|
-- if Matches is shorter than that on either end; missing components will
|
|
|
|
-- be ignored. Thus, in the above example, you could use 2 .. 2 if all you
|
|
|
|
-- care about it the second parenthesis pair "b*". Likewise, if
|
|
|
|
-- Matches'Last > Paren_Count (Regexp), the extra components will be set to
|
|
|
|
-- No_Match.
|
|
|
|
|
|
|
|
No_Match : constant Match_Location := (First => 0, Last => 0);
|
|
|
|
-- The No_Match constant is (0, 0) to differentiate between matching a null
|
|
|
|
-- string at position 1, which uses (1, 0) and no match at all.
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
-- Pattern_Matcher Compilation --
|
|
|
|
---------------------------------
|
|
|
|
|
|
|
|
-- The subprograms here are used to precompile regular expressions for use
|
|
|
|
-- in subsequent Match calls. Precompilation improves efficiency if the
|
|
|
|
-- same regular expression is to be used in more than one Match call.
|
|
|
|
|
|
|
|
type Pattern_Matcher (Size : Program_Size) is private;
|
|
|
|
-- Type used to represent a regular expression compiled into byte code
|
|
|
|
|
|
|
|
Never_Match : constant Pattern_Matcher;
|
|
|
|
-- A regular expression that never matches anything
|
|
|
|
|
|
|
|
function Compile
|
|
|
|
(Expression : String;
|
|
|
|
Flags : Regexp_Flags := No_Flags) return Pattern_Matcher;
|
|
|
|
-- Compile a regular expression into internal code
|
|
|
|
--
|
|
|
|
-- Raises Expression_Error if Expression is not a legal regular expression
|
|
|
|
--
|
|
|
|
-- The appropriate size is calculated automatically to correspond to the
|
|
|
|
-- provided expression. This is the normal default method of compilation.
|
|
|
|
-- Note that it is generally not possible to assign the result of two
|
|
|
|
-- different calls to this Compile function to the same Pattern_Matcher
|
|
|
|
-- variable, since the sizes will differ.
|
|
|
|
--
|
|
|
|
-- Flags is the default value to use to set properties for Expression
|
|
|
|
-- (e.g. case sensitivity,...).
|
|
|
|
|
|
|
|
procedure Compile
|
|
|
|
(Matcher : out Pattern_Matcher;
|
|
|
|
Expression : String;
|
|
|
|
Final_Code_Size : out Program_Size;
|
|
|
|
Flags : Regexp_Flags := No_Flags);
|
a-crbtgk.adb, [...]: Fix typos in comments.
gcc/ada/
* a-crbtgk.adb, a-direct.ads, a-tasatt.adb, ali.ads,
bindgen.adb, checks.adb, einfo.ads, exp_aggr.adb, exp_ch11.adb,
exp_ch3.adb, exp_ch4.adb, exp_ch6.adb, exp_ch7.adb, exp_ch9.adb,
exp_dbug.ads, exp_disp.adb, exp_dist.adb, exp_pakd.adb,
exp_util.adb, g-alveop.ads, g-comlin.adb, g-comlin.ads,
g-diopit.adb, g-socket.ads, gcc-interface/decl.c,
gcc-interface/gigi.h, gcc-interface/trans.c,
lib-load.adb, lib-xref.ads, make.adb, mlib-prj.adb, nlists.ads,
opt.ads, par-ch10.adb, par-ch5.adb, par.adb, s-os_lib.ads,
s-oscons-tmplt.c, s-parint.ads, s-regpat.ads, s-shasto.ads,
s-stausa.ads, s-taprop-vms.adb, sem.adb, sem_ch10.adb,
sem_ch11.adb, sem_ch12.adb, sem_ch13.adb, sem_ch3.adb,
sem_ch3.ads, sem_ch4.adb, sem_ch6.adb, sem_ch7.adb, sem_ch8.adb,
sem_elim.adb, sem_prag.adb, sem_util.adb, sem_util.ads,
sem_warn.adb, sinfo.ads, styleg.adb, vms_data.ads: Fix typos in
comments.
* gnathtml.pl: Fix typos.
From-SVN: r140356
2008-09-14 08:21:12 +02:00
|
|
|
-- Compile a regular expression into internal code
|
g-string.adb, [...]: Replace GNAT.xxx by System.xxx when appropriate.
2007-04-20 Robert Dewar <dewar@adacore.com>
* g-string.adb, s-proinf-irix-athread.adb, s-gloloc-mingw.adb,
s-tfsetr-default.adb, gnatfind.adb, gnatxref.adb, gprep.adb,
g-regexp.adb, g-regexp.ads, g-regpat.ads, g-tasloc.adb, g-tasloc.ads,
output.adb, switch-m.ads, tree_in.ads, tree_io.ads, indepsw.ads,
g-utf_32.adb, g-utf_32.ads, a-wichun.adb, a-wichun.ads, a-zchuni.adb,
a-zchuni.ads: Replace GNAT.xxx by System.xxx when appropriate.
* s-utf_32.adb, s-utf_32.ads, s-os_lib.adb, s-os_lib.ads, s-regexp.adb,
s-regexp.ads, s-regpat.adb, s-regpat.ads, s-string.adb, s-string.ads,
s-tasloc.adb, s-tasloc.ads: New files.
From-SVN: r125360
2007-06-06 12:14:14 +02:00
|
|
|
|
|
|
|
-- This procedure is significantly faster than the Compile function since
|
|
|
|
-- it avoids the extra step of precomputing the required size.
|
|
|
|
--
|
|
|
|
-- However, it requires the user to provide a Pattern_Matcher variable
|
|
|
|
-- whose size is preset to a large enough value. One advantage of this
|
|
|
|
-- approach, in addition to the improved efficiency, is that the same
|
|
|
|
-- Pattern_Matcher variable can be used to hold the compiled code for
|
|
|
|
-- several different regular expressions by setting a size that is large
|
gnat_ugn.texi: Fix typos.
gcc/ada/
* gnat_ugn.texi: Fix typos.
* raise-gcc.c, repinfo.adb, repinfo.ads, restrict.adb,
restrict.ads, rtsfind.adb, rtsfind.ads, s-arit64.ads,
s-asthan-vms-alpha.adb, s-auxdec.ads, s-casuti.ads,
s-fatflt.ads, s-fatgen.adb, s-fatlfl.ads,
s-fatllf.ads, s-fatsfl.ads, s-filofl.ads,
s-finimp.adb, s-finroo.ads, s-fishfl.ads,
s-fvadfl.ads, s-fvaffl.ads, s-fvagfl.ads,
s-hibaen.ads, s-htable.ads, s-imgcha.adb,
s-imgenu.ads, s-imgint.adb, s-imgrea.adb,
s-inmaop-dummy.adb, s-inmaop.ads, s-interr-vms.adb,
s-interr-vxworks.adb, s-interr.adb, s-interr.ads,
s-intman-vxworks.ads, s-intman.ads, s-mastop-irix.adb,
s-os_lib.adb, s-os_lib.ads, s-osinte-aix.ads,
s-osinte-darwin.ads, s-osinte-freebsd.ads,
s-osinte-hpux.ads, s-osinte-lynxos-3.adb,
s-osinte-lynxos-3.ads, s-osinte-lynxos.ads,
s-osinte-rtems.ads, s-osinte-solaris-posix.ads,
s-osprim-mingw.adb, s-osprim-vms.adb, s-parame-ae653.ads,
s-parame-hpux.ads, s-parame-vms-alpha.ads,
s-parame-vms-ia64.ads, s-parame-vms-restrict.ads,
s-parame-vxworks.ads, s-parame.ads, s-parint.adb,
s-parint.ads, s-poosiz.adb, s-proinf-irix-athread.ads,
s-proinf.ads, s-regexp.adb, s-regpat.adb, s-regpat.ads,
s-rident.ads: Fix comment typos.
From-SVN: r134177
2008-04-10 23:44:46 +02:00
|
|
|
-- enough to accommodate all possibilities.
|
g-string.adb, [...]: Replace GNAT.xxx by System.xxx when appropriate.
2007-04-20 Robert Dewar <dewar@adacore.com>
* g-string.adb, s-proinf-irix-athread.adb, s-gloloc-mingw.adb,
s-tfsetr-default.adb, gnatfind.adb, gnatxref.adb, gprep.adb,
g-regexp.adb, g-regexp.ads, g-regpat.ads, g-tasloc.adb, g-tasloc.ads,
output.adb, switch-m.ads, tree_in.ads, tree_io.ads, indepsw.ads,
g-utf_32.adb, g-utf_32.ads, a-wichun.adb, a-wichun.ads, a-zchuni.adb,
a-zchuni.ads: Replace GNAT.xxx by System.xxx when appropriate.
* s-utf_32.adb, s-utf_32.ads, s-os_lib.adb, s-os_lib.ads, s-regexp.adb,
s-regexp.ads, s-regpat.adb, s-regpat.ads, s-string.adb, s-string.ads,
s-tasloc.adb, s-tasloc.ads: New files.
From-SVN: r125360
2007-06-06 12:14:14 +02:00
|
|
|
--
|
|
|
|
-- In this version of the procedure call, the actual required code size is
|
|
|
|
-- returned. Also if Matcher.Size is zero on entry, then the resulting code
|
|
|
|
-- is not stored. A call with Matcher.Size set to Auto_Size can thus be
|
|
|
|
-- used to determine the space required for compiling the given regular
|
|
|
|
-- expression.
|
|
|
|
--
|
|
|
|
-- This function raises Storage_Error if Matcher is too small to hold
|
|
|
|
-- the resulting code (i.e. Matcher.Size has too small a value).
|
|
|
|
--
|
|
|
|
-- Expression_Error is raised if the string Expression does not contain
|
|
|
|
-- a valid regular expression.
|
|
|
|
--
|
|
|
|
-- Flags is the default value to use to set properties for Expression (case
|
|
|
|
-- sensitivity,...).
|
|
|
|
|
|
|
|
procedure Compile
|
|
|
|
(Matcher : out Pattern_Matcher;
|
|
|
|
Expression : String;
|
|
|
|
Flags : Regexp_Flags := No_Flags);
|
|
|
|
-- Same procedure as above, expect it does not return the final
|
|
|
|
-- program size, and Matcher.Size cannot be Auto_Size.
|
|
|
|
|
|
|
|
function Paren_Count (Regexp : Pattern_Matcher) return Match_Count;
|
|
|
|
pragma Inline (Paren_Count);
|
|
|
|
-- Return the number of parenthesis pairs in Regexp.
|
|
|
|
--
|
|
|
|
-- This is the maximum index that will be filled if a Match_Array is
|
|
|
|
-- used as an argument to Match.
|
|
|
|
--
|
|
|
|
-- Thus, if you want to be sure to get all the parenthesis, you should
|
|
|
|
-- do something like:
|
|
|
|
--
|
|
|
|
-- declare
|
|
|
|
-- Regexp : Pattern_Matcher := Compile ("a(b*)(c+)");
|
|
|
|
-- Matched : Match_Array (0 .. Paren_Count (Regexp));
|
|
|
|
-- begin
|
|
|
|
-- Match (Regexp, "a string", Matched);
|
|
|
|
-- end;
|
|
|
|
|
|
|
|
-------------
|
|
|
|
-- Quoting --
|
|
|
|
-------------
|
|
|
|
|
|
|
|
function Quote (Str : String) return String;
|
|
|
|
-- Return a version of Str so that every special character is quoted.
|
|
|
|
-- The resulting string can be used in a regular expression to match
|
|
|
|
-- exactly Str, whatever character was present in Str.
|
|
|
|
|
|
|
|
--------------
|
|
|
|
-- Matching --
|
|
|
|
--------------
|
|
|
|
|
|
|
|
-- The Match subprograms are given a regular expression in string
|
|
|
|
-- form, and perform the corresponding match. The following parameters
|
|
|
|
-- are present in all forms of the Match call.
|
|
|
|
|
|
|
|
-- Expression contains the regular expression to be matched as a string
|
|
|
|
|
|
|
|
-- Data contains the string to be matched
|
|
|
|
|
|
|
|
-- Data_First is the lower bound for the match, i.e. Data (Data_First)
|
|
|
|
-- will be the first character to be examined. If Data_First is set to
|
|
|
|
-- the special value of -1 (the default), then the first character to
|
|
|
|
-- be examined is Data (Data_First). However, the regular expression
|
|
|
|
-- character ^ (start of string) still refers to the first character
|
|
|
|
-- of the full string (Data (Data'First)), which is why there is a
|
|
|
|
-- separate mechanism for specifying Data_First.
|
|
|
|
|
|
|
|
-- Data_Last is the upper bound for the match, i.e. Data (Data_Last)
|
|
|
|
-- will be the last character to be examined. If Data_Last is set to
|
|
|
|
-- the special value of Positive'Last (the default), then the last
|
|
|
|
-- character to be examined is Data (Data_Last). However, the regular
|
|
|
|
-- expression character $ (end of string) still refers to the last
|
|
|
|
-- character of the full string (Data (Data'Last)), which is why there
|
|
|
|
-- is a separate mechanism for specifying Data_Last.
|
|
|
|
|
|
|
|
-- Note: the use of Data_First and Data_Last is not equivalent to
|
|
|
|
-- simply passing a slice as Expression because of the handling of
|
|
|
|
-- regular expression characters ^ and $.
|
|
|
|
|
|
|
|
-- Size is the size allocated for the compiled byte code. Normally
|
|
|
|
-- this is defaulted to Auto_Size which means that the appropriate
|
|
|
|
-- size is allocated automatically. It is possible to specify an
|
|
|
|
-- explicit size, which must be sufficiently large. This slightly
|
|
|
|
-- increases the efficiency by avoiding the extra step of computing
|
|
|
|
-- the appropriate size.
|
|
|
|
|
|
|
|
-- The following exceptions can be raised in calls to Match
|
|
|
|
--
|
|
|
|
-- Storage_Error is raised if a non-zero value is given for Size
|
|
|
|
-- and it is too small to hold the compiled byte code.
|
|
|
|
--
|
|
|
|
-- Expression_Error is raised if the given expression is not a legal
|
|
|
|
-- regular expression.
|
|
|
|
|
|
|
|
procedure Match
|
|
|
|
(Expression : String;
|
|
|
|
Data : String;
|
|
|
|
Matches : out Match_Array;
|
|
|
|
Size : Program_Size := Auto_Size;
|
|
|
|
Data_First : Integer := -1;
|
|
|
|
Data_Last : Positive := Positive'Last);
|
|
|
|
-- This version returns the result of the match stored in Match_Array;
|
|
|
|
-- see comments under Match_Array above for details.
|
|
|
|
|
|
|
|
function Match
|
|
|
|
(Expression : String;
|
|
|
|
Data : String;
|
|
|
|
Size : Program_Size := Auto_Size;
|
|
|
|
Data_First : Integer := -1;
|
|
|
|
Data_Last : Positive := Positive'Last) return Natural;
|
|
|
|
-- This version returns the position where Data matches, or if there is
|
|
|
|
-- no match, then the value Data'First - 1.
|
|
|
|
|
|
|
|
function Match
|
|
|
|
(Expression : String;
|
|
|
|
Data : String;
|
|
|
|
Size : Program_Size := Auto_Size;
|
|
|
|
Data_First : Integer := -1;
|
|
|
|
Data_Last : Positive := Positive'Last) return Boolean;
|
|
|
|
-- This version returns True if the match succeeds, False otherwise
|
|
|
|
|
|
|
|
------------------------------------------------
|
|
|
|
-- Matching a Pre-Compiled Regular Expression --
|
|
|
|
------------------------------------------------
|
|
|
|
|
|
|
|
-- The following functions are significantly faster if you need to reuse
|
|
|
|
-- the same regular expression multiple times, since you only have to
|
|
|
|
-- compile it once. For these functions you must first compile the
|
|
|
|
-- expression with a call to Compile as previously described.
|
|
|
|
|
|
|
|
-- The parameters Data, Data_First and Data_Last are as described
|
|
|
|
-- in the previous section.
|
|
|
|
|
|
|
|
function Match
|
|
|
|
(Self : Pattern_Matcher;
|
|
|
|
Data : String;
|
|
|
|
Data_First : Integer := -1;
|
|
|
|
Data_Last : Positive := Positive'Last) return Natural;
|
|
|
|
-- Match Data using the given pattern matcher. Returns the position
|
|
|
|
-- where Data matches, or (Data'First - 1) if there is no match.
|
|
|
|
|
|
|
|
function Match
|
|
|
|
(Self : Pattern_Matcher;
|
|
|
|
Data : String;
|
|
|
|
Data_First : Integer := -1;
|
|
|
|
Data_Last : Positive := Positive'Last) return Boolean;
|
|
|
|
-- Return True if Data matches using the given pattern matcher
|
|
|
|
|
|
|
|
pragma Inline (Match);
|
|
|
|
-- All except the last one below
|
|
|
|
|
|
|
|
procedure Match
|
|
|
|
(Self : Pattern_Matcher;
|
|
|
|
Data : String;
|
|
|
|
Matches : out Match_Array;
|
|
|
|
Data_First : Integer := -1;
|
|
|
|
Data_Last : Positive := Positive'Last);
|
|
|
|
-- Match Data using the given pattern matcher and store result in Matches;
|
|
|
|
-- see comments under Match_Array above for details.
|
|
|
|
|
|
|
|
-----------
|
|
|
|
-- Debug --
|
|
|
|
-----------
|
|
|
|
|
|
|
|
procedure Dump (Self : Pattern_Matcher);
|
|
|
|
-- Dump the compiled version of the regular expression matched by Self
|
|
|
|
|
|
|
|
--------------------------
|
|
|
|
-- Private Declarations --
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
subtype Pointer is Program_Size;
|
|
|
|
-- The Pointer type is used to point into Program_Data
|
|
|
|
|
|
|
|
-- Note that the pointer type is not necessarily 2 bytes
|
|
|
|
-- although it is stored in the program using 2 bytes
|
|
|
|
|
|
|
|
type Program_Data is array (Pointer range <>) of Character;
|
|
|
|
|
|
|
|
Program_First : constant := 1;
|
|
|
|
|
|
|
|
-- The "internal use only" fields in regexp are present to pass info from
|
|
|
|
-- compile to execute that permits the execute phase to run lots faster on
|
|
|
|
-- simple cases. They are:
|
|
|
|
|
g-expect-vms.adb, [...]: Fix incorrect casing of ASCII.NUL throughout.
2008-04-08 Thomas Quinot <quinot@adacore.com>
* g-expect-vms.adb, a-textio.adb, a-witeio.adb, exp_dbug.adb,
g-expect.adb, g-locfil.adb, gnatchop.adb, gnatdll.adb, gnatlbr.adb,
gnatmem.adb, g-regist.adb, i-vxwork.ads, mlib-utl.adb, i-vxwork-x86.ads,
a-ztexio.adb, g-enblsp-vms-alpha.adb, g-enblsp-vms-ia64.adb,
s-os_lib.adb, s-regpat.adb, s-regpat.ads: Fix incorrect casing of
ASCII.NUL throughout.
From-SVN: r134008
2008-04-08 08:44:39 +02:00
|
|
|
-- First character that must begin a match or ASCII.NUL
|
g-string.adb, [...]: Replace GNAT.xxx by System.xxx when appropriate.
2007-04-20 Robert Dewar <dewar@adacore.com>
* g-string.adb, s-proinf-irix-athread.adb, s-gloloc-mingw.adb,
s-tfsetr-default.adb, gnatfind.adb, gnatxref.adb, gprep.adb,
g-regexp.adb, g-regexp.ads, g-regpat.ads, g-tasloc.adb, g-tasloc.ads,
output.adb, switch-m.ads, tree_in.ads, tree_io.ads, indepsw.ads,
g-utf_32.adb, g-utf_32.ads, a-wichun.adb, a-wichun.ads, a-zchuni.adb,
a-zchuni.ads: Replace GNAT.xxx by System.xxx when appropriate.
* s-utf_32.adb, s-utf_32.ads, s-os_lib.adb, s-os_lib.ads, s-regexp.adb,
s-regexp.ads, s-regpat.adb, s-regpat.ads, s-string.adb, s-string.ads,
s-tasloc.adb, s-tasloc.ads: New files.
From-SVN: r125360
2007-06-06 12:14:14 +02:00
|
|
|
-- Anchored true iff match must start at beginning of line
|
|
|
|
-- Must_Have pointer to string that match must include or null
|
|
|
|
-- Must_Have_Length length of Must_Have string
|
|
|
|
|
|
|
|
-- First and Anchored permit very fast decisions on suitable starting
|
|
|
|
-- points for a match, cutting down the work a lot. Must_Have permits fast
|
|
|
|
-- rejection of lines that cannot possibly match.
|
|
|
|
|
|
|
|
-- The Must_Have tests are costly enough that Optimize supplies a Must_Have
|
|
|
|
-- only if the r.e. contains something potentially expensive (at present,
|
|
|
|
-- the only such thing detected is * or at the start of the r.e., which can
|
|
|
|
-- involve a lot of backup). The length is supplied because the test in
|
|
|
|
-- Execute needs it and Optimize is computing it anyway.
|
|
|
|
|
|
|
|
-- The initialization is meant to fail-safe in case the user of this
|
|
|
|
-- package tries to use an uninitialized matcher. This takes advantage
|
g-expect-vms.adb, [...]: Fix incorrect casing of ASCII.NUL throughout.
2008-04-08 Thomas Quinot <quinot@adacore.com>
* g-expect-vms.adb, a-textio.adb, a-witeio.adb, exp_dbug.adb,
g-expect.adb, g-locfil.adb, gnatchop.adb, gnatdll.adb, gnatlbr.adb,
gnatmem.adb, g-regist.adb, i-vxwork.ads, mlib-utl.adb, i-vxwork-x86.ads,
a-ztexio.adb, g-enblsp-vms-alpha.adb, g-enblsp-vms-ia64.adb,
s-os_lib.adb, s-regpat.adb, s-regpat.ads: Fix incorrect casing of
ASCII.NUL throughout.
From-SVN: r134008
2008-04-08 08:44:39 +02:00
|
|
|
-- of the knowledge that ASCII.NUL translates to the end-of-program (EOP)
|
g-string.adb, [...]: Replace GNAT.xxx by System.xxx when appropriate.
2007-04-20 Robert Dewar <dewar@adacore.com>
* g-string.adb, s-proinf-irix-athread.adb, s-gloloc-mingw.adb,
s-tfsetr-default.adb, gnatfind.adb, gnatxref.adb, gprep.adb,
g-regexp.adb, g-regexp.ads, g-regpat.ads, g-tasloc.adb, g-tasloc.ads,
output.adb, switch-m.ads, tree_in.ads, tree_io.ads, indepsw.ads,
g-utf_32.adb, g-utf_32.ads, a-wichun.adb, a-wichun.ads, a-zchuni.adb,
a-zchuni.ads: Replace GNAT.xxx by System.xxx when appropriate.
* s-utf_32.adb, s-utf_32.ads, s-os_lib.adb, s-os_lib.ads, s-regexp.adb,
s-regexp.ads, s-regpat.adb, s-regpat.ads, s-string.adb, s-string.ads,
s-tasloc.adb, s-tasloc.ads: New files.
From-SVN: r125360
2007-06-06 12:14:14 +02:00
|
|
|
-- instruction code of the state machine.
|
|
|
|
|
|
|
|
No_Flags : constant Regexp_Flags := 0;
|
|
|
|
Case_Insensitive : constant Regexp_Flags := 1;
|
|
|
|
Single_Line : constant Regexp_Flags := 2;
|
|
|
|
Multiple_Lines : constant Regexp_Flags := 4;
|
|
|
|
|
|
|
|
type Pattern_Matcher (Size : Pointer) is record
|
|
|
|
First : Character := ASCII.NUL; -- internal use only
|
|
|
|
Anchored : Boolean := False; -- internal use only
|
|
|
|
Must_Have : Pointer := 0; -- internal use only
|
|
|
|
Must_Have_Length : Natural := 0; -- internal use only
|
|
|
|
Paren_Count : Natural := 0; -- # paren groups
|
|
|
|
Flags : Regexp_Flags := No_Flags;
|
|
|
|
Program : Program_Data (Program_First .. Size) :=
|
|
|
|
(others => ASCII.NUL);
|
|
|
|
end record;
|
|
|
|
|
|
|
|
Never_Match : constant Pattern_Matcher :=
|
|
|
|
(0, ASCII.NUL, False, 0, 0, 0, No_Flags, (others => ASCII.NUL));
|
|
|
|
|
|
|
|
end System.Regpat;
|