bpriver_chain 0.3.1
bpriver_chain: ^0.3.1 copied to clipboard
this package is implementation of chain language.
Chain Language
Chain is serial data description language.
Use #
- cui
- argument parser
- inter-application communication
Syntax #
For example, tiger 's cui is chain language.
tiger run --taskLocation 'abc' --taskName 'tiger_sample.yaml'
run is head.
--taskLocation 'abc' and --taskName 'tiger_sample.yaml' is option.
There is no example, -log is flag.
Chain contains only Head, Option, and Flag.
Head #
- head position is the beginning.
- head prefix is no hypen.
- head is not empty.
- head quantity is 0 or 1.
- depending on your system, you may want to implement a default head.
Option #
- option position is free.
- option prefix is double-hypen.
- option is not empty.
- option quantity is 0 or more.
- option value quantity is 0 or more.
In the above example, 'abc'and'tiger_sample.yaml'is option value.
- option value position is right behind option or right behind option value.
- you can make a List by placing option value in a row.
- example,
--something 'a' 'b' 'c'
- option value prefix is no hypen.
Flag #
- flag position is free.
- flag prefix is single-hypen.
- flag is not empty.
- flag quantity is 0 or more.
Include white space #
if you want to include white space in serial source, Please circle it with single or double quotation.
example: --something 'hello world'
Include quotation #
if you want to include single quotation in serial source, Please circle it with double quotation.
example: --something "abc'def'ghi"
if you want to include double quotation in serial source, Please circle it with single quotation.
example: --something 'abc"def"ghi'
Other #
Triple-hypen or more prefix
Valid as head or option value.
But, Not recommended.
Pass value that starts with a hyphen to option value
Impossible.
There is no shorthand for head, option, and flag
There is only one way to specify.
Code example #
import 'package:bpriver_chain/bpriver_chain.dart';
void main() {
final source = 'a --b x -c --v -w --x x y z -z';
final parseStringResult = Chain.parseString(source);
if (parseStringResult is! Success<List<String>, ChainSyntaxException>) {
print('parseString() is Failure');
return;
}
final parseListResult = Chain.parseList(parseStringResult.wrapped);
if (parseListResult is! Success<Chain, ChainSyntaxException>) {
print('parseList() is Failure');
return;
};
final Chain chain = parseListResult.wrapped;
final headResult = chain.getHead();
if (headResult is! Success<String, ChainExceptionB>) {
print('headBox is Failure');
return;
}
final head = headResult.wrapped;
final optionResult = chain.getOptionAsSingleString('b');
if (optionResult is! Success<String, ChainExceptionIJK>) {
print('option is Failure');
return;
};
final option = optionResult.wrapped;
final flagResult = chain.isFlag('c');
final flag = flagResult.wrapped;
if (flag == false) {
print('flag is Failure');
return;
}
final multipleOptionResult = chain.getOptionAsMultiple('x');
if (multipleOptionResult is! Success<ArgumentList<ValueArgument>, ChainExceptionIJ>) {
print('multiple option is Failure');
return;
}
final multipleOption = multipleOptionResult.wrapped.toPrimitive();
print('head = ${head}');
print('b option = ${option}');
print('c flag = ${flag}');
print('x option = ${multipleOption}');
final List<String> optionList = [];
for (final i in chain.optionList) {
optionList.add(i.nameArgument.name);
}
print('option list = ${optionList}');
final List<String> flagList = [];
for (final i in chain.flagList) {
flagList.add(i.nameArgument.name);
}
print('flag list = ${flagList}');
}