first samples for a potential command-type description language

This commit is contained in:
Michael Sippel 2023-10-07 13:07:18 +02:00
parent 1ab8db590b
commit 73817529d6
Signed by: senvas
GPG key ID: F96CF119C34B64A6
6 changed files with 215 additions and 0 deletions

65
typeDB/cut Normal file
View file

@ -0,0 +1,65 @@
::cut OPTION... [FILE]... {
match OPTION... {
--help { <1 : Help~<Seq Char> ; }
--version { <1 : VersionInfo~<Seq Char> ; }
* {
match OPTION... {
-f--fields LIST:<Seq >~CutFieldList~<Seq Char> {
ROW-DELIM =
match OPTION... {
-z--zero-terminated { '\0' }
* { '\n' }
};
IN-COL-DELIM =
match OPTION... {
-d--delimiter DELIM:Char { DELIM }
* { '\t' }
};
OUT-COL-DELIM =
match OPTION... {
--output-delimiter STRING:<Seq Char> { STRING }
* { IN-COL-DELIM }
};
FILE : Path
~<Seq PathSegment
~<Seq Char>>
~<SepSeq Char '/'>
~<Seq Char> ;
@FILE : <Seq <* < ITEM~<Seq Char> >... >
~<Seq <Seq Char>>
~<SepSeq Char IN-COL-DELIM>
~<Seq Char>>
~<SepSeq Char ROW-DELIM>
~<Seq Char> ;
>0 : <Seq <* <ITEM~<Seq Char>>... >
~<Seq <Seq Char>>
~<SepSeq Char IN-COL-DELIM>
~<Seq Char>>
~<SepSeq Char ROW-DELIM>
~<Seq Char> ;
# `[LIST]` means `select all fields contained in LIST from parameter pack`
<1 : <Seq <* <ITEM~<Seq Char>>[LIST]... >
~<Seq <Seq Char>>
~<SepSeq Char OUT-COL-DELIM>
~<Seq Char>>
~<SepSeq Char ROW-DELIM>
~<Seq Char> ;
}
* {
<1 : Nothing ;
<2 : MissingFields~ErrorMessage~<Seq Char> ;
}
}
}
}
}

15
typeDB/date Normal file
View file

@ -0,0 +1,15 @@
::date [OPTION]... [+FORMAT] {
match FORMAT {
"+%s" {
<1 : TimePoint
~<TimeSince UnixEpoch>
~<Duration Seconds>
~
~<PosInt 10 BigEndian>
~<Seq <Digit 10>~Char>
}
* {
<1 : TimePoint ;
}
}
}

56
typeDB/dirname Normal file
View file

@ -0,0 +1,56 @@
::dirname [OPTION] NAME... {
# dont expect any data on stdin
#
>0 : None ;
# each (non-option) argument must be a path
#
NAME : Path
~<Seq PathSegment
~<Seq Char>>
~<SepSeq Char '/'>
~<Seq Char>
~UTF-8
~<Seq Byte> ;
matchopt OPTION {
# help and version flags will bypass any data processing
#
--help { <1 : Help~<Seq Char> ; }
--version { <1 : VersionInfo~<Seq Char> ; }
# in case neither --help nor --version is set
# ...
* {
# if zero-flag is set, use '\0' instead of '\n'
# as delimiter in output sequence
DELIM =
match OPTION {
-z--zero { '\0' }
* { '\n' }
};
# output a sequence of paths to stdout
#
<1 : <Seq Path
~<Seq PathSegment~<Seq Char>>
~<SepSeq Char '/'>
~<Seq Char>>
~<SepSeq Char DELIM>
~<Seq Char> ;
}
}
}

16
typeDB/echo Normal file
View file

@ -0,0 +1,16 @@
::echo [OPTIONS]... [STRING]... {
>0 : None ;
matchopt OPTION {
--help { <1 : Help~<Seq Char> ; }
--version { <1 : VersionInfo~<Seq Char> ; }
-n {
<1 : <* STRING~<Seq Char>... >
~<Seq Char> ;
}
* {
<1 : <* STRING~<Seq Char>... '\n' >
~<Seq Char> ;
}
}
}

25
typeDB/seq Normal file
View file

@ -0,0 +1,25 @@
::seq [OPTION]... [FIRST [INCREMENT]] LAST {
>0 : None ;
match OPTION... {
--help { <1 : Help~<Seq Char> ; }
--version { <1 : VersionInfo~<Seq Char> ; }
* {
NUM = match OPTION... {
-f--format FORMAT { ~<Float 10 FORMAT>~<Seq Char> }
* { ~<PosInt 10 BigEndian>~<Seq <Digit 10>~Char> }
};
SEP = match OPTION... {
-s--separator SEP { SEP }
* { '\n' }
};
$FIRST : NUM ;
$INCREMENT : NUM ;
$LAST : NUM ;
<1 : <Seq NUM~<Seq Char>>~<SepSeq Char SEP>~<Seq Char> ;
}
}
}

38
typeDB/xargs Normal file
View file

@ -0,0 +1,38 @@
::xargs [OPTION]... [CMD [INITIAL-ARGS]...] {
DELIM =
match OPTION... {
-0--null { '\0' }
-d--delimiter D:Char { D }
};
match OPTION... {
-a--argfile PATH => {
# type of data read from file at `path`
@PATH : ARGS~<Seq Char>...
~<Seq <Seq Char>>
~<SepSeq Char DELIM>
~<Seq Char> ;
}
* {
# type of data read from stdin
>0 : ARGS~<Seq Char>...
~<Seq <Seq Char>>
~<SepSeq Char DELIM>
~<Seq Char> ;
}
}
match OPTION... {
-I REPLACE-STR {
# TODO : how to handle replacement ?
<1 : cmdtype <1 { CMD { INITIAL-ARGS where REPLACE-STR -> ARGS... } } ;
}
* {
<1 : cmdtype <1 { CMD INITIAL-ARGS... ARGS... } ;
}
}
}