From bdd04f4d5c393d4ae0dcb1fdb23b1a747b08e8d8 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 16 Sep 2023 14:06:31 -0400 Subject: [PATCH] Do not allow '<' as a pre-character for text-markup but do allow start of file. --- scripts/run_docker_compare.bash | 56 +++++++++++++++++++++++---------- src/parser/text_markup.rs | 29 ++++++++--------- 2 files changed, 54 insertions(+), 31 deletions(-) diff --git a/scripts/run_docker_compare.bash b/scripts/run_docker_compare.bash index 6c331449..428e23e1 100755 --- a/scripts/run_docker_compare.bash +++ b/scripts/run_docker_compare.bash @@ -12,6 +12,21 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" REALPATH=$(command -v uu-realpath || command -v realpath) MAKE=$(command -v gmake || command -v make) +############## Setup ######################### + +function die { + local status_code="$1" + shift + (>&2 echo "${@}") + exit "$status_code" +} + +function log { + (>&2 echo "${@}") +} + +############## Program ######################### + function main { build_container launch_container "${@}" @@ -23,7 +38,6 @@ function build_container { function launch_container { local additional_flags=() - local additional_args=() local features=(compare) if [ "$NO_COLOR" != "" ]; then @@ -37,12 +51,8 @@ function launch_container { fi if [ "$SHELL" != "YES" ]; then - local features_joined - features_joined=$(IFS=","; echo "${features[*]}") - additional_args+=(cargo build --bin compare --no-default-features --features "$features_joined") additional_flags+=(--read-only) else - additional_args+=(/bin/sh) additional_flags+=(-t) fi @@ -50,31 +60,43 @@ function launch_container { additional_flags+=(--env RUST_BACKTRACE=full) fi + if [ "$SHELL" = "YES" ]; then + exec docker run "${additional_flags[@]}" --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -v "$($REALPATH "$DIR/../"):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source --entrypoint "" organic-test /bin/sh + fi + + local features_joined + features_joined=$(IFS=","; echo "${features[*]}") + if [ $# -gt 0 ]; then # If we passed in args, we need to forward them along for path in "${@}"; do local full_path full_path=$($REALPATH "$path") - docker run "${additional_flags[@]}" --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -v "$($REALPATH "$DIR/../"):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source --entrypoint "" organic-test "${additional_args[@]}" -- "/input${full_path}" - done - else - if [ "$SHELL" != "YES" ]; then - local current_directory init_script - current_directory=$(pwd) init_script=$(cat <( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Bold<'s>> { - let text_markup_object_specialized = text_markup_object("*"); - let (remaining, children) = text_markup_object_specialized(context, input)?; + let (remaining, children) = text_markup_object("*")(context, input)?; let source = get_consumed(input, remaining); Ok(( remaining, @@ -81,8 +81,7 @@ fn italic<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Italic<'s>> { - let text_markup_object_specialized = text_markup_object("/"); - let (remaining, children) = text_markup_object_specialized(context, input)?; + let (remaining, children) = text_markup_object("/")(context, input)?; let source = get_consumed(input, remaining); Ok(( remaining, @@ -98,8 +97,7 @@ fn underline<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Underline<'s>> { - let text_markup_object_specialized = text_markup_object("_"); - let (remaining, children) = text_markup_object_specialized(context, input)?; + let (remaining, children) = text_markup_object("_")(context, input)?; let source = get_consumed(input, remaining); Ok(( remaining, @@ -115,8 +113,7 @@ fn strike_through<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, StrikeThrough<'s>> { - let text_markup_object_specialized = text_markup_object("+"); - let (remaining, children) = text_markup_object_specialized(context, input)?; + let (remaining, children) = text_markup_object("+")(context, input)?; let source = get_consumed(input, remaining); Ok(( remaining, @@ -132,8 +129,7 @@ fn verbatim<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Verbatim<'s>> { - let text_markup_string_specialized = text_markup_string("="); - let (remaining, contents) = text_markup_string_specialized(context, input)?; + let (remaining, contents) = text_markup_string("=")(context, input)?; let source = get_consumed(input, remaining); Ok(( remaining, @@ -149,8 +145,7 @@ fn code<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Code<'s>> { - let text_markup_string_specialized = text_markup_string("~"); - let (remaining, contents) = text_markup_string_specialized(context, input)?; + let (remaining, contents) = text_markup_string("~")(context, input)?; let source = get_consumed(input, remaining); Ok(( remaining, @@ -292,16 +287,22 @@ fn pre<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> { + if start_of_line(input).is_ok() { + return Ok((input, ())); + } + if preceded_by_whitespace(true)(input).is_ok() { + return Ok((input, ())); + } let preceding_character = input.get_preceding_character(); match preceding_character { // If None, we are at the start of the file which is technically the beginning of a line. - None | Some('\r') | Some('\n') | Some(' ') | Some('\t') | Some('-') | Some('(') - | Some('{') | Some('\'') | Some('"') | Some('<') => {} + Some('-') | Some('(') | Some('{') | Some('\'') | Some('"') => {} Some(_) => { return Err(nom::Err::Error(CustomError::MyError(MyError( "Not a valid pre character for text markup.".into(), )))); } + None => unreachable!(), // None is for start of file, which should already be handled by the start_of_line matcher above. }; Ok((input, ())) }