Ejemplo n.º 1
0
 def test_choice(self):
     self._check(
         sut.Choice.of_single_argument_choices(
             sut.Multiplicity.MANDATORY,
             [sut.Named('arg1'), sut.Named('arg2')]),
         sut.Choice,
     )
Ejemplo n.º 2
0
def def_instruction_argument_syntax() -> List[a.ArgumentUsage]:
    return [
        a.Single(a.Multiplicity.MANDATORY, a.Named(TYPE_SYNTAX_ELEMENT)),
        a.Single(a.Multiplicity.MANDATORY,
                 syntax_elements.SYMBOL_NAME_SYNTAX_ELEMENT.argument),
        a.Single(a.Multiplicity.MANDATORY, a.Constant(ASSIGNMENT_ARGUMENT)),
        a.Single(a.Multiplicity.MANDATORY, a.Named(VALUE_SYNTAX_ELEMENT)),
    ]
Ejemplo n.º 3
0
 def test_choice__single_argument_choices(self):
     # ARRANGE #
     renderer = sut.ArgumentUsageOnCommandLineRenderer()
     argument_usage = arg.Choice.of_single_argument_choices(
         arg.Multiplicity.OPTIONAL,
         [arg.Named('name1'), arg.Named('name2')],
     )
     # ACT #
     actual = renderer.visit(argument_usage)
     # ASSERT #
     self.assertEqual('[name1|name2]', actual)
Ejemplo n.º 4
0
 def invokation_variants(self) -> Sequence[InvokationVariant]:
     from exactly_lib.definitions.entity.actors import SOURCE_INTERPRETER_ACTOR
     source_interpreter_arg = a.Single(a.Multiplicity.MANDATORY,
                                       a.Named(SOURCE_INTERPRETER_NAME))
     file_interpreter_arg = a.Single(a.Multiplicity.MANDATORY,
                                     a.Named(FILE_INTERPRETER_NAME))
     return (
         self._command_line_invokation_variant(),
         self._interpreter_actor_invokation_variant(FILE_INTERPRETER_ACTOR,
                                                    file_interpreter_arg),
         self._interpreter_actor_invokation_variant(
             SOURCE_INTERPRETER_ACTOR, source_interpreter_arg),
         self._null_invokation_variant(),
     )
Ejemplo n.º 5
0
 def argument_usage_list(self) -> Sequence[a.ArgumentUsage]:
     return [
         a.Choice.of_single_argument_choices(
             a.Multiplicity.MANDATORY,
             [a.Named(value) for value in logic.BOOLEANS.values()]
         )
     ]
def path_element_3(
    rel_options_conf: RelOptionArgumentConfiguration,
    custom_paragraphs: Sequence[ParagraphItem] = ()
) -> SyntaxElementDescriptionTree:
    return SyntaxElementDescriptionTreeFromSed(
        a.Named(rel_options_conf.argument_syntax_name),
        path_element_2(rel_options_conf, custom_paragraphs))
Ejemplo n.º 7
0
def _choice_w_multiple_args_from_strings(
    multiplicity: arg.Multiplicity,
    choices: List[List[str]],
) -> arg.Choice:
    return arg.Choice.of_multiple_argument_choices(
        multiplicity, [[arg.Named(choice_arg) for choice_arg in choice]
                       for choice in choices])
Ejemplo n.º 8
0
def _standard_type_value_args(
    type_info: TypeNameAndCrossReferenceId,
    value_multiplicity: a.Multiplicity = a.Multiplicity.MANDATORY
) -> List[a.ArgumentUsage]:
    return [
        a.Single(value_multiplicity, a.Named(type_info.syntax_element_name))
    ]
Ejemplo n.º 9
0
 def test_named_argument_SHOULD_produce_name(self):
     # ARRANGE #
     renderer = sut.ArgumentOnCommandLineRenderer()
     argument_usage = arg.Named('the_name')
     # ACT #
     actual = renderer.visit(argument_usage)
     # ASSERT #
     self.assertEqual('the_name', actual)
Ejemplo n.º 10
0
 def __init__(self):
     super().__init__(directives.INCLUDING_DIRECTIVE_INFO)
     self.file_argument = a.Named(
         file_inclusion_directive_parser.FILE_ARGUMENT_NAME)
     self._tp = TextParser({
         'including_directive': self.info.singular_name,
         'FILE': self.file_argument.name,
     })
