示例#1
0
    def EndLiteralExpression(self, **_):
        if len(self.stack) <= 1:
            raise lexer.ParseError(
                "Unbalanced literal sequence: Can not expand '%s'" %
                self.processed_buffer)

        arg = self.stack.pop(-1)
        self.stack[-1] += arg
示例#2
0
  def ExpandArg(self, **_):
    """Expand the args as a section.parameter from the config."""
    # This function is called when we see close ) and the stack depth has to
    # exactly match the number of (.
    if len(self.stack) <= 1:
      raise lexer.ParseError(
          "Unbalanced parenthesis: Can not expand '%s'" % self.processed_buffer)

    # This is the full parameter name: e.g. Logging.path
    parameter_name = self.stack.pop(-1)
    if "." not in parameter_name:
      parameter_name = "%s.%s" % (self.default_section, parameter_name)

    final_value = self.config.Get(parameter_name, context=self.context)
    if final_value is None:
      final_value = ""

    type_info_obj = (self.config.FindTypeInfo(parameter_name) or
                     type_info.String())

    # Encode the interpolated string according to its type.
    self.stack[-1] += type_info_obj.ToString(final_value)
示例#3
0
    def Parse(self):
        self.Close()
        if len(self.stack) != 1:
            raise lexer.ParseError("Nested expression not balanced.")

        return self.stack[0]