2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-21 15:02:19 +00:00

Add native version of 'regex.transform'. The rule is used during header

scanning, so should be as fast as possible.


[SVN r21205]
This commit is contained in:
Vladimir Prus
2003-12-10 11:29:09 +00:00
parent 167f6c79da
commit 8dacac3c02
11 changed files with 129 additions and 6 deletions

View File

@@ -319,7 +319,7 @@ set BJAM_SOURCES=%BJAM_SOURCES% hdrmacro.c headers.c jam.c jambase.c jamgram.c l
set BJAM_SOURCES=%BJAM_SOURCES% newstr.c option.c parse.c pathunix.c pathvms.c regexp.c
set BJAM_SOURCES=%BJAM_SOURCES% rules.c scan.c search.c subst.c timestamp.c variable.c modules.c
set BJAM_SOURCES=%BJAM_SOURCES% strings.c filesys.c builtins.c pwd.c class.c w32_getreg.c native.c
set BJAM_SOURCES=%BJAM_SOURCES% modules/set.c modules/path.c
set BJAM_SOURCES=%BJAM_SOURCES% modules/set.c modules/path.c modules/regex.c
@echo ON
rd /S /Q bootstrap.%BOOST_JAM_TOOLSET%

View File

@@ -276,7 +276,7 @@ jam.source =
scan.c search.c subst.c
timestamp.c variable.c modules.c strings.c filesys.c
builtins.c pwd.c class.c native.c modules/set.c
modules/path.c
modules/path.c modules/regex.c
;
if $(NT)
{

View File

@@ -192,7 +192,7 @@ BJAM_SOURCES="\
newstr.c option.c parse.c pathunix.c pathvms.c regexp.c\
rules.c scan.c search.c subst.c timestamp.c variable.c modules.c\
strings.c filesys.c builtins.c pwd.c class.c native.c modules/set.c\
modules/path.c"
modules/path.c modules/regex.c"
echo_run rm -rf bootstrap.$BOOST_JAM_TOOLSET
echo_run mkdir bootstrap.$BOOST_JAM_TOOLSET

View File

@@ -274,6 +274,7 @@ load_builtins()
/* Initialize builtin modules */
init_set();
init_path();
init_regex();
}
/*

View File

@@ -0,0 +1,60 @@
#include "../native.h"
#include "../timestamp.h"
#include "../newstr.h"
#include "../strings.h"
#include "../regexp.h"
#include "../compile.h"
/*
rule transform ( list * : pattern )
{
local result ;
for local e in $(list)
{
local m = [ MATCH $(pattern) : $(e) ] ;
if $(m)
{
result += $(m[1]) ;
}
}
return $(result) ;
}
*/
LIST *regex_transform( PARSE *parse, FRAME *frame )
{
LIST* l = lol_get( frame->args, 0 );
LIST* pattern = lol_get( frame->args, 1 );
LIST* result = 0;
string buf[1];
string_new(buf);
/* Result is cached and intentionally never freed */
regexp *re = regex_compile( pattern->string );
for(; l; l = l->next)
{
if( regexec( re, l->string ) )
{
if (re->startp[1])
{
string_append_range( buf, re->startp[1], re->endp[1] );
result = list_new( result, newstr( buf->value ) );
string_truncate( buf, 0 );
}
}
}
string_free( buf );
return result;
}
void init_regex()
{
{
char* args[] = { "list", "*", ":", "pattern", 0 };
declare_native_rule("regex", "transform", args, regex_transform);
}
}

View File

@@ -319,7 +319,7 @@ set BJAM_SOURCES=%BJAM_SOURCES% hdrmacro.c headers.c jam.c jambase.c jamgram.c l
set BJAM_SOURCES=%BJAM_SOURCES% newstr.c option.c parse.c pathunix.c pathvms.c regexp.c
set BJAM_SOURCES=%BJAM_SOURCES% rules.c scan.c search.c subst.c timestamp.c variable.c modules.c
set BJAM_SOURCES=%BJAM_SOURCES% strings.c filesys.c builtins.c pwd.c class.c w32_getreg.c native.c
set BJAM_SOURCES=%BJAM_SOURCES% modules/set.c modules/path.c
set BJAM_SOURCES=%BJAM_SOURCES% modules/set.c modules/path.c modules/regex.c
@echo ON
rd /S /Q bootstrap.%BOOST_JAM_TOOLSET%

View File

@@ -276,7 +276,7 @@ jam.source =
scan.c search.c subst.c
timestamp.c variable.c modules.c strings.c filesys.c
builtins.c pwd.c class.c native.c modules/set.c
modules/path.c
modules/path.c modules/regex.c
;
if $(NT)
{

View File

@@ -192,7 +192,7 @@ BJAM_SOURCES="\
newstr.c option.c parse.c pathunix.c pathvms.c regexp.c\
rules.c scan.c search.c subst.c timestamp.c variable.c modules.c\
strings.c filesys.c builtins.c pwd.c class.c native.c modules/set.c\
modules/path.c"
modules/path.c modules/regex.c"
echo_run rm -rf bootstrap.$BOOST_JAM_TOOLSET
echo_run mkdir bootstrap.$BOOST_JAM_TOOLSET

View File

@@ -274,6 +274,7 @@ load_builtins()
/* Initialize builtin modules */
init_set();
init_path();
init_regex();
}
/*

60
jam_src/modules/regex.c Normal file
View File

@@ -0,0 +1,60 @@
#include "../native.h"
#include "../timestamp.h"
#include "../newstr.h"
#include "../strings.h"
#include "../regexp.h"
#include "../compile.h"
/*
rule transform ( list * : pattern )
{
local result ;
for local e in $(list)
{
local m = [ MATCH $(pattern) : $(e) ] ;
if $(m)
{
result += $(m[1]) ;
}
}
return $(result) ;
}
*/
LIST *regex_transform( PARSE *parse, FRAME *frame )
{
LIST* l = lol_get( frame->args, 0 );
LIST* pattern = lol_get( frame->args, 1 );
LIST* result = 0;
string buf[1];
string_new(buf);
/* Result is cached and intentionally never freed */
regexp *re = regex_compile( pattern->string );
for(; l; l = l->next)
{
if( regexec( re, l->string ) )
{
if (re->startp[1])
{
string_append_range( buf, re->startp[1], re->endp[1] );
result = list_new( result, newstr( buf->value ) );
string_truncate( buf, 0 );
}
}
}
string_free( buf );
return result;
}
void init_regex()
{
{
char* args[] = { "list", "*", ":", "pattern", 0 };
declare_native_rule("regex", "transform", args, regex_transform);
}
}

View File

@@ -57,6 +57,7 @@ rule transform ( list * : pattern )
}
return $(result) ;
}
NATIVE_RULE regex : transform ;
# Escapes all of the characters in symbols using the escape symbol
# escape-symbol for the given string, and returns the escaped string