Ejemplo n.º 11
0
def _constant_sed(name: str) -> SyntaxElementDescription:
    return SyntaxElementDescription(name, _TP.fnap(_LITERAL__HEADER), [
        invokation_variant_from_args([
            a.Single(a.Multiplicity.MANDATORY, a.Constant(
                syntax.LITERAL_BEGIN)),
            a.Single(a.Multiplicity.ONE_OR_MORE, a.Named(_FILE_CONDITION)),
            a.Single(a.Multiplicity.MANDATORY, a.Constant(syntax.LITERAL_END)),
        ], _TP.fnap(_LITERAL__DESCRIPTION_REST)),
    ])
Ejemplo n.º 12
0
 def invokation_variants(self) -> List[InvokationVariant]:
     return [
         invokation_variant_from_args([
             a.single_mandatory(self._pgm_and_args.element),
             a.Single(a.Multiplicity.OPTIONAL, _STDIN_ARGUMENT),
             a.Single(a.Multiplicity.OPTIONAL,
                      a.Named(_OUTPUT_TRANSFORMATION)),
         ]),
     ]
Ejemplo n.º 13
0
 def test_single(self):
     # ARRANGE #
     renderer = sut.ArgumentUsageOnCommandLineRenderer()
     argument_usage = arg.Single(arg.Multiplicity.OPTIONAL,
                                 arg.Named('name'))
     # ACT #
     actual = renderer.visit(argument_usage)
     # ASSERT #
     self.assertEqual('[name]', actual)
Ejemplo n.º 14
0
def _here_doc() -> InvokationVariant:
    return invokation_variant_from_args([
        a.Single(
            a.Multiplicity.MANDATORY,
            a.Constant(string.HERE_DOCUMENT_MARKER_PREFIX +
                       _HERE_DOC_SYNTAX_MARKER)),
        a.Single(a.Multiplicity.ZERO_OR_MORE, a.Named(_HERE_DOC_LINE)),
        a.Single(a.Multiplicity.MANDATORY,
                 a.Constant(_HERE_DOC_SYNTAX_MARKER)),
    ], _TEXT_PARSER.fnap(_DESCRIPTION__HERE_DOC))
Ejemplo n.º 15
0
 def invokation_variants(self) -> List[InvokationVariant]:
     primitive_arg = a.single_mandatory(a.Named(self._primitive_name))
     return [
         invokation_variant_from_args([primitive_arg]),
         invokation_variant_from_args([
             a.single_mandatory(a.Constant('(')),
             primitive_arg,
             a.single_mandatory(a.Constant(')')),
         ]),
     ]
Ejemplo n.º 16
0
 def invokation_variants(self) -> Sequence[InvokationVariant]:
     phase_spec_args = self._phase_spec_args()
     name = a.Single(a.Multiplicity.MANDATORY,
                     a.Named(defs.VAR_NAME_ELEMENT))
     value = a.Single(a.Multiplicity.MANDATORY,
                      a.Named(defs.VAR_VALUE_ELEMENT))
     assignment = a.Single(a.Multiplicity.MANDATORY,
                           a.Constant(defs.ASSIGNMENT_IDENTIFIER))
     unset_kw = a.Single(a.Multiplicity.MANDATORY,
                         a.Constant(defs.UNSET_IDENTIFIER))
     return [
         invokation_variant_from_args(
             phase_spec_args + [name, assignment, value],
             self._tp.fnap(_DESCRIPTION_OF_SET),
         ),
         invokation_variant_from_args(
             phase_spec_args + [unset_kw, name],
             self._tp.fnap(_DESCRIPTION_OF_UNSET),
         ),
     ]
Ejemplo n.º 17
0
def _file_list_sed(name: str) -> SyntaxElementDescription:
    return SyntaxElementDescription(name, (), [
        invokation_variant_from_args([
            a.Single(a.Multiplicity.MANDATORY,
                     a.Constant(syntax.FILE_LIST_BEGIN)),
            a.Single(a.Multiplicity.ONE_OR_MORE,
                     a.Named(syntax.FILE_SPEC__SE_STR)),
            a.Single(a.Multiplicity.MANDATORY, a.Constant(
                syntax.FILE_LIST_END)),
        ], _TP.fnap(_FILE_LIST__DESCRIPTION_REST)),
    ])
Ejemplo n.º 18
0
 def test_choice(self):
     test_cases = [
         sut.Choice.of_single_argument_choices(sut.Multiplicity.OPTIONAL,
                                               [sut.Constant('constant')]),
         sut.Choice.of_single_argument_choices(
             sut.Multiplicity.OPTIONAL,
             [sut.Constant('constant'),
              sut.Named('name')]),
     ]
     for value in test_cases:
         with self.subTest():
             str(value)
Ejemplo n.º 19
0
 def test_choice__single_argument_choices(self):
     # ARRANGE #
     args_cases = [
         ['name1', 'name2'],
         ['name1', 'name2', 'name3'],
     ]
     renderer = sut.ArgumentUsageOnCommandLineRenderer()
     for args_case in args_cases:
         with self.subTest(repr(args_case)):
             argument_usage = arg.Choice.of_single_argument_choices(
                 arg.Multiplicity.ONE_OR_MORE,
                 [arg.Named(arg_name) for arg_name in args_case],
             )
             # ACT #
             actual = renderer.visit(argument_usage)
             # ASSERT #
             self.assertEqual('({})...'.format('|'.join(args_case)), actual)
Ejemplo n.º 20
0
class SyntaxDescription(grammar.PrimitiveDescriptionWithNameAsInitialSyntaxToken):
    LINES_SELECTOR = a.Named('LINES-SELECTION')

    @property
    def argument_usage_list(self) -> Sequence[a.ArgumentUsage]:
        return [
            a.Single(a.Multiplicity.OPTIONAL,
                     self.LINES_SELECTOR),
            a.Single(a.Multiplicity.OPTIONAL,
                     names.PRESERVE_NEW_LINES_OPTION),
            a.Single(a.Multiplicity.MANDATORY,
                     _REGEX_ARGUMENT),
            a.Single(a.Multiplicity.MANDATORY,
                     _REPLACEMENT_ARGUMENT),
        ]

    @property
    def description_rest(self) -> Sequence[ParagraphItem]:
        return _TEXT_PARSER.fnap(_DESCRIPTION)

    @property
    def syntax_elements(self) -> Sequence[SyntaxElementDescription]:
        return [
            self._lines_selection_syntax_elements()
        ]

    def _lines_selection_syntax_elements(self) -> SyntaxElementDescription:
        description = _TEXT_PARSER.fnap(_DESCRIPTION__LINES_SELECTION)
        description += texts.type_expression_has_syntax_of_primitive([
            names.LINES_SELECTION_OPTION.argument,
        ])
        return SyntaxElementDescription(
            self.LINES_SELECTOR.name,
            (),
            [
                invokation_variant_from_args(
                    [a.Single(a.Multiplicity.MANDATORY, names.LINES_SELECTION_OPTION)],
                )
            ],
            description,
        )

    @property
    def see_also_targets(self) -> Sequence[SeeAlsoTarget]:
        return [syntax_elements.REGEX_SYNTAX_ELEMENT.cross_reference_target]
Ejemplo n.º 21
0
            [
                invokation_variant_from_args(
                    [a.Single(a.Multiplicity.MANDATORY, names.LINES_SELECTION_OPTION)],
                )
            ],
            description,
        )

    @property
    def see_also_targets(self) -> Sequence[SeeAlsoTarget]:
        return [syntax_elements.REGEX_SYNTAX_ELEMENT.cross_reference_target]


_REGEX_ARGUMENT = syntax_elements.REGEX_SYNTAX_ELEMENT.argument

_REPLACEMENT_ARGUMENT = a.Named(types.STRING_TYPE_INFO.syntax_element_name)
_MISSING_REPLACEMENT_ARGUMENT_ERR_MSG = 'Missing ' + _REPLACEMENT_ARGUMENT.name

_PARSE_REPLACEMENT_CONFIGURATION = parse_string.Configuration('REPLACEMENT')

_TEXT_PARSER = TextParser({
    'preserve_new_lines_option': formatting.argument_option(names.PRESERVE_NEW_LINES_OPTION_NAME),
    '_REG_EX_': _REGEX_ARGUMENT.name,
    '_STRING_': _REPLACEMENT_ARGUMENT.name,
    'plain_string': misc_texts.PLAIN_STRING,
    'LINES_SELECTOR_MATCHER': names.LINES_SELECTION_OPTION.argument,
    'line_matcher_model': matcher_model.LINE_MATCHER_MODEL,
    'Note': headers.NOTE_LINE_HEADER,
    'NL': formatting.string_constant('\\n'),
    'LINES_ARE_SEPARATED_BY_NEW_LINE': misc_texts.LINES_ARE_SEPARATED_BY_NEW_LINE,
})
Ejemplo n.º 22
0
        syntax_elements: Sequence[SyntaxElementDescription] = (),
        see_also_targets: Sequence[SeeAlsoTarget] = (),
        operand_evaluation__lazy__left_to_right: bool = False,
    ):
        self._description_rest = description_rest
        self._see_also_targets = list(see_also_targets)
        self._syntax_elements = syntax_elements
        self._operand_evaluation__lazy__left_to_right = operand_evaluation__lazy__left_to_right

    @property
    def description_rest(self) -> Sequence[ParagraphItem]:
        return self._description_rest

    @property
    def syntax_elements(self) -> Sequence[SyntaxElementDescription]:
        return self._syntax_elements

    @property
    def see_also_targets(self) -> Sequence[SeeAlsoTarget]:
        return self._see_also_targets

    @property
    def operand_evaluation__lazy__left_to_right(self) -> bool:
        return self._operand_evaluation__lazy__left_to_right


CONCEPT = grammar.Concept(
    NameWithGenderWithFormatting(
        NameWithGender('a', 'concept singular', 'concept plural')),
    'type-system-name', a.Named('SYNTAX-ELEMENT-NAME'))
Ejemplo n.º 23
0
 def argument(self) -> a.Named:
     return a.Named(self.singular_name)
Ejemplo n.º 24
0
                        syntax_elements.SYMBOL_NAME_SYNTAX_ELEMENT.argument)

_EQUALS = a.Single(a.Multiplicity.MANDATORY, a.Constant(ASSIGNMENT_ARGUMENT))

TYPE_W_STR_RENDERING_INFO_DICT: Mapping[
    WithStrRenderingType, TypeInfo] = MappingProxyType({
        WithStrRenderingType.STRING:
        TypeInfo(
            types.STRING_TYPE_INFO,
            _standard_type_value_args(types.STRING_TYPE_INFO,
                                      a.Multiplicity.MANDATORY)),
        WithStrRenderingType.PATH:
        TypeInfo(
            types.PATH_TYPE_INFO,
            path_syntax.mandatory_path_with_optional_relativity(
                a.Named(types.PATH_TYPE_INFO.syntax_element_name),
                PATH_SUFFIX_IS_REQUIRED)),
        WithStrRenderingType.LIST:
        TypeInfo(types.LIST_TYPE_INFO,
                 [syntax_elements.LIST_SYNTAX_ELEMENT.single_mandatory]),
    })


def _logic_type_info(type_info: TypeNameAndCrossReferenceId) -> TypeInfo:
    return TypeInfo(type_info, _standard_type_value_args(type_info))


