Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-line string #31

Open
ypyl opened this issue Jan 4, 2023 · 5 comments · May be fixed by #36
Open

Multi-line string #31

ypyl opened this issue Jan 4, 2023 · 5 comments · May be fixed by #36
Labels

Comments

@ypyl
Copy link

ypyl commented Jan 4, 2023

it seems the parser converts multiline string to simple string, e.g.

description: |
  Some information

will be saved internally as

description: | Some description

My assumption is that it should be like

description: |\n  Some description
@RDBModel
Copy link

RDBModel commented Aug 3, 2023

I was able to add such support by modifying multilineStep and postProcessString in Util.elm file:

multilineStep : Int -> List String -> P.Parser (P.Step (List String) String)
multilineStep indent lines =
    let
        multilineString : List String -> String
        multilineString lines_ =
            String.join "\n" (List.reverse lines_)

        conclusion line indent_ =
            let
                intendedLine =
                    if List.isEmpty lines then
                        line
                    else
                        String.repeat (indent + 1) " " ++ line
            in
            if indent_ > indent then
                P.Loop (intendedLine :: lines)

            else
                P.Done (multilineString (intendedLine :: lines))
    in
    P.oneOf
        [ P.succeed conclusion
            |= characters (not << isNewLine)
            |. P.chompIf isNewLine
            |. spaces
            |= P.getCol
        , P.succeed (P.Done <| multilineString lines)
        ]
postProcessString : String -> String
postProcessString str =
  -- let
  --     regexFromString : String -> Regex
  --     regexFromString =
  --         Regex.fromString >> Maybe.withDefault Regex.never
  -- in
  str
      -- |> Regex.replace (regexFromString "\\s\\s+")
      --     (\match ->
      --         if String.contains "\n\n" match.match then
      --             "\n"

      --         else
      --             " "
      --     )

@RDBModel
Copy link

RDBModel commented Aug 7, 2023

I will be happy to prepare PR if my change makes sense.
As I am basically removing postProcessString and I am not sure that it is correct.

@MaybeJustJames
Copy link
Owner

If it passes the tests then I'm happy to accept it

@RDBModel
Copy link

RDBModel commented Aug 7, 2023

I need some time to understand how to write/run and check unit tests in Elm.
As for Elm, unfortunately I am following the next principle at least for now:
image

@lovebug356
Copy link

An improvement has been proposed in #36 to parse literal multi-line strings, with tests ;-).

@MaybeJustJames MaybeJustJames linked a pull request Feb 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants