Skip to content

Commit

Permalink
simplify parser
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Jan 1, 2025
1 parent 3ab54e8 commit 21f1779
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/ada/url_pattern_helpers-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ parse_pattern_string(std::string_view input,
parser.tokens = std::move(*tokenize_result);

// While parser’s index is less than parser’s token list's size:
while (parser.index < parser.tokens.size()) {
while (parser.can_continue()) {
// Let char token be the result of running try to consume a token given
// parser and "char".
auto char_token = parser.try_consume_token(token_type::CHAR);
Expand Down
8 changes: 5 additions & 3 deletions include/ada/url_pattern_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class url_pattern_parser {
url_pattern_parser(F& encoding_callback_,
std::string_view segment_wildcard_regexp_)
: encoding_callback(encoding_callback_),
segment_wildcard_regexp(std::string(segment_wildcard_regexp_)) {}
segment_wildcard_regexp(segment_wildcard_regexp_) {}

bool can_continue() const { return index < tokens.size(); }

// @see https://urlpattern.spec.whatwg.org/#try-to-consume-a-token
Token* try_consume_token(token_type type);
Expand Down Expand Up @@ -123,9 +125,9 @@ class Tokenizer {
size_t next_position, size_t value_position) ada_warn_unused;

// has an associated input, a pattern string, initially the empty string.
std::string input{};
std::string input;
// has an associated policy, a tokenize policy, initially "strict".
token_policy policy = token_policy::STRICT;
token_policy policy;
// has an associated token list, a token list, initially an empty list.
std::vector<Token> token_list{};
// has an associated index, a number, initially 0.
Expand Down

0 comments on commit 21f1779

Please sign in to comment.