bpriver_chain 0.2.0 copy "bpriver_chain: ^0.2.0" to clipboard
bpriver_chain: ^0.2.0 copied to clipboard

this package is implementation of chain language.

Chain Language #

Chain is data description language.

Syntax #

Simple example #

For example, tiger 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.

  1. head position is the beginning.
  2. head prefix is no hypen.
  3. head is not empty.
  4. head quantity is 0 or 1.
    • depending on your system, you may want to implement a default head.

Option #

  1. option position is free.
  2. option prefix is double-hypen.
  3. option is not empty.
  4. option quantity is 0 or more.
  5. option value quantity is 0 or more.
    • In the above example, 'abc' and 'tiger_sample.yaml' is option value.
  6. 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'
  7. option value prefix is no hypen.

Flag #

  1. flag position is free.
  2. flag prefix is single-hypen.
  3. flag is not empty.
  4. 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 option and flag

There is only one way to specify.

Code example #

Source is List(arguments) #


import 'package:bpriver_origin/bpriver_origin.dart';
import 'package:bpriver_chain/chain.dart';

void main() {

    final arguments = [
        'a',
        '--b', 'x', 'y', 'z',
        '-c',
        '--v',
        '-w',
        '--x', 'y',
        '-z',
    ];

    final chainResult = Chain.parseListSource(arguments);
    if (chainResult is! Success<Chain, ChainSyntaxException>) {
        print('parseListSource() is Failure');
        return;
    };

    final Chain chain = chainResult.wrapped;

    final headBox = chain.headBox;
    if (headBox is ! Full<Head>) {
        print('headBox is Failure');
        return;
    }
    final head = headBox.content;

    final optionResult = chain.getOption('b');
    if (optionResult is! Success<Option, ChainExceptionI>) {
        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;
    }

    print('head = ${head.nameArgument.name}');
    print('b option name = ${option.nameArgument.name}');
    print('b option name(with hypen) = ${option.nameArgument.value}');
    print('b option value list= ${option.valueArgumentList}');
    print('c flag = ${flag}');

    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}');

}

Source is string(serial) #


import 'package:bpriver_origin/bpriver_origin.dart';
import 'package:bpriver_chain/chain.dart';

void main() {

    final source = 'a --b x y z -c --v -w --x y -z';

    final parseStringSourceResult = Chain.parseStringSource(source);
    if (parseStringSourceResult is! Success<List<String>, ChainSyntaxException>) {
        print('parseStringSource() is Failure');
        return;
    }

    final arguments = parseStringSourceResult.wrapped;

    // The rest is the same as list_source.dart.

    final chainResult = Chain.parseListSource(arguments);
    if (chainResult is! Success<Chain, ChainSyntaxException>) {
        print('parseListSource() is Failure');
        return;
    };

    final Chain chain = chainResult.wrapped;

    final headBox = chain.headBox;
    if (headBox is ! Full<Head>) {
        print('headBox is Failure');
        return;
    }
    final head = headBox.content;

    final optionResult = chain.getOption('b');
    if (optionResult is! Success<Option, ChainExceptionI>) {
        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;
    }

    print('head = ${head.nameArgument.name}');
    print('b option name = ${option.nameArgument.name}');
    print('b option name(with hypen) = ${option.nameArgument.value}');
    print('b option value list= ${option.valueArgumentList}');
    print('c flag = ${flag}');

    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}');

}

0
likes
0
points
326
downloads

Publisher

verified publisherbpriver.com

Weekly Downloads

this package is implementation of chain language.

Repository (GitLab)
View/report issues

License

unknown (license)

Dependencies

bpriver_origin, bpriver_syntax_scanner

More

Packages that depend on bpriver_chain