Compute transitions for regex pattern rules
This commit is contained in:
parent
040ec86000
commit
ecd317ccd9
13 changed files with 206 additions and 23 deletions
63
spec/rules/pattern_spec.cpp
Normal file
63
spec/rules/pattern_spec.cpp
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#include "spec_helper.h"
|
||||
#include "rules.h"
|
||||
#include "transition_map.h"
|
||||
|
||||
using namespace tree_sitter::rules;
|
||||
|
||||
Describe(pattern_rules) {
|
||||
It(parses_simple_strings) {
|
||||
pattern_ptr rule = pattern("abc");
|
||||
AssertThat(
|
||||
rule->to_rule_tree()->to_string(),
|
||||
Equals(seq({
|
||||
character('a'),
|
||||
character('b'),
|
||||
character('c')
|
||||
})->to_string()));
|
||||
};
|
||||
|
||||
It(parses_choices) {
|
||||
pattern_ptr rule = pattern("ab|cd|ef");
|
||||
AssertThat(
|
||||
rule->to_rule_tree()->to_string(),
|
||||
Equals(choice({
|
||||
seq({
|
||||
character('a'),
|
||||
character('b'),
|
||||
}),
|
||||
seq({
|
||||
character('c'),
|
||||
character('d')
|
||||
}),
|
||||
seq({
|
||||
character('e'),
|
||||
character('f')
|
||||
})
|
||||
})->to_string()));
|
||||
};
|
||||
|
||||
It(parses_choices_in_sequences) {
|
||||
pattern_ptr rule = pattern("(a|b)cd");
|
||||
AssertThat(
|
||||
rule->to_rule_tree()->to_string(),
|
||||
Equals(seq({
|
||||
choice({
|
||||
character('a'),
|
||||
character('b'),
|
||||
}),
|
||||
character('c'),
|
||||
character('d')
|
||||
})->to_string()));
|
||||
};
|
||||
|
||||
It(parses_special_characters_when_they_are_escaped) {
|
||||
pattern_ptr rule = pattern("a\\(b");
|
||||
AssertThat(
|
||||
rule->to_rule_tree()->to_string(),
|
||||
Equals(seq({
|
||||
character('a'),
|
||||
character('('),
|
||||
character('b')
|
||||
})->to_string()));
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue