krieselreihe / litr

Litr (Language Independent Task Runner) lets you configure and then run any tasks you want for any language.
MIT License
8 stars 0 forks source link

Document and implement the different ways of execution #15

Closed MartinHelmut closed 3 years ago

MartinHelmut commented 3 years ago
litr --help                          # Show litr help
litr -h                              # Show litr help

litr build                           # Exec command "build"

litr build cpp                       # Exec command "cpp" inside "build"

litr build cpp,java                  # Exec "cpp" and "java" in that order inside "build"
litr build cpp, java                 # Exec "cpp" and "java" in that order inside "build"

litr build,run                       # Exec "build" and then "run"
litr build, run                      # Exec "build" and then "run"

litr build cpp another               # Exec "another" inside "cpp" inside "build"

litr --target="release" build,run    # Exec "build" and "run", both with the param "target=release"
litr --target="release" build, run   # Exec "build" and "run", both with the param "target=release"

litr build -t="release"              # Exec "build" with short param "t=release"

litr build -t="release" --debug -p=2 # Exec "build" with 3 different parameters

litr -t="release" build, run -p=1    # Exec "build" and "run" with parameter "t", and "run" extra with "p"
litr -t="release" build, run -p=1.23 # Exec "build" and "run" with parameter "t", and "run" extra with "p"
MartinHelmut commented 3 years ago

First part: Adding a scanner to tokenize input 8cdd1c9289fc7c61954b8c38ab13e37aec6a4796

MartinHelmut commented 3 years ago

To continue with the parser, convert Tokens to Instructions.

For the following given command:

litr -t="debug" build cpp -p=1 , java -p=2 ,, run -y

Here a pseudo instructions list as example:

BEGIN_SCOPE ""
LOAD        "t" "debug"
BEGIN_SCOPE "build"
BEGIN_SCOPE "cpp"
LOAD        "p" "1"
EXECUTE     "build.cpp"
END_SCOPE   "," "cpp" // Comma clears the last scope
BEGIN_SCOPE "java"
LOAD        "p" "2"
EXECUTE     "build.java"
END_SCOPE   "," "java"
END_SCOPE   "," "build"
BEGIN_SCOPE "run"
LOAD        "y" true
EXECUTE     "run"
END_SCOPE   "," "run"
END_SCOPE   "EOS" ""

The double comma ,, to end another scope should not be documented, as it is not an officially supported feature. Or should it?

MartinHelmut commented 3 years ago

Possible notation to describe syntax:

# Entry point:
arguments = parameters? commands?;

parameters = parameter+;

parameter = parameter_name ( "=" literal )?;

parameter_name = short_parameter | long_parameter;

short_parameter = "-" STRICT_ALPHA;

long_parameter = "--" STRICT_ALPHA;

commands = command ( "," command )?;

command = ALPHA parameters?;

# Numbers are handled as strings as well. This won't make a difference for any shell.
literal = NUMBER | STRING;

NUMBER = "-"? 0-9+ ("." 0-9+)?
STRING = '"' .* '"';
ALPHA = A-Za-z_;
STRICT_ALPHA = A-Za-z;

Legend:

MartinHelmut commented 3 years ago

For the given command

litr -t="debug" build cpp -p=1 -p=2 , java --pog=2

the current parser produces the following instructions:

0000 DEFINE              0 't'
0002 CONSTANT            1 'debug is cool'
0004 BEGIN_SCOPE         2 'build'
0006 BEGIN_SCOPE         3 'cpp'
0008 DEFINE              4 'p'
0010 CONSTANT            5 '1'
0012 DEFINE              6 'p'
0014 CONSTANT            7 '2'
0016 EXECUTE             8 'build.cpp'
0018 CLEAR
0019 BEGIN_SCOPE         9 'java'
0021 DEFINE             10 'pog'
0023 CONSTANT           11 '2'
0025 EXECUTE            12 'build.java'
0027 CLEAR

Process finished with exit code 0
MartinHelmut commented 3 years ago

Documentation created under: https://github.com/krieselreihe/litr/wiki/Command-line-argument-parsing