Expression ExpressionBuilder::Build(std::string expression) {
	TokenList tokens = m_tokenizer(expression);

	TokenList postfix = m_converter(tokens);

	std::stack<ExpressionNode*> nodeStk;

	auto it = postfix.begin();

	nodeStk.push(m_nodeBuilder.NewExpressionNode(*it));

	while (++it != postfix.end()) {
		ExpressionNode* node = m_nodeBuilder.NewExpressionNode(*it);

		switch (node->NumChildren()) {
		case 0:
			nodeStk.push(node);
			break;
		case 1:
			static_cast<OperatorNode*>(node)->SetChild(nodeStk.top());
			nodeStk.pop();
			nodeStk.push(node);
			break;
		case 2:
			static_cast<OperatorNode*>(node)->SetChild(nodeStk.top(), 1);
			nodeStk.pop();
			static_cast<OperatorNode*>(node)->SetChild(nodeStk.top(), 0);
			nodeStk.pop();
			nodeStk.push(node);
			break;
		}
	}

	return{ nodeStk.top(),  m_nodeBuilder.GetVariableMap() };
}
示例#2
0
RTFStatus RTFReader::Paragraph(void)
{
	// MW-2012-03-14: [[ RtfParaStyles ]] Build the paragraph style record up
	//   to apply to the new paragraph.
	MCTextParagraph t_para;
	memset(&t_para, 0, sizeof(MCTextParagraph));
	t_para . text_align = m_state . GetTextAlign();
	t_para . border_width = twips_to_pixels(m_state . GetBorderWidth());
	t_para . padding = twips_to_pixels(m_state . GetPadding());
	t_para . first_indent = twips_to_pixels(m_state . GetFirstIndent());
	t_para . left_indent = twips_to_pixels(m_state . GetLeftIndent());
	t_para . right_indent = twips_to_pixels(m_state . GetRightIndent());
	t_para . space_above = twips_to_pixels(m_state . GetSpaceAbove());
	t_para . space_below = twips_to_pixels(m_state . GetSpaceBelow());
	t_para . background_color = m_state . GetParagraphBackgroundColor();
	t_para . border_color = m_state . GetBorderColor();
	t_para . metadata = m_state . GetParagraphMetadata();

	if (m_lists . Count() == 0 || m_state . GetListStyle() == kMCTextListStyleSkip)
	{
		t_para . list_style = m_state . GetListStyle();
		t_para . list_depth = m_state . GetListLevel() + 1;
	}
	else if (m_state . GetListIndex() != 0)
	{
		int4 t_list_id;
		if (m_overrides . Get(m_state . GetListIndex(), t_list_id))
		{
			uint32_t t_level;
			t_level = m_state . GetListLevel();

			MCTextListStyle t_style;
			if (m_lists . Get(t_list_id, t_level + 1, t_style))
			{
				t_para . list_style = t_style;
				t_para . list_depth = t_level + 1;
			}
		}
	}

	m_converter(m_converter_context, &t_para, NULL);
	
	return kRTFStatusSuccess;
}
示例#3
0
RTFStatus RTFReader::Flush(bool p_force)
{
	RTFStatus t_status;
	t_status = kRTFStatusSuccess;

	if (!m_attributes_changed && !p_force)
		return t_status;

	MCTextBlock t_block;
	bool t_changed;
	t_changed = false;
	if (m_attributes_changed)
	{
		t_block . foreground_color = m_state . GetForegroundColor();
		t_block . background_color = m_state . GetBackgroundColor();
		t_block . font_name = m_state . GetFontName();
		if (m_state . GetFontSize() != 0)
			t_block . font_size = half_points_to_pixels(m_state . GetFontSize());
		else
			t_block . font_size = 0;
		
		t_block . font_style = FA_DEFAULT_STYLE;
		if ((m_state . GetFontStyle() & kRTFFontStyleItalic) != 0)
			t_block . font_style |= FA_ITALIC;
		if ((m_state . GetFontStyle() & kRTFFontStyleBold) != 0)
			t_block . font_style |= FA_BOLD;
		if ((m_state . GetFontStyle() & kRTFFontStyleUnderline) != 0)
			t_block . font_style |= FA_UNDERLINE;
		if ((m_state . GetFontStyle() & kRTFFontStyleStrikethrough) != 0)
			t_block . font_style |= FA_STRIKEOUT;
		if ((m_state . GetFontStyle() & kRTFFontStyleLink) != 0)
			t_block . font_style |= FA_LINK;

		if ((m_state . GetFontStyle() & kRTFFontStyleSuperscript) != 0)
			t_block . text_shift = -4;
		else if ((m_state . GetFontStyle() & kRTFFontStyleSubscript) != 0)
			t_block . text_shift = 4;
		else
			t_block . text_shift = 0;
		
		if (m_state . GetHyperlink() != kMCEmptyName)
			MCNameClone(m_state . GetHyperlink(), t_block . text_link);
		else
			t_block . text_link = nil;

		if (m_state . GetMetadata() != kMCEmptyName)
			MCNameClone(m_state . GetMetadata(), t_block . text_metadata);
		else
			t_block . text_metadata = nil;

		t_block . string_native = false;
		t_block . string_buffer = NULL;
		t_block . string_length = 0;

		if (t_block . foreground_color != m_attributes . foreground_color ||
			t_block . background_color != m_attributes . background_color ||
			t_block . font_size != m_attributes . font_size ||
			t_block . font_style != m_attributes . font_style ||
			t_block . text_shift != m_attributes . text_shift ||
			CStringCompare(t_block . font_name, m_attributes . font_name) != 0 ||
			t_block . text_link != m_attributes . text_link ||
			t_block . text_metadata != m_attributes . text_metadata)
			t_changed = true;
	}

	const uint2 *t_string_buffer;
	uint4 t_string_length;
	if (t_status == kRTFStatusSuccess)
		t_status = m_text . Borrow(t_string_buffer, t_string_length);

	if (t_status == kRTFStatusSuccess && t_string_length > 0 && (t_changed || p_force))
	{
		if (m_needs_paragraph)
		{
			m_needs_paragraph = false;

			// MW-2012-03-14: [[ RtfParaStyles ]] Use the 'Paragraph()' method to ensure
			//   paragraph styles get applied.
			Paragraph();
		}

		m_attributes . string_native = false;
		m_attributes . string_buffer = t_string_buffer;
		m_attributes . string_length = t_string_length / 2;
		m_converter(m_converter_context, NULL, &m_attributes);
		m_text . Clear();
	}

	if (t_changed)
	{
		MCNameDelete(m_attributes . text_metadata);
		MCNameDelete(m_attributes . text_link);
		memcpy(&m_attributes, &t_block, sizeof(MCTextBlock));
		m_attributes_changed = false;
	}

	return t_status;
}
示例#4
0
 result_type operator()() const { return m_converter(); }