Пример #1
0
    def GetValueAsTokens(self, expand_tok):
        exp_location = _pc_utils.TokSource(expand_tok)
        value = '"' + _pc_utils.BoxStringHigh(self._GetStringValue()) + '"'
        result_token = (_pc_utils.token_flags.k_trivial_flag,
                        _pc_utils.primitive_tokens.kString, [value
                                                             ], exp_location)

        return [result_token]
Пример #2
0
    def GetValueAsTokens(self, expand_tok):
        exp_location = _pc_utils.TokSource(expand_tok)
        value = str(
            self._GetNumberValue(exp_location)
        )  #TODO: make lexer number tokens actual numbers not string
        result_token = (_pc_utils.token_flags.k_trivial_flag,
                        _pc_utils.primitive_tokens.kNumber, [value
                                                             ], exp_location)

        return [result_token]
Пример #3
0
    def _evaluate_functions_with_string_arg(self, tok, toktype, unboxed_str):

        if toktype == _cmd_tokens.k_include:
            self.precompiler.open_file_and_include(unboxed_str, tok)
        elif toktype == _cmd_tokens.k_inline_include:
            self.assembler.Write(
                (_token_flags.k_trivial_flag, _primitive_toks.kInlined,
                 [self.precompiler.open_file_and_get_str(unboxed_str, tok)],
                 _pc_utils.TokSource(tok)))
        elif toktype == _cmd_tokens.k_inline_str:
            self.assembler.Write(
                (_token_flags.k_trivial_flag, _primitive_toks.kInlined,
                 [unboxed_str], _pc_utils.TokSource(tok)))
        elif toktype == _cmd_tokens.k_error:
            self.precompiler.RaiseErrorOnToken(tok, "User #error!",
                                               unboxed_str)
        else:
            assert False, "Internal Error"

        return self
Пример #4
0
 def _evaluate_source_id(self, tok, _id):
     if _id == 'once':
         source_file = self.precompiler.input_state.GetActiveSourceFile()
         self.precompiler.file_interface.StashFileContent(source_file)
     elif _id == 'dup':
         source_file = self.precompiler.input_state.GetActiveSourceFile()
         self.precompiler.file_interface.StashFileContent(source_file)
     elif _id == 'break':
         self.precompiler._break_file_unit()
     elif _id == 'info':
         file_info = self._create_file_info(tok)
         self.assembler.Write(
             (_token_flags.k_trivial_flag, _primitive_toks.kInlined,
              [file_info], _pc_utils.TokSource(tok)))
     else:
         self.precompiler.RaiseErrorOnToken(tok, "Unknown #source token!",
                                            "Value `" + _id + "`")
Пример #5
0
    def _run_command(self, tok, inline_content):
        result = self.precompiler._evaluate_tok(tok)
        if (result != None):
            if inline_content == True:
                self.assembler.Write(
                    (_token_flags.k_trivial_flag, _primitive_toks.kInlined,
                     [str(result)], _pc_utils.TokSource(tok)))
            else:
                #todo: make function in pre
                tokens = self.precompiler.file_interface.RetokenizeContent(
                    str(result), tok)
                next_iterator = _impl_pc_iterator.GeneratedTokenInterator(
                    tokens)

                if self.precompiler.input_state.PushState(next_iterator,
                                                          None) == False:
                    self.precompiler.RaiseErrorOnToken(
                        tok, "Stack overflow while executin #run!", None)
Пример #6
0
	def open_file_and_inline_include(self,assembler,strval,tok, no_error_on_failed_to_load):

		(file_handle_obj, abs_file_path) = self._get_file_handle(strval, tok, no_error_on_failed_to_load)
		if file_handle_obj == None:
			return

		self.mark_dependency(abs_file_path,file_handle_obj)

		assembler.Write((_token_flags.k_trivial_flag,_primitive_toks.kInlined,[file_handle_obj.get_file_content()],_pc_utils.TokSource(tok)))
Пример #7
0
	def _evaluate_functions_with_string_arg(self,tok,toktype,unboxed_str,noerror_flag):

		if toktype == _cmd_tokens.k_include:
			self.precompiler.open_file_and_include(unboxed_str,tok,noerror_flag)
		elif toktype == _cmd_tokens.k_load_config:
			self.precompiler.open_and_load_config_file(unboxed_str,tok)
		elif toktype == _cmd_tokens.k_inline_include:
			#inline write directly to output
			self.precompiler.open_file_and_inline_include(self.assembler,unboxed_str,tok,noerror_flag)
			#if file_content_str != None:
			#	self.assembler.Write((_token_flags.k_trivial_flag,_primitive_toks.kInlined,[file_content_str],_pc_utils.TokSource(tok)))
		elif toktype == _cmd_tokens.k_inline_str:
			self.assembler.Write((_token_flags.k_trivial_flag,_primitive_toks.kInlined,[unboxed_str],_pc_utils.TokSource(tok)))
		elif toktype == _cmd_tokens.k_error:
			self.precompiler.RaiseErrorOnToken(tok,"User #error!",unboxed_str)
		else:
			assert False, "Internal Error [" + str(toktype) + "]"

		return self
Пример #8
0
 def RetokenizeContent(self, content_str, inherited_token):
     file = _pc_utils.TokSource(inherited_token)[0]
     return self.lexer_interface.StringTokenize(file, content_str,
                                                inherited_token)