Sha256: cc74a057f6b58ed857051781e3dcbb37e0c42d220ba809fb802dd731a396325c

Contents?: true

Size: 1.57 KB

Versions: 8

Compression:

Stored size: 1.57 KB

Contents

#include "template.h"

%%{
	machine Trenni_template_parser;
	
	action instruction_begin {
		instruction.begin = p;
	}
	
	action instruction_end {
		instruction.end = p;
	}
	
	action emit_instruction {
		rb_funcall(delegate, id_instruction, 1, Trenni_Token_string(instruction, encoding));
	}
	
	action emit_instruction_line {
		rb_funcall(delegate, id_instruction, 2, Trenni_Token_string(instruction, encoding), newline);
	}
	
	action instruction_error {
		Trenni_raise_error("failed to parse instruction", buffer, p-s);
	}
	
	action expression_begin {
		expression.begin = p;
	}
	
	action expression_end {
		expression.end = p;
	}
	
	action emit_expression {
		rb_funcall(delegate, id_expression, 1, Trenni_Token_string(expression, encoding));
	}
	
	action expression_error {
		Trenni_raise_error("failed to parse expression", buffer, p-s);
	}
	
	action emit_text {
		rb_funcall(delegate, id_text, 1, Trenni_string(ts, te, encoding));
	}
	
	include template "trenni/template.rl";
	
	write data;
}%%

VALUE Trenni_Native_parse_template(VALUE self, VALUE buffer, VALUE delegate) {
	VALUE string = rb_funcall(buffer, id_read, 0);
	
	rb_encoding *encoding = rb_enc_get(string);
	
	VALUE newline = rb_obj_freeze(rb_enc_str_new("\n", 1, encoding));
	
	const char *s, *p, *pe, *eof, *ts, *te;
	unsigned long cs, act, top = 0, stack[32] = {0};
	
	Trenni_Token expression = {0}, instruction = {0};
	
	s = p = RSTRING_PTR(string);
	eof = pe = p + RSTRING_LEN(string);
	
	%%{
		write init;
		write exec;
	}%%
	
	if (p != eof) {
		Trenni_raise_error("could not parse all input", buffer, p-s);
	}
	
	return Qnil;
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
trenni-3.14.0 ext/trenni/template.rl
trenni-3.13.2 ext/trenni/template.rl
trenni-3.13.1 ext/trenni/template.rl
trenni-3.13.0 ext/trenni/template.rl
trenni-3.12.0 ext/trenni/template.rl
trenni-3.11.0 ext/trenni/template.rl
trenni-3.10.0 ext/trenni/template.rl
trenni-3.9.0 ext/trenni/template.rl