mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-17 18:00:41 -07:00
Convert parser to C99
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
# V=0 quiet, V=1 verbose. other values don't work.
|
||||
V = 0
|
||||
Q1 = $(V:1=)
|
||||
Q = $(Q1:0=@)
|
||||
n=$(NULLCMD)
|
||||
ECHO1 = $(V:1=@$n)
|
||||
ECHO = $(ECHO1:0=@echo)
|
||||
|
||||
#### Start of system configuration section. ####
|
||||
|
||||
srcdir = .
|
||||
topdir = /Users/tobi/.rbenv/versions/1.9.3-p194-perf/include/ruby-1.9.1
|
||||
hdrdir = /Users/tobi/.rbenv/versions/1.9.3-p194-perf/include/ruby-1.9.1
|
||||
arch_hdrdir = /Users/tobi/.rbenv/versions/1.9.3-p194-perf/include/ruby-1.9.1/$(arch)
|
||||
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
|
||||
prefix = $(DESTDIR)/Users/tobi/.rbenv/versions/1.9.3-p194-perf
|
||||
exec_prefix = $(prefix)
|
||||
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
||||
bindir = $(exec_prefix)/bin
|
||||
sbindir = $(exec_prefix)/sbin
|
||||
libexecdir = $(exec_prefix)/libexec
|
||||
datarootdir = $(prefix)/share
|
||||
datadir = $(datarootdir)
|
||||
sysconfdir = $(prefix)/etc
|
||||
sharedstatedir = $(prefix)/com
|
||||
localstatedir = $(prefix)/var
|
||||
includedir = $(prefix)/include
|
||||
oldincludedir = $(DESTDIR)/usr/include
|
||||
docdir = $(datarootdir)/doc/$(PACKAGE)
|
||||
infodir = $(datarootdir)/info
|
||||
htmldir = $(docdir)
|
||||
dvidir = $(docdir)
|
||||
pdfdir = $(docdir)
|
||||
psdir = $(docdir)
|
||||
libdir = $(exec_prefix)/lib
|
||||
localedir = $(datarootdir)/locale
|
||||
mandir = $(datarootdir)/man
|
||||
ridir = $(datarootdir)/$(RI_BASE_NAME)
|
||||
sitedir = $(rubylibprefix)/site_ruby
|
||||
vendordir = $(rubylibprefix)/vendor_ruby
|
||||
rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
|
||||
sitehdrdir = $(rubyhdrdir)/site_ruby
|
||||
vendorhdrdir = $(rubyhdrdir)/vendor_ruby
|
||||
rubylibdir = $(rubylibprefix)/$(ruby_version)
|
||||
archdir = $(rubylibdir)/$(arch)
|
||||
sitelibdir = $(sitedir)/$(ruby_version)
|
||||
sitearchdir = $(sitelibdir)/$(sitearch)
|
||||
vendorlibdir = $(vendordir)/$(ruby_version)
|
||||
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
||||
|
||||
NULLCMD = :
|
||||
|
||||
CC = /usr/bin/gcc-4.2
|
||||
CXX = g++
|
||||
LIBRUBY = $(LIBRUBY_A)
|
||||
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
||||
LIBRUBYARG_SHARED =
|
||||
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
||||
OUTFLAG = -o
|
||||
COUTFLAG = -o
|
||||
|
||||
RUBY_EXTCONF_H =
|
||||
cflags = $(optflags) $(debugflags) $(warnflags)
|
||||
optflags = -O3
|
||||
debugflags = -ggdb
|
||||
warnflags = -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration
|
||||
CFLAGS = -fno-common $(cflags) -pipe $(ARCH_FLAG)
|
||||
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
||||
DEFS =
|
||||
CPPFLAGS = -I'/Users/tobi/.rbenv/versions/1.9.3-p194-perf/include' -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
|
||||
CXXFLAGS = $(CFLAGS) $(cxxflags)
|
||||
ldflags = -L. -L'/Users/tobi/.rbenv/versions/1.9.3-p194-perf/lib' -L/usr/local/lib
|
||||
dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace
|
||||
ARCH_FLAG =
|
||||
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
|
||||
LDSHARED = $(CC) -dynamic -bundle
|
||||
LDSHAREDXX = $(CXX) -dynamic -bundle
|
||||
AR = ar
|
||||
EXEEXT =
|
||||
|
||||
RUBY_BASE_NAME = ruby
|
||||
RUBY_INSTALL_NAME = ruby
|
||||
RUBY_SO_NAME = ruby
|
||||
arch = x86_64-darwin12.0.0
|
||||
sitearch = $(arch)
|
||||
ruby_version = 1.9.1
|
||||
ruby = /Users/tobi/.rbenv/versions/1.9.3-p194-perf/bin/ruby
|
||||
RUBY = $(ruby)
|
||||
RM = rm -f
|
||||
RM_RF = $(RUBY) -run -e rm -- -rf
|
||||
RMDIRS = rmdir -p
|
||||
MAKEDIRS = mkdir -p
|
||||
INSTALL = /usr/bin/install -c
|
||||
INSTALL_PROG = $(INSTALL) -m 0755
|
||||
INSTALL_DATA = $(INSTALL) -m 644
|
||||
COPY = cp
|
||||
|
||||
#### End of system configuration section. ####
|
||||
|
||||
preload =
|
||||
|
||||
libpath = . $(libdir)
|
||||
LIBPATH = -L. -L$(libdir)
|
||||
DEFFILE =
|
||||
|
||||
CLEANFILES = mkmf.log
|
||||
DISTCLEANFILES =
|
||||
DISTCLEANDIRS =
|
||||
|
||||
extout =
|
||||
extout_prefix =
|
||||
target_prefix =
|
||||
LOCAL_LIBS =
|
||||
LIBS = -lc -lpthread -ldl -lobjc
|
||||
SRCS = liquid_ext.c
|
||||
OBJS = liquid_ext.o
|
||||
TARGET = liquid_ext
|
||||
DLLIB = $(TARGET).bundle
|
||||
EXTSTATIC =
|
||||
STATIC_LIB =
|
||||
|
||||
BINDIR = $(bindir)
|
||||
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
||||
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
||||
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
||||
HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
|
||||
ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
|
||||
|
||||
TARGET_SO = $(DLLIB)
|
||||
CLEANLIBS = $(TARGET).bundle
|
||||
CLEANOBJS = *.o *.bak
|
||||
|
||||
all: $(DLLIB)
|
||||
static: $(STATIC_LIB)
|
||||
.PHONY: all install static install-so install-rb
|
||||
.PHONY: clean clean-so clean-rb
|
||||
|
||||
clean-rb-default::
|
||||
clean-rb::
|
||||
clean-so::
|
||||
clean: clean-so clean-rb-default clean-rb
|
||||
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
||||
|
||||
distclean-rb-default::
|
||||
distclean-rb::
|
||||
distclean-so::
|
||||
distclean: clean distclean-so distclean-rb-default distclean-rb
|
||||
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
||||
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
||||
@-$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
|
||||
|
||||
realclean: distclean
|
||||
install: install-so install-rb
|
||||
|
||||
install-so: $(RUBYARCHDIR)
|
||||
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
||||
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
||||
@-$(MAKEDIRS) $(@D)
|
||||
$(INSTALL_PROG) $(DLLIB) $(@D)
|
||||
install-rb: pre-install-rb install-rb-default
|
||||
install-rb-default: pre-install-rb-default
|
||||
pre-install-rb: Makefile
|
||||
pre-install-rb-default: Makefile
|
||||
pre-install-rb-default:
|
||||
$(ECHO) installing default liquid_ext libraries
|
||||
$(RUBYARCHDIR):
|
||||
$(Q) $(MAKEDIRS) $@
|
||||
|
||||
site-install: site-install-so site-install-rb
|
||||
site-install-so: install-so
|
||||
site-install-rb: install-rb
|
||||
|
||||
.SUFFIXES: .c .m .cc .mm .cxx .cpp .C .o
|
||||
|
||||
.cc.o:
|
||||
$(ECHO) compiling $(<)
|
||||
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
||||
|
||||
.mm.o:
|
||||
$(ECHO) compiling $(<)
|
||||
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
||||
|
||||
.cxx.o:
|
||||
$(ECHO) compiling $(<)
|
||||
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
||||
|
||||
.cpp.o:
|
||||
$(ECHO) compiling $(<)
|
||||
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
||||
|
||||
.C.o:
|
||||
$(ECHO) compiling $(<)
|
||||
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
||||
|
||||
.c.o:
|
||||
$(ECHO) compiling $(<)
|
||||
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
||||
|
||||
.m.o:
|
||||
$(ECHO) compiling $(<)
|
||||
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
||||
|
||||
$(DLLIB): $(OBJS) Makefile
|
||||
$(ECHO) linking shared-object $(DLLIB)
|
||||
@-$(RM) $(@)
|
||||
$(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
||||
|
||||
|
||||
|
||||
$(OBJS): $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h
|
||||
@@ -0,0 +1,6 @@
|
||||
require 'mkmf'
|
||||
|
||||
dir_config("liquid_ext")
|
||||
have_library("c", "main")
|
||||
|
||||
create_makefile("liquid_ext")
|
||||
Executable
BIN
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
Parser for context#[] method. Generated through ragel from parser.rl
|
||||
Only modify parser.rl. Run rake ragel afterwards to generate this file.
|
||||
*/
|
||||
|
||||
#include <ruby.h>
|
||||
|
||||
%%{
|
||||
machine fsm;
|
||||
|
||||
action mark {
|
||||
mark = p;
|
||||
}
|
||||
|
||||
action lookup {
|
||||
EMIT("lookup", Qnil)
|
||||
}
|
||||
|
||||
action call {
|
||||
EMIT("call", Qnil)
|
||||
}
|
||||
action range {
|
||||
EMIT("range", Qnil)
|
||||
}
|
||||
|
||||
constants = ( "true" | "false" | "nil" | "null" );
|
||||
|
||||
# strings
|
||||
string = "\"" any* "\"" | "'" any* "'";
|
||||
|
||||
# nothingness
|
||||
nil = "nil" | "null" ;
|
||||
|
||||
# numbers
|
||||
integer = ('+'|'-')? digit+;
|
||||
float = ('+'|'-')? digit+ '.' digit+;
|
||||
|
||||
# simple values
|
||||
primitive = (
|
||||
|
||||
integer >mark %{
|
||||
EMIT("id", rb_funcall(rb_cObject, rb_intern("Integer"), 1, rb_str_new(mark, p - mark)));
|
||||
} |
|
||||
|
||||
float >mark %{
|
||||
EMIT("id", rb_funcall(rb_cObject, rb_intern("Float"), 1, rb_str_new(mark, p - mark)))
|
||||
} |
|
||||
|
||||
nil %{ EMIT("id", Qnil) } |
|
||||
"true" %{ EMIT("id", Qtrue) } |
|
||||
"false" %{ EMIT("id", Qfalse) } |
|
||||
|
||||
string >mark %{ EMIT("id", rb_str_new(mark + 1, p - mark - 2)) }
|
||||
|
||||
);
|
||||
|
||||
entity = (
|
||||
((alpha [A-Za-z0-9_\-]*) - (constants)) >mark %{
|
||||
EMIT("id", rb_str_new(mark, p - mark))
|
||||
EMIT("lookup", Qnil)
|
||||
}
|
||||
);
|
||||
|
||||
# Because of recursion we cannot immediatly resolve the content of this in
|
||||
# the current grammar. We simply re-invoke the parser here to descend into
|
||||
# the substring
|
||||
recur = (
|
||||
(any+ - ']') >mark %{
|
||||
VALUE body = rb_str_new(mark, p - mark);
|
||||
liquid_context_parse_impl(body, tokens);
|
||||
}
|
||||
);
|
||||
|
||||
expr = (
|
||||
entity |
|
||||
primitive |
|
||||
"(" (primitive | entity) ".." (primitive | entity) <: ")" %range |
|
||||
"[" recur "]" %lookup
|
||||
);
|
||||
|
||||
hash_accessors = (
|
||||
"[" recur "]" %call |
|
||||
|
||||
".first" %{
|
||||
EMIT("buildin", rb_str_new2("first"))
|
||||
} |
|
||||
|
||||
".last" %{
|
||||
EMIT("buildin", rb_str_new2("last"))
|
||||
} |
|
||||
|
||||
".size" %{
|
||||
EMIT("buildin", rb_str_new2("size"))
|
||||
} |
|
||||
|
||||
"." ((alpha [A-Za-z0-9_\-]*) - ("first"|"last"|"size")) >mark %{
|
||||
EMIT("id", rb_str_new(mark, p - mark))
|
||||
EMIT("call", Qnil)
|
||||
}
|
||||
);
|
||||
|
||||
main := (
|
||||
|
||||
expr <: (hash_accessors)*
|
||||
|
||||
);
|
||||
|
||||
}%%
|
||||
|
||||
%% write data nofinal;
|
||||
|
||||
// def self.emit(sym, data, tokens)
|
||||
// puts "emitting: #{sym} -> #{data.inspect}" if $VERBOSE
|
||||
// tokens.push [sym, data]
|
||||
// end
|
||||
|
||||
#define EMIT(sym, data) rb_ary_push(tokens, rb_ary_new3(2, ID2SYM(rb_intern(sym)), data));
|
||||
|
||||
|
||||
void liquid_context_parse_impl(VALUE text, VALUE tokens)
|
||||
{
|
||||
char *p;
|
||||
char *pe;
|
||||
char *eof;
|
||||
char *mark;
|
||||
int cs, res = 0;
|
||||
|
||||
if (RSTRING_LEN(text) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
mark = p = RSTRING_PTR(text);
|
||||
eof = pe = RSTRING_PTR(text) + RSTRING_LEN(text);
|
||||
|
||||
%% write init;
|
||||
%% write exec;
|
||||
}
|
||||
|
||||
VALUE liquid_context_parse(VALUE self, VALUE text) {
|
||||
VALUE tokens;
|
||||
|
||||
//printf("text: %s\n", RSTRING_PTR(text));
|
||||
|
||||
//Check_Type(text, T_STRING);
|
||||
|
||||
tokens = rb_ary_new();
|
||||
liquid_context_parse_impl(text, tokens);
|
||||
return tokens;
|
||||
}
|
||||
|
||||
static VALUE rb_Liquid;
|
||||
static VALUE rb_Parser;
|
||||
|
||||
void Init_liquid_ext()
|
||||
{
|
||||
rb_Liquid = rb_define_module("Liquid");
|
||||
rb_Parser = rb_define_class_under(rb_Liquid, "Parser", rb_cObject);
|
||||
rb_define_singleton_method(rb_Parser, "parse", liquid_context_parse, 1);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
have_library: checking for main() in -lc... -------------------- yes
|
||||
|
||||
"/usr/bin/gcc-4.2 -o conftest -I/Users/tobi/.rbenv/versions/1.9.3-p194-perf/include/ruby-1.9.1/x86_64-darwin12.0.0 -I/Users/tobi/.rbenv/versions/1.9.3-p194-perf/include/ruby-1.9.1/ruby/backward -I/Users/tobi/.rbenv/versions/1.9.3-p194-perf/include/ruby-1.9.1 -I. -I'/Users/tobi/.rbenv/versions/1.9.3-p194-perf/include' -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I'/Users/tobi/.rbenv/versions/1.9.3-p194-perf/include' -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -pipe conftest.c -L. -L/Users/tobi/.rbenv/versions/1.9.3-p194-perf/lib -L. -L'/Users/tobi/.rbenv/versions/1.9.3-p194-perf/lib' -L/usr/local/lib -lruby-static -lpthread -ldl -lobjc "
|
||||
checked program was:
|
||||
/* begin */
|
||||
1: #include "ruby.h"
|
||||
2:
|
||||
3: int main() {return 0;}
|
||||
/* end */
|
||||
|
||||
"/usr/bin/gcc-4.2 -o conftest -I/Users/tobi/.rbenv/versions/1.9.3-p194-perf/include/ruby-1.9.1/x86_64-darwin12.0.0 -I/Users/tobi/.rbenv/versions/1.9.3-p194-perf/include/ruby-1.9.1/ruby/backward -I/Users/tobi/.rbenv/versions/1.9.3-p194-perf/include/ruby-1.9.1 -I. -I'/Users/tobi/.rbenv/versions/1.9.3-p194-perf/include' -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I'/Users/tobi/.rbenv/versions/1.9.3-p194-perf/include' -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -pipe conftest.c -L. -L/Users/tobi/.rbenv/versions/1.9.3-p194-perf/lib -L. -L'/Users/tobi/.rbenv/versions/1.9.3-p194-perf/lib' -L/usr/local/lib -lruby-static -lc -lpthread -ldl -lobjc "
|
||||
checked program was:
|
||||
/* begin */
|
||||
1: #include "ruby.h"
|
||||
2:
|
||||
3: /*top*/
|
||||
4: int main() {return 0;}
|
||||
5: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
|
||||
/* end */
|
||||
|
||||
--------------------
|
||||
|
||||
Reference in New Issue
Block a user