summaryrefslogtreecommitdiff
path: root/syntax.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-11 14:19:38 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-11 14:50:02 -0500
commitaaebf30ccd75ba27ec55bc45ed886cdae2ca58ef (patch)
tree7dc6e7c752dacdd916a96f304fa51edd61db0cb0 /syntax.c
parent90b4b08717730733402df25190bba0cc5d2fd952 (diff)
highlight matching parentheses
Diffstat (limited to 'syntax.c')
-rw-r--r--syntax.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/syntax.c b/syntax.c
index 01e6b7d..26ce234 100644
--- a/syntax.c
+++ b/syntax.c
@@ -45,6 +45,32 @@ static inline bool syntax_keyword_matches(char32_t *text, size_t len, char const
}
}
+// returns ')' for '(', etc., or 0 if c is not an opening bracket
+char32_t syntax_matching_bracket(Language lang, char32_t c) {
+ (void)lang; // not needed yet
+ switch (c) {
+ case '(': return ')';
+ case ')': return '(';
+ case '[': return ']';
+ case ']': return '[';
+ case '{': return '}';
+ case '}': return '{';
+ }
+ return 0;
+}
+
+// returns true for opening brackets, false for closing brackets/non-brackets
+bool syntax_is_opening_bracket(Language lang, char32_t c) {
+ (void)lang;
+ switch (c) {
+ case '(':
+ case '[':
+ case '{':
+ return true;
+ }
+ return false;
+}
+
// lookup the given string in the keywords table
static Keyword const *syntax_keyword_lookup(Keyword const *const *all_keywords, size_t n_all_keywords, char32_t *str, size_t len) {
if (!len) return NULL;