Changeset 520


Ignore:
Timestamp:
01/31/09 15:15:37 (3 years ago)
Author:
mooneer
Message:

Regular expressions can be specified with "r/.../[i]" syntax (ticket #79)

Location:
interpreter/trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • interpreter/trunk/ChangeLog

    r513 r520  
     11/31/2009: 
     2    * Regular expressions can be specified with "r/.../[i]" syntax (ticket #79) 
     3 
     41/30/2009: 
     5    * Compile errors/warnings fixed when compiling with GCC 4.2. (ticket #82) 
     6    * Fixed infinite loop during string|split with an empty-string delimiter. (ticket #80) 
     7    * Fixed capture issue in the regular expression engine when using '?' next to parenthesis (ticket #81) 
     8     
    191/29/2009: 
    210    * System.digest merged into main tree (thanks to Michael J. Edgar). 
    311    * System.list|sort method added (credit: Michael J. Edgar). 
    4      
     12 
    5131/1/2009: 
    614    * 1.0.0 released. 
  • interpreter/trunk/docs/kite-language.texi

    r517 r520  
    8888System.math.range object (see kdoc documentation) that represents all the 
    8989numbers from one integer to another (possibly skipping numbers along the way). 
     90 
     91Regular expressions are also built-into the language syntax as of 1.0.1. Regular 
     92expressions begin with "r/" and end with either "/" (case-sensitive) or "/i" 
     93(case-insensitive). This is equivalent to creating a new System.regex object 
     94with the appropriate parameters. 
    9095 
    9196@node Declarations 
  • interpreter/trunk/modules/System/regex.kt

    r415 r520  
    4242]; 
    4343 
     44construct( 
     45    regex /[Regular expression to use.]/, 
     46    c_insensitive /[Case insensitivity on/off]/ 
     47) /[Construct new regular expression object.]/ 
     48[ 
     49    this.internal_regex_obj = make __internal._regex(regex); 
     50    this.case_insensitive = c_insensitive; 
     51]; 
     52 
    4453method match( 
    4554    str /[String to search.]/ 
  • interpreter/trunk/tests/Makefile.am

    r515 r520  
    256256./objs/regex/regex_boundary.kt \ 
    257257./objs/regex/regex_boundary.kt.out \ 
     258./objs/regex/regex_syntax.kt \ 
     259./objs/regex/regex_syntax.kt.out \ 
    258260./objs/base64/base64_encode.kt \ 
    259261./objs/base64/base64_encode.kt.out \ 
  • interpreter/trunk/tests/objs/loader/loader_notfound.kt

    r208 r520  
    11import "System.vm.loader"; 
    22run [ 
    3     System.vm.loader|loadClass("System.exceptions.TypeMismatch2"); 
     3    System.vm.loader|loadClass("Kite.ThisClassDoesNotExist"); 
    44] catch [ 
    55    __exc|str()|print(); 
  • interpreter/trunk/vm/kite_lexer.l

    r491 r520  
    2828%} 
    2929 
    30 %x operator str sym docstr 
     30%x operator str sym docstr regex 
    3131%option noyywrap 
    3232%option bison-bridge bison-locations reentrant 
     
    105105false { fillBoth(yyscanner); yylval->intValue = 0; return BOOL_VALUE; } 
    106106 
     107"r/" { 
     108    kite_compiler_t *compiler = (kite_compiler_t*)yyextra; 
     109        fillFirst(yyscanner); 
     110        BEGIN(regex); 
     111        compiler->curStr = strdup(""); 
     112} 
     113 
    107114\" { 
    108115        kite_compiler_t *compiler = (kite_compiler_t*)yyextra; 
     
    117124        BEGIN(docstr); 
    118125        compiler->curStr = strdup(""); 
     126} 
     127 
     128<regex>[^/]+ { 
     129    kite_compiler_t *compiler = (kite_compiler_t*)yyextra; 
     130        APPEND_STRING(yytext); 
     131        compiler->currentCol += strlen(yytext); 
     132} 
     133 
     134<regex>"\\/" { 
     135    kite_compiler_t *compiler = (kite_compiler_t*)yyextra; 
     136        APPEND_STRING("/"); 
     137        compiler->currentCol += strlen(yytext); 
     138} 
     139 
     140<regex>"/i" { 
     141    kite_compiler_t *compiler = (kite_compiler_t*)yyextra; 
     142        fillLast(yyscanner); 
     143        BEGIN(INITIAL); 
     144        yylval->stringValue = compiler->curStr; 
     145        return REGEX_VALUE_CI; 
     146} 
     147 
     148<regex>"/" { 
     149    kite_compiler_t *compiler = (kite_compiler_t*)yyextra; 
     150        fillLast(yyscanner); 
     151        BEGIN(INITIAL); 
     152        yylval->stringValue = compiler->curStr; 
     153        return REGEX_VALUE; 
    119154} 
    120155 
  • interpreter/trunk/vm/kite_parser.y

    r507 r520  
    154154%token RETURN 
    155155%token VERSION_KEYWORD 
     156%token REGEX_VALUE 
     157%token REGEX_VALUE_CI 
    156158 
    157159/* Needed since we can't quite lay out the associativity using the rules yet. */ 
     
    10471049        kite_dereference_object(range_class); 
    10481050        kite_dereference_object(range_object); 
     1051        $<opValue>$ = NULL; 
     1052    } 
     1053    | REGEX_VALUE { 
     1054        kite_compiler_t *compiler = (kite_compiler_t*)yyget_extra(parm); 
     1055        kite_thread_t *thd = compiler->thd; 
     1056        kite_object_t *param_list = kite_new_list(thd); 
     1057        kite_object_t *regex_obj = kite_dereference_and_load(thd, "System.regex"); 
     1058         
     1059        kite_append_list(thd, param_list, kite_new_string(thd, $<stringValue>1)); 
     1060         
     1061        COMPILE_INSTRUCTION(kite_compile_push(regex_obj), @1.first_line); 
     1062        COMPILE_INSTRUCTION(kite_compile_push(param_list), @1.first_line); 
     1063        COMPILE_INSTRUCTION(kite_compile_make(), @1.first_line); 
     1064         
     1065        free($<stringValue>1); 
     1066        $<opValue>$ = NULL; 
     1067    } 
     1068    | REGEX_VALUE_CI { 
     1069        kite_compiler_t *compiler = (kite_compiler_t*)yyget_extra(parm); 
     1070        kite_thread_t *thd = compiler->thd; 
     1071        kite_object_t *param_list = kite_new_list(thd); 
     1072        kite_object_t *regex_obj = kite_dereference_and_load(thd, "System.regex"); 
     1073         
     1074        kite_append_list(thd, param_list, kite_new_string(thd, $<stringValue>1)); 
     1075        kite_append_list(thd, param_list, kite_new_boolean(thd, TRUE)); 
     1076         
     1077        COMPILE_INSTRUCTION(kite_compile_push(regex_obj), @1.first_line); 
     1078        COMPILE_INSTRUCTION(kite_compile_push(param_list), @1.first_line); 
     1079        COMPILE_INSTRUCTION(kite_compile_make(), @1.first_line); 
     1080         
     1081        free($<stringValue>1); 
    10491082        $<opValue>$ = NULL; 
    10501083    } 
Note: See TracChangeset for help on using the changeset viewer.