summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormattn <[email protected]>2013-02-15 13:55:41 +0900
committermattn <[email protected]>2013-02-15 13:55:41 +0900
commite0f25b1fda0c9c67526885fafdabf35d4d4039b7 (patch)
tree4a55368fe51eff1bd6b9d8d1e29fe691ceb5d7ee /src
parent55ef8c50fb959649c8a37ac2412d59da3d79e5b1 (diff)
downloadmruby-e0f25b1fda0c9c67526885fafdabf35d4d4039b7.tar.gz
mruby-e0f25b1fda0c9c67526885fafdabf35d4d4039b7.zip
ready to pass second argument of Regexp.new
Diffstat (limited to 'src')
-rw-r--r--src/codegen.c13
-rw-r--r--src/parse.y55
-rw-r--r--src/re.h7
3 files changed, 39 insertions, 36 deletions
diff --git a/src/codegen.c b/src/codegen.c
index d1242a29f..86cb5eb87 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -16,6 +16,7 @@
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
+#include "re.h"
typedef mrb_ast_node node;
typedef struct mrb_parser_state parser_state;
@@ -1912,12 +1913,14 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_REGX:
if (val) {
- char *p = (char*)tree->car;
- size_t len = (intptr_t)tree->cdr;
+ char *p1 = (char*)tree->car;
+ //char *p2 = (char*)tree->cdr;
int ai = mrb_gc_arena_save(s->mrb);
- struct RClass* c = mrb_class_get(s->mrb, "Regexp");
- mrb_value args[1];
- args[0] = mrb_str_new(s->mrb, p, len);
+ struct RClass* c = mrb_class_get(s->mrb, REGEXP_CLASS);
+ mrb_value args[2];
+ args[0] = mrb_str_new(s->mrb, p1, strlen(p1));
+ // TODO: Some regexp implementation does not have second argument
+ //args[1] = mrb_str_new(s->mrb, p2, strlen(p2));
int off = new_lit(s,
mrb_class_new_instance(s->mrb, 1, args, c));
diff --git a/src/parse.y b/src/parse.y
index 518985ea6..9af8682c1 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -708,11 +708,11 @@ new_dsym(parser_state *p, node *a)
return cons((node*)NODE_DSYM, new_dstr(p, a));
}
-// (:str . (s . len))
+// (:str . (a . a))
static node*
-new_regx(parser_state *p, const char *s, int len)
+new_regx(parser_state *p, const char *p1, const char* p2)
{
- return cons((node*)NODE_REGX, cons((node*)strndup(s, len), (node*)(intptr_t)len));
+ return cons((node*)NODE_REGX, cons((node*)p1, (node*)p2));
}
// (:backref . n)
@@ -3401,26 +3401,6 @@ read_escape(parser_state *p)
}
}
-static void
-regx_options(parser_state *p)
-{
- int c;
-
- newtok(p);
- while (c = nextc(p), ISALPHA(c)) {
- tokadd(p, c);
- }
-
- pushback(p, c);
- if (toklen(p)) {
- char msg[128];
- tokfix(p);
- snprintf(msg, sizeof(msg), "unknown regexp option %s - %s",
- toklen(p) > 1 ? "s" : "", tok(p));
- yyerror(p, msg);
- }
-}
-
static int
parse_string(parser_state *p, int term)
{
@@ -3465,8 +3445,33 @@ parse_string(parser_state *p, int term)
p->sterm = 0;
if (p->regexp) {
- //regx_options(p);
- yylval.nd = new_regx(p, tok(p), toklen(p));
+ int f = 0;
+ int c;
+ char* s;
+ s = strndup(tok(p), toklen(p));
+ newtok(p);
+ while (c = nextc(p), ISALPHA(c)) {
+ switch (c) {
+ case 'i': f |= 1; break;
+ case 'x': f |= 2; break;
+ case 'm': f |= 4; break;
+ default: tokadd(p, c); break;
+ }
+ }
+ pushback(p, c);
+ if (toklen(p)) {
+ char msg[128];
+ free(s);
+ tokfix(p);
+ snprintf(msg, sizeof(msg), "unknown regexp option %s - %s",
+ toklen(p) > 1 ? "s" : "", tok(p));
+ yyerror(p, msg);
+ }
+ char flag[4] = {0};
+ if (f & 1) strcat(flag, "i");
+ if (f & 2) strcat(flag, "x");
+ if (f & 4) strcat(flag, "m");
+ yylval.nd = new_regx(p, s, strdup(flag));
p->regexp = 0;
return tREGEXP;
diff --git a/src/re.h b/src/re.h
index eafe50dc8..64dbd60dc 100644
--- a/src/re.h
+++ b/src/re.h
@@ -7,12 +7,7 @@
#ifndef RE_H
#define RE_H
-//#include <sys/types.h>
-#include <stdio.h>
-
-#include "node.h"
-#include "st.h"
-
+//#define REGEXP_CLASS "HsRegexp"
#define REGEXP_CLASS "Regexp"
#endif