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

Unified cli-ops & script parser #614

Closed
foresterre opened this issue Oct 7, 2020 · 0 comments
Closed

Unified cli-ops & script parser #614

foresterre opened this issue Oct 7, 2020 · 0 comments
Assignees
Labels
A-parser Area: changes related to the image operations parser (all strategies) N-experimental Nature: experimental

Comments

@foresterre
Copy link
Owner

foresterre commented Oct 7, 2020

Unified parser

Advantages:

  • Easier and faster to implement a new operation, since no more writing two similar but also quite different (semi) parsers
  • More generic, ie the operation names aren't part of the grammar any more. This also helps with enabling plugins (the current prototype for this doesn't have proper parsing support).

Disadvantages:

  • Dealing with two slightly different textual inputs (e.g. operations in cli-ops start with -- while, script doesn't, perhaps we could make starting with -- optional like op_name = "--"? ~ op_ident)
  • Dealing with two different input methods. cli-ops are received through std::env::env() while script is received through files or text.

Breaking changes:

Proposed:

  • Implicit argument maps:

Currently, complex arguments are given like so:

draw-text '<3' coord(10, 2) rgba(255, 0, 0, 255) size(14) font('./Lato-Regular.ttf')

Dissecting each component:

  • draw-text: operation name
  • <3: string (arg 1)
  • coord(10,2): named value with name type coord (arg 2)
  • rgba(255, 0, 0, 255): named value with name type rgba (arg 3)
  • size(14): named value with name type size (arg 4)
  • font('./Lato-Regular.ttf')': named value with name typefont` (arg 5)

For script, this is getting complex, but is workable. For cli-ops however this may be getting too complex.
Not using named values also isn't the best option, since a long list of numbers and text, makes it unclear what is what.
The current implementation cares about argument ordering, and perhaps the future should do too (?).
Inspired by python, maybe we should add named parameters (instead of values) like so:

draw-text '<3' pos=10,2 color=rgba(255, 0, 0, 255) size=14 font='./Lato-Regular.ttf'

where for example pos = 10, 2, coord is the formal parameter name, 10, 2 is a tuple with values 10 and 2 (using , as tuple operator)

The perhaps biggest question however is whether this is more ergonomic than the old syntax, and then what we could do to make it even more ergonomic.

def
  draw-text
with
  positional required :: text <string>
  implicitmap required <T is Coord> :: pos <(T, T)>
  implicitmap withdefault <T is Color> :: color <T> (default rgb(0,0,0,0))
  implicitmap withdefault <T is Size> :: size <T> (default 16px)
  implicitmap withdefault <T is Font> :: font <T> (default %include='Lato-Regular.ttf'% )  

At some point I would also like to add default values. Currently we use modifiers for this, but possibly optional arguments could be more ergonomic.

Efforts:

duo parser draft pr: #617

@foresterre foresterre added N-experimental Nature: experimental A-parser Area: changes related to the image operations parser (all strategies) labels Oct 7, 2020
@foresterre foresterre self-assigned this Oct 7, 2020
@foresterre foresterre mentioned this issue Oct 7, 2020
12 tasks
@foresterre foresterre pinned this issue Oct 7, 2020
@foresterre foresterre added this to the 0.15.0 milestone Nov 8, 2020
@foresterre foresterre modified the milestones: 0.15.0, 0.16.0 Dec 19, 2020
@foresterre foresterre removed this from the 0.16.0 milestone Feb 13, 2021
@foresterre foresterre unpinned this issue Feb 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: changes related to the image operations parser (all strategies) N-experimental Nature: experimental
Projects
None yet
Development

No branches or pull requests

1 participant