ANY_TYPE_INFO_DICT: Mapping[ValueType, TypeInfo] = {
    ValueType.STRING:
    TYPE_W_STR_RENDERING_INFO_DICT[WithStrRenderingType.STRING],
    ValueType.PATH:
Ejemplo n.º 25
0
    def _test_suite_option_argument(self) -> cli_syntax.DescribedArgument:
        return cli_syntax.DescribedArgument(
            SUITE_OPTION_ARGUMENT,
            _TP.fnap(_CORRESPONDS_TO_TEST_SUITE_ARGUMENT))

    def see_also(self) -> List[SeeAlsoTarget]:
        return [
            PredefinedHelpContentsPartReference(
                HelpPredefinedContentsPart.TEST_CASE_CLI),
            PredefinedHelpContentsPartReference(
                HelpPredefinedContentsPart.TEST_SUITE_CLI),
        ]


CASE_OPTION_ARGUMENT = arg.Named('TEST-CASE-OPTION')
SUITE_OPTION_ARGUMENT = arg.Named('TEST-SUITE-OPTION')
SYMBOL_OPTION_ARGUMENT = arg.Named('SYMBOL-OPTION')


def synopsis_general() -> cli_syntax.Synopsis:
    command_line = _command_line__case(
        [arg.Single(arg.Multiplicity.ZERO_OR_MORE, SYMBOL_OPTION_ARGUMENT)])
    return cli_syntax.Synopsis(
        command_line, _TP.text(_SINGLE_LINE_DESCRIPTION_FOR_CLI_SYNTAX))


def synopsis_all() -> cli_syntax.Synopsis:
    return cli_syntax.Synopsis(
        _command_line__case([]),
        paragraphs=_TP.fnap(_DESCRIPTION_PARAGRAPHS_ALL),
Ejemplo n.º 26
0
 def test_single(self):
     self._check(
         sut.Single(sut.Multiplicity.MANDATORY, sut.Named('value-element')),
         sut.Single)
Ejemplo n.º 27
0
 def test_named(self):
     value = sut.Named('name')
     str(value)
Ejemplo n.º 28
0
from exactly_lib.symbol.value_type import ValueType
from exactly_lib.type_val_deps.types.file_matcher import FileMatcherSdv
from exactly_lib.type_val_prims.matcher.file_matcher import FileMatcher
from exactly_lib.util.cli_syntax.elements import argument as a
from exactly_lib.util.name_and_value import NameAndValue
from exactly_lib.util.textformat.structure import structures as docs
from exactly_lib.util.textformat.structure.core import ParagraphItem
from exactly_lib.util.textformat.structure.document import SectionContents
from exactly_lib.util.textformat.structure.table import TableCell
from exactly_lib.util.textformat.textformat_parser import TextParser
from .impl.names import parsers as names_parsers, doc as names_doc
from ... import file_properties

NAME_MATCHER_ARGUMENT = syntax_elements.GLOB_PATTERN_SYNTAX_ELEMENT.argument

TYPE_MATCHER_ARGUMENT = a.Named('TYPE')


def parsers(must_be_on_current_line: bool = False) -> GrammarParsers[FileMatcherSdv]:
    return _PARSERS_FOR_MUST_BE_ON_CURRENT_LINE[must_be_on_current_line]


def _parse_type_matcher(parser: TokenParser) -> FileMatcherSdv:
    file_type = parser.consume_mandatory_constant_string_that_must_be_unquoted_and_equal(
        file_properties.SYNTAX_TOKEN_2_FILE_TYPE,
        file_properties.SYNTAX_TOKEN_2_FILE_TYPE.get,
        TYPE_MATCHER_ARGUMENT.name)
    return sdv_components.matcher_sdv_from_constant_primitive(FileMatcherType(file_type))


def _parse_regular_file_contents(token_parser: TokenParser) -> FileMatcherSdv:
Ejemplo n.º 29
0
 def test_named(self):
     self._check(sut.Named('value-element'), sut.Named)
Ejemplo n.º 30
0
from typing import List

from exactly_lib.common.help.syntax_contents_structure import InvokationVariant
from exactly_lib.definitions import instruction_arguments
from exactly_lib.definitions.argument_rendering import cl_syntax
from exactly_lib.section_document.element_parsers.instruction_parser_exceptions import \
    SingleInstructionInvalidArgumentException
from exactly_lib.section_document.element_parsers.misc_utils import split_arguments_list_string
from exactly_lib.util.cli_syntax.elements import argument as a
from exactly_lib.util.messages import expected_found

MANDATORY_EQ_ARG = a.Single(a.Multiplicity.MANDATORY,
                            a.Named(instruction_arguments.ASSIGNMENT_OPERATOR))


def single_eq_invokation_variants(mandatory_arg: a.Argument) -> list:
    args = [
        MANDATORY_EQ_ARG,
        a.Single(a.Multiplicity.MANDATORY, mandatory_arg),
    ]
    return [
        InvokationVariant(cl_syntax.cl_syntax_for_args(args)),
    ]


def extract_single_eq_argument_string(syntax_element: str,
                                      rest_of_line: str) -> str:
    arguments = rest_of_line.strip().split(maxsplit=1)
    if not arguments:
        raise SingleInstructionInvalidArgumentException(
            _missing(instruction_arguments.ASSIGNMENT_OPERATOR))