simple-learning

Simple learning web program
git clone git://git.laack.co/simple-learning.git
Log | Files | Refs | README | LICENSE

commit 3f6916200789da0768d3adccc15601efd872f4ba
parent 8569c911e3fa48df91a5b088066efe281a24ce24
Author: Andrew Laack <andrew@laack.co>
Date:   Sun,  6 Sep 2026 10:35:32 -0500

Match on prefixes for most line types

Diffstat:
Mlearning/lib/parser.ml | 46+++++-----------------------------------------
Mlearning/lib/shared.ml | 3+++
2 files changed, 8 insertions(+), 41 deletions(-)

diff --git a/learning/lib/parser.ml b/learning/lib/parser.ml @@ -12,7 +12,6 @@ type line_format = | Link | ListItem - (** [line_format_map format] returns a pair where the first element is the [format] as a string and the second element is the number of characters that format removes from the prefix of a line. *) let line_format_map format = match format with @@ -42,55 +41,20 @@ let permute_line line line_type = (**[is_hidden line preformatted] checks if [line] is a hidden line type. *) let is_hidden line preformatted = - if - (not preformatted) - && String.length line > 2 - && line.[0] = '?' - && line.[1] = '?' - && line.[2] = ' ' - then true - else false + ((not preformatted) && Shared.match_on_prefix line "?? ") (**[is_list line preformatted] checks if [line] is a list line type. *) let is_list line preformatted = - if - (not preformatted) - && String.length line > 1 - && line.[0] = '*' - && line.[1] = ' ' - then true - else false + ((not preformatted) && Shared.match_on_prefix line "* ") let is_quote line preformatted = - if - (not preformatted) - && String.length line > 1 - && line.[0] = '>' - && line.[1] = ' ' - then true - else false + ((not preformatted) && Shared.match_on_prefix line "> ") let is_embedded_link line preformatted = - if - (not preformatted) - && String.length line > 3 - && line.[0] = '=' - && line.[1] = '>' - && line.[2] = 'e' - && line.[3] = ' ' - then true - else false + ((not preformatted) && Shared.match_on_prefix line "=>e ") let is_link line preformatted = - if - (not preformatted) - && (not (is_embedded_link line preformatted)) - && String.length line > 2 - && line.[0] = '=' - && line.[1] = '>' - && line.[2] = ' ' - then true - else false + ((not preformatted) && Shared.match_on_prefix line "=> ") let header_count line preformatted = let count = Basic_functions.count_prefix '#' line in diff --git a/learning/lib/shared.ml b/learning/lib/shared.ml @@ -8,3 +8,6 @@ let is_file filename = if Sys.file_exists filename then true else false let is_directory path = if Sys.file_exists path then if Sys.is_directory path then true else false else false + +let match_on_prefix s prefix = + (String.length s >= String.length prefix) && (String.sub s 0 (String.length prefix) = prefix)