skanaar / nomnoml

The sassy UML diagram renderer
https://www.nomnoml.com
MIT License
2.7k stars 209 forks source link

[enhancement] Alias/nickname syntax #106

Closed stolksdorf closed 1 year ago

stolksdorf commented 5 years ago

It would be great to have a syntax for assigning a shorter alias to nodes. Sometimes I'll have very large diagrams with long node names, it makes it difficult to update each instance of the node in the structure.

example:

pum := [Progressive Utility Matrix]

[pum] -> [Hyperwave Shell]
[<actor> pum | 
  nitrogen shock; containment field
]

//Still can use the original Node name
[Progressive Utility Matrix] <-> [Tau Particle]

Any syntax can work, I don't know what would be easiest in regards to the internal parser.

I would be interested in taking a stab at this feature and making a PR. If you could let me know how do-able this is and any tips/places in code to get started, that would be great.

skanaar commented 5 years ago

It shouldn't be too hard I think. The trickiest part (for me at least) is the Jison grammar that is used to generate the parser.

I am always careful about syntax changes, since it is hard to change once it is released in the wild. In this case the syntax mustn't clash with just a plain line of text - which can appear inside a classifier.

The most straightforward way - which also could open up for other uses - would be a new macro declaration.

#--pum: Progressive Utility Matrix (inspired by css custom properties)

or

#declare-pum: Progressive Utility Matrix (inspired by C)

C macros might not have this "this was a really good idea" reputation, but it would be a less invasive change here.

stolksdorf commented 5 years ago

I was hoping a simple directive would work, but after taking a quick glance, it seems directives don't want to be multi-declared. I was hopeful looking at #import, but it looks like you do a special cli-only parse step for that one.

the syntax I'm hoping for is something like:

#alias: pum=Progressive Utility Matrix

Not sure if I can collect each #alias directive declaration into a list to utilize. Still might be possible to achieve, I'll have to play around a bit more with the parsing.

Are there any issues with using a syntax like this?

skanaar commented 5 years ago

The custom classifier styles is a good starting point. They have a “.” prefix to separate them from other directives. We could prefix the aliases with “--“ or “alias-“ (or similar).

/Daniel


From: Scott Tolksdorf notifications@github.com Sent: Tuesday, July 16, 2019 5:01 PM To: skanaar/nomnoml Cc: Daniel Kallin; Comment Subject: Re: [skanaar/nomnoml] [enhancement] Alias/nickname syntax (#106)

I was hoping a simple directive would work, but after taking a quick glance, it seems directives don't want to be multi-declared. I was hopeful looking at #import, but it looks like you do a special cli-only parse step for that one.

the syntax I'm hoping for is something like:

alias: pum=Progressive Utility Matrix

Not sure if I can collect each #alias directive declaration into a list to utilize. Still might be possible to achieve, I'll have to play around a bit more with the parsing.

Are there any issues with using a syntax like this?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/skanaar/nomnoml/issues/106?email_source=notifications&email_token=AAE4P55MIPWVNO4YNWY2VD3P7XPDLA5CNFSM4IDYXXVKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2BERWA#issuecomment-511854808, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAE4P57K3JR4Q2BDFLQYZSTP7XPDLANCNFSM4IDYXXVA.

KurkanRamazan commented 4 years ago

Hi, In IPython, there is a syntax called "Magic command system" (https://ipython.org/ipython-doc/stable/interactive/reference.html#magic-command-system)

IPython will treat any line whose first character is a % as a special call to a ‘magic’ function. These allow you to control the behavior of IPython itself, plus a lot of system-type features.

We can apply similar logic in here.

%alias SailorMessage shiver me; timbers
[<actor>Sailor] - [<usecase>Ahoy friend. Message from alias: ${SailorMessage}]

I tweaked jison file a little bit: https://github.com/KurkanRamazan/nomnoml/blob/magic_commands/src/nomnoml.jison

skanaar commented 1 year ago

A few year late, but I am about to release "alias" support!

Have a look at https://stage.nomnoml.com/ where I have deployed a release candidate for the new parser.

@stolksdorf I would be very grateful for some testing here before I deploy it to www.nomnoml.com 🙏

stolksdorf commented 1 year ago

A few months late, but I'm here!

So happy that you worked on this feature. What is the syntax that you ended up with? I don't see alias referenced in the documentation, but in some examples I see the use of the id= attribute.

If I try to use the id attribute on it's own I get an error (on both prod and stage) . eg. [<id=foo> Foo Bar].

skanaar commented 1 year ago

You have to start the attribute bracket with a type (for example "class"). This might change...

I have intentionally not promoted the new features too much since I had to rewrite the parser and I would like to find the bugs related to the old syntax first.

skanaar commented 1 year ago

This is now released as v1.6.1 🎉