xonixx / makesure

Simple task/command runner with declarative goals and dependencies

Home Page:https://makesure.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve parsing algorithm to handle spaces and comments

xonixx opened this issue · comments

Things to take into account

  1. Support comments in @directive lines and spaces in goal names
  2. We need to rely on quoting 'str' or "str"
  3. It's desirable that whatever quoting approach we chose it plays nice with shell's quoting:
    • The shell highligting applied to Makesurefile in IDE keeps working.
    • You can take the goal name as rendered by ./makesure -l and use it to call ./makesure 'goal name'
    • However to implement the whole shell-compliant parsing for 'all' "types" of $'strings' will be too complex.
  4. Need to handle '\'' properly and consistently.
  5. Complications with @doc and @define

Comments

@goal goal_with_comment # comment
  echo goal_with_comment

@goal test1
@depends_on goal_with_comment

This one won't parse as expected. # comment will be treated as part of goal name

Spaces

@goal @glob 22_parsing*.txt # glob can produce files with whitespaces in the name
  echo "$ITEM"
  cat "$ITEM"

@goal test2
@depends_on '22_parsing 2.txt' # but currently this is impossible

Right now we rely on default AWK algorithm at parsing a line (NF + $i). This is totally fine for current version since covers most of cases, but we need something more flexible.

Possible approach

@goal no_space

@goal 'name with spaces' # no single quote allowed between single quotes

@goal $'name with \' quote' # $'strings' allow quote escaping 

./makesure -l

Available goals:
  no_space
  'name with spaces'
  $'name with \' quote'

Rationale

  • Why support both 'str' and $'str'
    • most of the time 'str' can be used, rarely $'str\'str'
  • Why not "str\"\'str"
    • this implies unneded variables substitution. I.e. ./makesure "aaa$bbb" will not work as expected.