コード例 #1
0
 def add_function_to_stack(stack: AutomatonStack):
     arguments = []
     if not stack.data_stack:
         raise ParsingError('Detected a closing parantheses without an opening one')
     stack_content = stack.pop_data()
     while not isinstance(stack_content, FunctionDeclaration):
         arguments.insert(0, stack_content)
         if not stack.data_stack:
             raise ParsingError('Detected a closing parantheses without an opening one')
         stack_content = stack.pop_data()
     stack.add_data(stack_content.create_function(arguments))
コード例 #2
0
ファイル: argument.py プロジェクト: zhiyin121/adviser
 def perform_stack_action(self, stack: AutomatonStack,
                          configuration: Configuration):
     current_content = stack.get_current_content()
     if not current_content:
         raise ParsingError('A variable name was expected!')
     stack.add_data(Argument(current_content))
     stack.remove_level()
コード例 #3
0
 def perform_stack_action(self, stack: AutomatonStack, configuration: Configuration):
     current_content = stack.get_current_content()
     if not current_content:
         raise ParsingError('Empty function name is not allowed!')
     stack.add_data(FunctionDeclaration(current_content))
     stack.remove_level()
     stack.add_level()
コード例 #4
0
ファイル: argumentstart.py プロジェクト: zhiyin121/adviser
 def get_output_configuration(
         self, input_configuration: Configuration) -> Configuration:
     if not input_configuration.character.isalpha(
     ) and input_configuration.character != '_':
         raise ParsingError(
             f'Non-alpha character "{input_configuration.character}" detected.'
         )
     return Configuration(ArgumentState(), input_configuration.character)
コード例 #5
0
    def parse(self, input_tape: str) -> List[object]:
        self.stack.clear()
        current_state = self.start_state
        input_tape_index = 0

        for input_char in input_tape:
            try:
                configuration = Configuration(current_state, input_char)
                transition = self._find_transition(configuration)
                current_state = self._apply_transition(transition, configuration)
                input_tape_index += 1
            except ParsingError as error:
                print('State:', current_state.name)
                print('Index:', input_tape_index)
                print('Original Input:', input_tape)
                raise error

        if current_state not in self.accept_states:
            print('State:', current_state.name)
            raise ParsingError(f'Parser was not in a final state after the input tape was read.')

        return self.stack.data_stack[:]
コード例 #6
0
 def check_stack(stack: AutomatonStack):
     if stack.get_current_content() == '':
         ParsingError('Empty member variable detected')
コード例 #7
0
 def check_stack(stack: AutomatonStack):
     if len(stack.data_stack) != 1:
         ParsingError('At the end of the code environment, there must be exactly'
                      'one element on the stack!')
コード例 #8
0
ファイル: expressionend.py プロジェクト: zhiyin121/adviser
 def get_output_configuration(
         self, input_configuration: Configuration) -> Configuration:
     ParsingError(
         f'Unexpected character "{input_configuration.character}" after '
         f'the expression ended.')
コード例 #9
0
 def _find_default_transition(self, current_state: State):
     if current_state not in self.state_default_transition_mapping:
         raise ParsingError(f'No default transition found for state {current_state.name}.')
     return self.state_default_transition_mapping.get(current_state, None)
コード例 #10
0
 def get_output_configuration(
         self, input_configuration: Configuration) -> Configuration:
     if input_configuration.character != '$':
         raise ParsingError(
             'Received a character after the NLG message ended.')
コード例 #11
0
ファイル: constraintend.py プロジェクト: zhiyin121/adviser
 def perform_stack_action(self, stack: AutomatonStack,
                          input_configuration: Configuration):
     raise ParsingError(
         'Expected the end of the constraint or a conjunctive "&"!')
コード例 #12
0
 def perform_stack_action(self, stack: AutomatonStack,
                          input_configuration: Configuration):
     raise ParsingError(
         'Expected a string on the right side of the constraint!')
コード例 #13
0
ファイル: accept.py プロジェクト: zhiyin121/adviser
 def perform_stack_action(self, stack: AutomatonStack, input_configuration: Configuration):
     raise ParsingError('Received a character after the function declaration ended.')
コード例 #14
0
ファイル: accept.py プロジェクト: zhiyin121/adviser
 def get_output_configuration(self, input_configuration: Configuration) -> Configuration:
     raise ParsingError('Received a character after the function declaration ended.')
コード例 #15
0
 def perform_stack_action(self, stack: AutomatonStack,
                          configuration: Configuration):
     raise ParsingError(
         'The python code environment requires two closing braces!')
コード例 #16
0
 def get_output_configuration(
         self, input_configuration: Configuration) -> Configuration:
     raise ParsingError(
         'The python code environment requires two closing braces!')
コード例 #17
0
ファイル: stack.py プロジェクト: zhiyin121/adviser
 def remove_level(self):
     if not self.levels:
         raise ParsingError('No more levels to remove from the stack')
     self.levels.pop()
コード例 #18
0
ファイル: stack.py プロジェクト: zhiyin121/adviser
 def get_current_content(self) -> str:
     if not self.levels:
         raise ParsingError('No more levels left on the stack')
     return ''.join(self.levels[-1])
コード例 #19
0
ファイル: stack.py プロジェクト: zhiyin121/adviser
 def add_char(self, stack_char: str):
     if not self.levels:
         raise ParsingError('No more levels left on the stack')
     self.levels[-1].append(stack_char)
コード例 #20
0
 def perform_stack_action(self, stack: AutomatonStack,
                          input_configuration: Configuration):
     raise ParsingError(
         'Expected an operator for the constraint (e.g. "=")!')
コード例 #21
0
 def get_output_configuration(
         self, input_configuration: Configuration) -> Configuration:
     raise ParsingError(
         'Expected a string on the right side of the constraint!')
コード例 #22
0
ファイル: accept.py プロジェクト: zhiyin121/adviser
 def get_output_configuration(
         self, input_configuration: Configuration) -> Configuration:
     raise ParsingError(
         'Received a character after the code environment was closed.')
コード例 #23
0
ファイル: constraintend.py プロジェクト: zhiyin121/adviser
 def get_output_configuration(
         self, input_configuration: Configuration) -> Configuration:
     raise ParsingError(
         'Expected the end of the constraint or a conjunctive "&"!')
コード例 #24
0
 def get_output_configuration(
         self, input_configuration: Configuration) -> Configuration:
     raise ParsingError(
         'Expected an operator for the constraint (e.g. "=")!')
コード例 #25
0
ファイル: start.py プロジェクト: zhiyin121/adviser
 def get_output_configuration(
         self, input_configuration: Configuration) -> Configuration:
     raise ParsingError('An NLG message must start with a quotation mark!')
コード例 #26
0
 def perform_stack_action(self, stack: AutomatonStack,
                          input_configuration: Configuration):
     if input_configuration.character != '$':
         raise ParsingError(
             'Received a character after the NLG message ended.')
コード例 #27
0
ファイル: accept.py プロジェクト: zhiyin121/adviser
 def perform_stack_action(self, stack: AutomatonStack,
                          input_configuration: Configuration):
     raise ParsingError(
         'Received a character after the code environment was closed.')
コード例 #28
0
ファイル: start.py プロジェクト: zhiyin121/adviser
 def perform_stack_action(self, stack: AutomatonStack,
                          input_configuration: Configuration):
     raise ParsingError('An NLG message must start with a quotation mark!')