Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,25 @@ pkg/*

# Templated Files
ext/herb/error_helpers.c
ext/herb/parser_options_helpers.c
ext/herb/parser_options_helpers.h
ext/herb/error_helpers.h
ext/herb/nodes.c
ext/herb/nodes.h
java/error_helpers.c
java/parser_options_helpers.c
java/parser_options_helpers.h
java/error_helpers.h
java/nodes.c
java/nodes.h
java/org/herb/ast/Errors.java
java/org/herb/ParserOptions.java
java/org/herb/ast/Nodes.java
java/org/herb/ast/NodeVisitor.java
java/org/herb/ast/HelperRegistry.java
java/org/herb/ast/Visitor.java
javascript/packages/core/src/action-view-helpers.ts
javascript/packages/core/src/parser-options.ts
javascript/packages/core/src/errors.ts
javascript/packages/core/src/html-entities.json
javascript/packages/core/src/node-type-guards.ts
Expand All @@ -117,11 +123,13 @@ javascript/packages/node/extension/nodes.h
lib/herb/action_view/helper_registry.rb
lib/herb/ast/nodes.rb
lib/herb/errors.rb
lib/herb/parser_options.rb
lib/herb/visitor.rb
rust/src/action_view_helpers.rs
rust/src/ast/nodes.rs
rust/src/config.rs
rust/src/errors.rs
rust/src/parser_options.rs
rust/src/nodes.rs
rust/src/union_types.rs
rust/src/visitor.rs
Expand All @@ -135,17 +143,21 @@ src/analyze/transform.c
src/ast/ast_nodes.c
src/ast/ast_pretty_print.c
src/errors.c
src/parser_options_defaults.c
src/include/analyze/action_view/helper_registry.h
src/include/ast/ast_nodes.h
src/include/ast/ast_pretty_print.h
src/include/errors.h
src/include/parser/parser_options.h
src/include/lib/hb_foreach.h
src/parser/match_tags.c
src/diff/herb_diff_helpers.c
src/diff/herb_diff_nodes.c
src/diff/herb_hash_tree.c
src/visitor.c
wasm/error_helpers.cpp
wasm/parser_options_helpers.cpp
wasm/parser_options_helpers.h
wasm/error_helpers.h
wasm/nodes.cpp
wasm/nodes.h
Expand Down
92 changes: 92 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,98 @@ warnings:
fields: []
types: []

parser_options:
fields:
- name: track_whitespace
type: boolean
default: false
description: "Whether to track whitespace tokens during parsing."

- name: analyze
type: boolean
default: true
description: "Whether analysis is performed during parsing."

- name: strict
type: boolean
default: true
description: "Whether strict mode is enabled during parsing."

- name: action_view_helpers
type: boolean
default: false
description: "Whether ActionView tag helper transformation is enabled during parsing."

- name: transform_conditionals
type: boolean
default: false
description: "Whether postfix conditional transformation is enabled during parsing."

- name: render_nodes
type: boolean
default: false
description: "Whether ActionView render call detection is enabled during parsing."

- name: strict_locals
type: boolean
default: false
description: "Whether strict locals analysis is enabled during parsing."

- name: prism_program
type: boolean
default: false
description: "Whether the full Prism ProgramNode is serialized on the DocumentNode."

- name: prism_nodes
type: boolean
default: false
description: "Whether Prism node serialization is enabled during parsing."

- name: prism_nodes_deep
type: boolean
default: false
description: "Whether deep Prism node serialization is enabled during parsing."

- name: dot_notation_tags
type: boolean
default: false
description: "Whether dot-notation component tags (e.g. Dialog.Button) are parsed as HTML elements."

- name: html
type: boolean
default: true
description: "Whether HTML tag parsing is enabled. When false, HTML-like content is treated as literal text."

- name: timeout
type: uint32
c_name: timeout_ms
default_ms: 1000
ruby_unit: seconds
description: "Parse timeout."

- name: max_errors
type: uint32
default: 25
nullable: true
null_sentinel: 0
description: "Maximum number of errors to report. nil/null means unlimited."

internal_fields:
- name: start_line
type: uint32
default: 0

- name: start_column
type: uint32
default: 0

- name: error_count
type: pointer_uint32

- name: deadline_ms
type: uint64
default: 0

nodes:
# fields:
# - name: type
Expand Down
3 changes: 2 additions & 1 deletion ext/herb/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
"extension.c",
"nodes.c",
"error_helpers.c",
"extension_helpers.c"
"extension_helpers.c",
"parser_options_helpers.c"
]

$srcs = core_src_files + herb_src_files + prism_main_files + prism_util_files
Expand Down
73 changes: 2 additions & 71 deletions ext/herb/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "extension.h"
#include "extension_helpers.h"
#include "nodes.h"
#include "parser_options_helpers.h"

VALUE mHerb;
VALUE cPosition;
Expand Down Expand Up @@ -116,79 +117,9 @@ static VALUE Herb_parse(int argc, VALUE* argv, VALUE self) {
bool print_arena_stats = false;

parser_options_T parser_options = HERB_DEFAULT_PARSER_OPTIONS;
herb_extract_parser_options(options, &parser_options);

if (!NIL_P(options)) {
VALUE track_whitespace = rb_hash_lookup(options, rb_utf8_str_new_cstr("track_whitespace"));
if (NIL_P(track_whitespace)) { track_whitespace = rb_hash_lookup(options, ID2SYM(rb_intern("track_whitespace"))); }
if (!NIL_P(track_whitespace) && RTEST(track_whitespace)) { parser_options.track_whitespace = true; }

VALUE analyze = rb_hash_lookup(options, rb_utf8_str_new_cstr("analyze"));
if (NIL_P(analyze)) { analyze = rb_hash_lookup(options, ID2SYM(rb_intern("analyze"))); }
if (!NIL_P(analyze) && !RTEST(analyze)) { parser_options.analyze = false; }

VALUE strict = rb_hash_lookup(options, rb_utf8_str_new_cstr("strict"));
if (NIL_P(strict)) { strict = rb_hash_lookup(options, ID2SYM(rb_intern("strict"))); }
if (!NIL_P(strict)) { parser_options.strict = RTEST(strict); }

VALUE action_view_helpers = rb_hash_lookup(options, rb_utf8_str_new_cstr("action_view_helpers"));
if (NIL_P(action_view_helpers)) {
action_view_helpers = rb_hash_lookup(options, ID2SYM(rb_intern("action_view_helpers")));
}
if (!NIL_P(action_view_helpers) && RTEST(action_view_helpers)) { parser_options.action_view_helpers = true; }

VALUE transform_conditionals = rb_hash_lookup(options, rb_utf8_str_new_cstr("transform_conditionals"));
if (NIL_P(transform_conditionals)) {
transform_conditionals = rb_hash_lookup(options, ID2SYM(rb_intern("transform_conditionals")));
}
if (!NIL_P(transform_conditionals) && RTEST(transform_conditionals)) {
parser_options.transform_conditionals = true;
}

VALUE dot_notation_tags = rb_hash_lookup(options, rb_utf8_str_new_cstr("dot_notation_tags"));
if (NIL_P(dot_notation_tags)) {
dot_notation_tags = rb_hash_lookup(options, ID2SYM(rb_intern("dot_notation_tags")));
}
if (!NIL_P(dot_notation_tags) && RTEST(dot_notation_tags)) { parser_options.dot_notation_tags = true; }

VALUE render_nodes = rb_hash_lookup(options, rb_utf8_str_new_cstr("render_nodes"));
if (NIL_P(render_nodes)) { render_nodes = rb_hash_lookup(options, ID2SYM(rb_intern("render_nodes"))); }
if (!NIL_P(render_nodes) && RTEST(render_nodes)) { parser_options.render_nodes = true; }

VALUE strict_locals = rb_hash_lookup(options, rb_utf8_str_new_cstr("strict_locals"));
if (NIL_P(strict_locals)) { strict_locals = rb_hash_lookup(options, ID2SYM(rb_intern("strict_locals"))); }
if (!NIL_P(strict_locals) && RTEST(strict_locals)) { parser_options.strict_locals = true; }

VALUE prism_nodes = rb_hash_lookup(options, rb_utf8_str_new_cstr("prism_nodes"));
if (NIL_P(prism_nodes)) { prism_nodes = rb_hash_lookup(options, ID2SYM(rb_intern("prism_nodes"))); }
if (!NIL_P(prism_nodes) && RTEST(prism_nodes)) { parser_options.prism_nodes = true; }

VALUE prism_nodes_deep = rb_hash_lookup(options, rb_utf8_str_new_cstr("prism_nodes_deep"));
if (NIL_P(prism_nodes_deep)) { prism_nodes_deep = rb_hash_lookup(options, ID2SYM(rb_intern("prism_nodes_deep"))); }
if (!NIL_P(prism_nodes_deep) && RTEST(prism_nodes_deep)) { parser_options.prism_nodes_deep = true; }

VALUE prism_program = rb_hash_lookup(options, rb_utf8_str_new_cstr("prism_program"));
if (NIL_P(prism_program)) { prism_program = rb_hash_lookup(options, ID2SYM(rb_intern("prism_program"))); }
if (!NIL_P(prism_program) && RTEST(prism_program)) { parser_options.prism_program = true; }

VALUE html = rb_hash_lookup(options, rb_utf8_str_new_cstr("html"));
if (NIL_P(html)) { html = rb_hash_lookup(options, ID2SYM(rb_intern("html"))); }
if (!NIL_P(html) && !RTEST(html)) { parser_options.html = false; }

VALUE timeout = rb_hash_lookup(options, rb_utf8_str_new_cstr("timeout"));
if (NIL_P(timeout)) { timeout = rb_hash_lookup(options, ID2SYM(rb_intern("timeout"))); }
if (!NIL_P(timeout)) { parser_options.timeout_ms = (uint32_t) (NUM2DBL(timeout) * 1000); }

VALUE max_errors_sentinel = ID2SYM(rb_intern("__not_set__"));
VALUE max_errors = rb_hash_lookup2(options, rb_utf8_str_new_cstr("max_errors"), max_errors_sentinel);

if (max_errors == max_errors_sentinel) {
max_errors = rb_hash_lookup2(options, ID2SYM(rb_intern("max_errors")), max_errors_sentinel);
}

if (max_errors != max_errors_sentinel) {
parser_options.max_errors = NIL_P(max_errors) ? 0 : (uint32_t) NUM2UINT(max_errors);
}

VALUE arena_stats = rb_hash_lookup(options, rb_utf8_str_new_cstr("arena_stats"));
if (NIL_P(arena_stats)) { arena_stats = rb_hash_lookup(options, ID2SYM(rb_intern("arena_stats"))); }
if (!NIL_P(arena_stats) && RTEST(arena_stats)) { print_arena_stats = true; }
Expand Down
21 changes: 2 additions & 19 deletions ext/herb/extension_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "extension.h"
#include "extension_helpers.h"
#include "nodes.h"
#include "parser_options_helpers.h"

#include "../../src/include/herb.h"
#include "../../src/include/lexer/token.h"
Expand Down Expand Up @@ -83,25 +84,7 @@ VALUE create_parse_result(AST_DOCUMENT_NODE_T* root, VALUE source, const parser_
VALUE value = rb_node_from_c_struct((AST_NODE_T*) root);
VALUE warnings = rb_ary_new();
VALUE errors = rb_ary_new();

VALUE kwargs = rb_hash_new();
rb_hash_aset(kwargs, ID2SYM(rb_intern("strict")), options->strict ? Qtrue : Qfalse);
rb_hash_aset(kwargs, ID2SYM(rb_intern("track_whitespace")), options->track_whitespace ? Qtrue : Qfalse);
rb_hash_aset(kwargs, ID2SYM(rb_intern("analyze")), options->analyze ? Qtrue : Qfalse);
rb_hash_aset(kwargs, ID2SYM(rb_intern("action_view_helpers")), options->action_view_helpers ? Qtrue : Qfalse);
rb_hash_aset(kwargs, ID2SYM(rb_intern("transform_conditionals")), options->transform_conditionals ? Qtrue : Qfalse);
rb_hash_aset(kwargs, ID2SYM(rb_intern("render_nodes")), options->render_nodes ? Qtrue : Qfalse);
rb_hash_aset(kwargs, ID2SYM(rb_intern("strict_locals")), options->strict_locals ? Qtrue : Qfalse);
rb_hash_aset(kwargs, ID2SYM(rb_intern("prism_nodes")), options->prism_nodes ? Qtrue : Qfalse);
rb_hash_aset(kwargs, ID2SYM(rb_intern("prism_nodes_deep")), options->prism_nodes_deep ? Qtrue : Qfalse);
rb_hash_aset(kwargs, ID2SYM(rb_intern("prism_program")), options->prism_program ? Qtrue : Qfalse);
rb_hash_aset(kwargs, ID2SYM(rb_intern("timeout")), DBL2NUM((double) options->timeout_ms / 1000.0));

rb_hash_aset(
kwargs,
ID2SYM(rb_intern("max_errors")),
options->max_errors == 0 ? Qnil : UINT2NUM(options->max_errors)
);
VALUE kwargs = herb_build_parser_options_hash(options);

VALUE parser_options_args[1] = { kwargs };
VALUE parser_options = rb_class_new_instance_kw(1, parser_options_args, cParserOptions, RB_PASS_KEYWORDS);
Expand Down
2 changes: 1 addition & 1 deletion java/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ HERB_SOURCES = $(shell find $(SRC_DIR) -name '*.c')
HERB_OBJECTS = $(filter-out $(SRC_DIR)/main.o, $(HERB_SOURCES:.c=.o))

JNI_SOURCES = herb_jni.c extension_helpers.c
JNI_GENERATED_SOURCES = nodes.c error_helpers.c
JNI_GENERATED_SOURCES = nodes.c error_helpers.c parser_options_helpers.c

JNI_OBJECTS = $(JNI_SOURCES:.c=.o) $(JNI_GENERATED_SOURCES:.c=.o)

Expand Down
Loading
Loading