Skip to content

Commit 449da34

Browse files
committed
Parser: Analyze and transform ActionView helpers
1 parent 000dbff commit 449da34

File tree

150 files changed

+7126
-358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+7126
-358
lines changed

.clang-format-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ src/errors.c
88
src/include/ast_nodes.h
99
src/include/ast_pretty_print.h
1010
src/include/errors.h
11+
src/include/util/hb_foreach.h
1112
src/parser_match_tags.c
1213
src/visitor.c

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
exec = herb
22
test_exec = run_herb_tests
33

4-
sources = $(wildcard src/*.c) $(wildcard src/**/*.c)
5-
headers = $(wildcard src/*.h) $(wildcard src/**/*.h)
4+
sources = $(shell find src -name '*.c')
5+
headers = $(shell find src -name '*.h')
66
objects = $(sources:.c=.o)
77

88
extension_sources = $(wildcard ext/**/*.c)

config.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,19 @@ nodes:
426426
- name: tag_name
427427
type: token
428428
429+
- name: HTMLVirtualCloseTagNode
430+
fields:
431+
- name: tag_name
432+
type: token
433+
429434
- name: HTMLElementNode
430435
fields:
431436
- name: open_tag
432437
type: node
433438
kind:
434439
- HTMLOpenTagNode
435440
- HTMLConditionalOpenTagNode
441+
- ERBOpenTagNode
436442
437443
- name: tag_name
438444
type: token
@@ -446,6 +452,7 @@ nodes:
446452
kind:
447453
- HTMLCloseTagNode
448454
- HTMLOmittedCloseTagNode
455+
- HTMLVirtualCloseTagNode
449456
450457
- name: is_void
451458
type: boolean
@@ -526,6 +533,37 @@ nodes:
526533
type: node
527534
kind: HTMLAttributeValueNode
528535
536+
- name: RubyLiteralNode
537+
fields:
538+
- name: content
539+
type: string
540+
541+
- name: RubyHTMLAttributesSplatNode
542+
fields:
543+
- name: content
544+
type: string
545+
546+
- name: prefix
547+
type: string
548+
549+
- name: ERBOpenTagNode
550+
fields:
551+
- name: tag_opening
552+
type: token
553+
554+
- name: content
555+
type: token
556+
557+
- name: tag_closing
558+
type: token
559+
560+
- name: tag_name
561+
type: token
562+
563+
- name: children
564+
type: array
565+
kind: Node
566+
529567
- name: HTMLTextNode
530568
fields:
531569
- name: content

ext/herb/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
$VPATH << "$(srcdir)/../../src"
1414
$VPATH << "$(srcdir)/../../src/analyze"
15+
$VPATH << "$(srcdir)/../../src/analyze/action_view"
1516
$VPATH << "$(srcdir)/../../src/util"
1617
$VPATH << prism_src_path
1718
$VPATH << "#{prism_src_path}/util"

ext/herb/extension.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ static VALUE Herb_parse(int argc, VALUE* argv, VALUE self) {
130130
if (NIL_P(strict)) { strict = rb_hash_lookup(options, ID2SYM(rb_intern("strict"))); }
131131
if (!NIL_P(strict)) { parser_options.strict = RTEST(strict); }
132132

133+
VALUE action_view_helpers = rb_hash_lookup(options, rb_utf8_str_new_cstr("action_view_helpers"));
134+
if (NIL_P(action_view_helpers)) {
135+
action_view_helpers = rb_hash_lookup(options, ID2SYM(rb_intern("action_view_helpers")));
136+
}
137+
if (!NIL_P(action_view_helpers) && RTEST(action_view_helpers)) { parser_options.action_view_helpers = true; }
138+
133139
VALUE arena_stats = rb_hash_lookup(options, rb_utf8_str_new_cstr("arena_stats"));
134140
if (NIL_P(arena_stats)) { arena_stats = rb_hash_lookup(options, ID2SYM(rb_intern("arena_stats"))); }
135141
if (!NIL_P(arena_stats) && RTEST(arena_stats)) { print_arena_stats = true; }

ext/herb/extension_helpers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ VALUE create_parse_result(AST_DOCUMENT_NODE_T* root, VALUE source, const parser_
8888
rb_hash_aset(kwargs, ID2SYM(rb_intern("strict")), options->strict ? Qtrue : Qfalse);
8989
rb_hash_aset(kwargs, ID2SYM(rb_intern("track_whitespace")), options->track_whitespace ? Qtrue : Qfalse);
9090
rb_hash_aset(kwargs, ID2SYM(rb_intern("analyze")), options->analyze ? Qtrue : Qfalse);
91+
rb_hash_aset(kwargs, ID2SYM(rb_intern("action_view_helpers")), options->action_view_helpers ? Qtrue : Qfalse);
9192

9293
VALUE parser_options_args[1] = { kwargs };
9394
VALUE parser_options = rb_class_new_instance_kw(1, parser_options_args, cParserOptions, RB_PASS_KEYWORDS);

java/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ INCLUDES = -I. -I$(SRC_DIR)/include -I$(PRISM_INCLUDE) $(JNI_INCLUDES)
3535
LDFLAGS = -shared
3636
LIBS = $(PRISM_BUILD)/libprism.a
3737

38-
HERB_SOURCES = $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/**/*.c)
38+
HERB_SOURCES = $(shell find $(SRC_DIR) -name '*.c')
3939
HERB_OBJECTS = $(filter-out $(SRC_DIR)/main.o, $(HERB_SOURCES:.c=.o))
4040

4141
JNI_SOURCES = herb_jni.c extension_helpers.c

java/herb_jni.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ Java_org_herb_Herb_parse(JNIEnv* env, jclass clazz, jstring source, jobject opti
6060
jboolean strict = (*env)->CallBooleanMethod(env, options, getStrict);
6161
parser_options.strict = (strict == JNI_TRUE);
6262
}
63+
64+
jmethodID getActionViewHelpers =
65+
(*env)->GetMethodID(env, optionsClass, "isActionViewHelpers", "()Z");
66+
67+
if (getActionViewHelpers != NULL) {
68+
jboolean actionViewHelpers = (*env)->CallBooleanMethod(env, options, getActionViewHelpers);
69+
parser_options.action_view_helpers = (actionViewHelpers == JNI_TRUE);
70+
}
6371
}
6472

6573
hb_allocator_T allocator;

java/org/herb/ParserOptions.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class ParserOptions {
44
private boolean trackWhitespace = false;
55
private boolean analyze = true;
66
private boolean strict = true;
7+
private boolean actionViewHelpers = false;
78

89
public ParserOptions() {}
910

@@ -34,6 +35,15 @@ public boolean isStrict() {
3435
return strict;
3536
}
3637

38+
public ParserOptions actionViewHelpers(boolean value) {
39+
this.actionViewHelpers = value;
40+
return this;
41+
}
42+
43+
public boolean isActionViewHelpers() {
44+
return actionViewHelpers;
45+
}
46+
3747
public static ParserOptions create() {
3848
return new ParserOptions();
3949
}

java/snapshots/snapshot_tests/testParse.txt

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)