ext/lexerc/lexerc.rl in hotcell-0.2.0 vs ext/lexerc/lexerc.rl in hotcell-0.3.0
- old
+ new
@@ -1,15 +1,42 @@
%%{
- machine puffer_lexer;
+ machine hotcell_lexer;
action RegexpCheck {
if (regexp_possible == Qfalse) {
emit_operator;
fgoto expression;
}
}
+ action Interpolate {
+ braces_count = 0;
+ emit_interpolation;
+ fcall interpolation;
+ }
+
+ action OpenBrace {
+ emit_operator;
+ braces_count++;
+ }
+
+ action CloseBrace {
+ if (braces_count < 1) {
+ emit_interpolation;
+ fret;
+ } else {
+ emit_operator;
+ braces_count--;
+ }
+ }
+
+ action ParseDstring {
+ dstring_start = ts - data;
+ emit_dstring_open;
+ fcall dstring;
+ }
+
include "lexer.rl";
}%%
#include <ruby.h>
@@ -23,10 +50,12 @@
static char *p;
static char *ts;
static char *te;
static char *data;
static VALUE encoding;
+static int braces_count;
+static long dstring_start;
static VALUE tokenize(VALUE self) {
VALUE source = rb_iv_get(self, "@source");
encoding = rb_funcall(source, rb_intern("encoding"), 0);
VALUE string = rb_funcall(source, rb_intern("source"), 0);
@@ -47,9 +76,14 @@
free(stack);
if (ts > 0 && ((ts - data) < (pe - data - 1))) {
raise_unexpected_symbol;
+ }
+
+ if (cs == hotcell_lexer_en_dstring) {
+ ts = data + dstring_start;
+ raise_unterminated_string;
}
return rb_iv_get(self, "@token_array");
}