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

Add support for new lines in Sequence #40

Conversation

tg-m
Copy link
Contributor

@tg-m tg-m commented Jun 7, 2022

When using diagon Sequence it is not possible (at least I couldn't
find a way) to add new lines to the messages in the Sequence submodule.

This patch adds parameter --new_lines_at_bsn that results in
substituting literal \n with new lines.

Example:

$ echo "Alice -> Bob: send(\n  msg="Hello...",\n  length=8,\n)" | \
       diagon Sequence --new_lines_at_bsn=true

output:

┌─────┐          ┌───┐
│Alice│          │Bob│
└──┬──┘          └─┬─┘
   │               │
   │send(          │
   │  msg=Hello...,│
   │  length=8,    │
   │)              │
   │──────────────>│
┌──┴──┐          ┌─┴─┐
│Alice│          │Bob│
└─────┘          └───┘

When using `diagon Sequence` it is not possible (at least I couldn't
find a way) to add new lines to the messages in the Sequence submodule.

This patch adds parameter `--new_lines_at_bsn` that results in
substituting literal `\n` with new lines.

Example:

```bash
$ echo "Alice -> Bob: send(\n  msg="Hello...",\n  length=8,\n)" | \
       diagon Sequence --new_lines_at_bsn=true
```

output:
```
┌─────┐          ┌───┐
│Alice│          │Bob│
└──┬──┘          └─┬─┘
   │               │
   │send(          │
   │  msg=Hello...,│
   │  length=8,    │
   │)              │
   │──────────────>│
┌──┴──┐          ┌─┴─┐
│Alice│          │Bob│
└─────┘          └───┘
```
@ArthurSonzogni
Copy link
Owner

Thanks!

Please let me some time to review this patch. I believe this is a good thing to add.

@ArthurSonzogni ArthurSonzogni merged commit 3a1dfe8 into ArthurSonzogni:master Jun 7, 2022
@ArthurSonzogni
Copy link
Owner

Thank you!

I am also thinking about an alternative syntax:

A->B: |
  This is
  a multiline string

similar to YAML: https://yaml-multiline.info/

@tg-m
Copy link
Contributor Author

tg-m commented Jun 7, 2022

TBH, my first impression was to abandon the custom grammar and switch to YAML, but I needed multi-line support quite fast, thus the patch.

Also... I think there is an issue with the Sequence grammar definition. It does not handle colons (:) in message text / label correctly.

YAML will give far more flexibility, but it's somewhat verbose... I had something like below in my mind, when I was looking at the grammar.

Basic

nodes: 
  - &ref_alice
    name: Alice
  - &ref_bob
    name: Bob
  - &ref_charlie
    name: Charlie
messages:
  - from: *ref_alice
    to: *ref_bob
    label: "Hello Alice! It's me, Bob."
  - from: *ref_bob
    to: *ref_charlie
    label: |-
      A label with...
      Not only one or two lines.
      Not even three!
      But four! :)

More detailed

options:
  message-arrow-ending: triangle
  node-style:
    - name
    - label
nodes: 
  - &ref_alice
    label: "Alice node"
    name: A
    rotate: 90
  - &ref_bob
    label: "Bob"
    name: B
  - &ref_charlie
    label: "Charlie"
    name: C
    node-style:
      - label
messages:
  - from: *ref_alice
    to: *ref_bob
    label: "Hello Alice! It's me, Bob."
    align: left
    order: 11
    message-arrow-ending: square ## custom arrow ending
  - from: *ref_bob
    to: *ref_charlie
    label: |-
      A label with...
      Not only one or two lines.
      Not even three!
      But four! :)
    align: centre ## or center for US speakers ;)
    order: 2
    ## message-arrow-ending: triangle ## defaults to what is in options

@ArthurSonzogni
Copy link
Owner

Sorry, I didn't meant switching toward yaml. I just meant updating the syntax, so that we can use something similar to YAML multiline strings.

@tg-m
Copy link
Contributor Author

tg-m commented Jun 8, 2022

Yes, I was aware of that. After a little bit of sleep, I think that your grammar is more concise than YAML, thus better in this case.

It would be nice to have support for |, |- and |+ variants of YAML's |. See, e.g., https://yaml-multiline.info/. (Added: Oh, you've already pasted that link, I missed that...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants