コード例 #1
0
ファイル: Manager.cpp プロジェクト: abarbu/schemetex
void Manager::ProcessInput(const wstring& input, bool texvcCompatibility, bool displayStyle)
{
    // Here are all the commands which get "Reserved" tacked on the end
    // before the MacroProcessor sees them:

    static wstring reservedCommandArray[] =
    {
        L"\\sqrt",
        L"\\mbox",
        L"\\text",
        L"\\textit",
        L"\\textrm",
        L"\\textbf",
        L"\\textsf",
        L"\\texttt",
        L"\\jap",
        L"\\cyr",
        L"\\emph",
        L"\\frac",
        L"\\mathrm",
        L"\\mathbf",
        L"\\mathbb",
        L"\\mathit",
        L"\\mathcal",
        L"\\mathfrak",
        L"\\mathtt",
        L"\\mathsf",
        L"\\big",
        L"\\bigg",
        L"\\Big",
        L"\\Bigg",
        L"\\overset",
        L"\\underset",
        L"\\substack"
    };
    static wishful_hash_set<wstring> reservedCommandTable(
        reservedCommandArray,
        END_ARRAY(reservedCommandArray)
    );

    vector<wstring> inputTokens;
    Tokenise(input, inputTokens);

    mStrictSpacingRequested = false;

    // Check that the user hasn't supplied any input directly containing the
    // "Reserved" suffix, and add Reserved suffixes appropriately.
    //
    // Also search for magic commands (currently the only magic command is
    // "\strictspacing")
    for (vector<wstring>::iterator
        ptr = inputTokens.begin();
        ptr != inputTokens.end();
        ptr++
    )
    {
        if (reservedCommandTable.count(*ptr))
            *ptr += L"Reserved";

        else if (
            ptr->size() >= 8 &&
            ptr->substr(ptr->size() - 8, 8) == L"Reserved"
        )
            throw Exception(L"ReservedCommand", *ptr);

        else if (*ptr == L"\\strictspacing")
        {
            mStrictSpacingRequested = true;
            *ptr = L" ";
        }
    }

    vector<wstring> tokens;

    // Append the texvc-compatibility and standard macros where appropriate.

    if (texvcCompatibility)
        tokens = gTexvcCompatibilityMacrosTokenised;

    copy(
        gStandardMacrosTokenised.begin(),
        gStandardMacrosTokenised.end(),
        back_inserter(tokens)
    );
    copy(inputTokens.begin(), inputTokens.end(), back_inserter(tokens));

    // Generate the parse tree and the layout tree.
    Parser P;
    mParseTree = P.DoParse(tokens);
    mHasDelayedMathmlError = false;
    
    try
    {
        TexProcessingState topState;
        topState.mStyle = displayStyle ? LayoutTree::Node::cStyleDisplay : LayoutTree::Node::cStyleText;
        topState.mColour = 0;
        mLayoutTree = mParseTree->BuildLayoutTree(topState);
        mLayoutTree->Optimise();
    }
    catch (Exception& e)
    {
        // Some types of error need to returned as MathML errors, not
        // parsing errors.
        if (e.GetCode() == L"UnavailableSymbolFontCombination")
        {
            mHasDelayedMathmlError = true;
            mDelayedMathmlError = e;
            mLayoutTree.reset(NULL);
        }
        else
            throw e;
    }
}
コード例 #2
0
ファイル: cmd.c プロジェクト: rjc862003/Unvanquished
/*
===================
Cmd_UnquoteString

Usually passed a raw partial command string
String length is UNCHECKED
===================
*/
const char *Cmd_UnquoteString( const char *str )
{
	char *escapeBuffer = GetEscapeBuffer();
	Tokenise( str, escapeBuffer, qfalse, qfalse );
	return escapeBuffer;
}
コード例 #3
0
ファイル: script.cpp プロジェクト: rdmpage/forest
int main (int argc, const char * argv[]) 
{
	if (argc < 3)
	{
		cout << "Usage: script <graph-file-name> <script-file-name>" << endl;
		exit(1);
	}
	char filename[256];
	strcpy (filename, argv[1]);
	char script_filename[256];
	strcpy (script_filename, argv[2]);

  	// ---------------------------------------------------------	
  	// Read graph	

 	MyGraph G;
	
	GML_error err  = G.load (filename);
	if (err.err_num != GML_OK)
	{
		cerr << "Error (" << err.err_num << ") loading graph from file \"" << filename << "\"";
		switch (err.err_num)
		{
			case GML_FILE_NOT_FOUND: cerr << "A file with that name doesn't exist."; break;
			case GML_TOO_MANY_BRACKETS: cerr << "A mismatch of brackets was detected, i.e. there were too many closing brackets (])."; break;
			case GML_OPEN_BRACKET: cerr << "Now, there were too many opening brackets ([)";  break;
			case GML_TOO_MANY_DIGITS: cerr << "The number of digits a integer or floating point value can have is limited to 1024, this should be enough :-)";  break;
			case GML_PREMATURE_EOF: cerr << "An EOF occured, where it wasn't expected, e.g. while scanning a string."; break;
			case GML_SYNTAX: cerr << "The file isn't a valid GML file, e.g. a mismatch in the key-value pairs."; break;
			case GML_UNEXPECTED: cerr << "A character occured, where it makes no sense, e.g. non-numerical characters"; break;
			case GML_OK: break;
		}
		cerr << endl;
		exit(1);
	}
	else
	{
		cout << "Graph read from file \"" << filename << "\" has " << G.number_of_nodes() << " nodes and " << G.number_of_edges() << " edges" << endl;
	}
	
	
	// Output starting graph
	G.save_dot ("start.dot");


	// 1. Get map between labels and nodes
	std::map < std::string, GTL::node, std::less<std::string> > l; 
	node n;
	forall_nodes (n, G)
	{
		l[G.get_node_label(n)] = n;
	}
	
	// Read edit script
	{
		ifstream f (script_filename);
		char buf[512];
		
		while (f.good())
		{
			f.getline (buf, sizeof(buf));
			
			if (f.good())
			{
				
				// Break line into tokens
				std::vector<std::string> tokens;
				std::string s = buf;
				std::string delimiters = "|";
				Tokenise (s, delimiters, tokens);
				
				if (tokens[0] == "delete")
				{
					if (tokens[1] == "node")
					{
						string name = tokens[2];
						if (l.find(name) == l.end())
						{
							cout << "Node labelled \"" << name << "\" not found" << endl;
							exit(1);
						}
						else
						{
							cout << "Node \"" << name << "\" deleted" << endl;
							G.del_node(l[name]);
							l.erase(name);
						}
					}
					else if (tokens[1] == "branch")
					{
						string source = tokens[2];
						string target = tokens[3];
						if (l.find(source) == l.end())
						{
							cout << "Node labelled \"" << source << "\" not found" << endl;
							exit(1);
						}
						if (l.find(target) == l.end())
						{
							cout << "Node labelled \"" << target << "\" not found" << endl;
							exit(1);
						}
						cout << "Edge \"" << source << "\"-->\"" << target << "\" deleted" << endl;
						G.delete_edge(l[source], l[target]);
					}
				}
				if (tokens[0] == "insert")
				{
					if (tokens[1] == "node")
					{
						string name = tokens[2];
						node n = G.new_node();
						G.set_node_label (n, name);
						G.set_node_colour (n, "green");
						l[name] = n;
						cout << "Node \"" << name << "\" inserted" << endl;
					}
					else if (tokens[1] == "branch")
					{
						string source = tokens[2];
						string target = tokens[3];
						if (l.find(source) == l.end())
						{
							cout << "Node labelled \"" << source << "\" not found" << endl;
							exit(1);
						}
						if (l.find(target) == l.end())
						{
							cout << "Node labelled \"" << target << "\" not found" << endl;
							exit(1);
						}
						
						edge e = G.new_edge (l[source], l[target]);
						G.set_edge_colour (e, "green");
						
						cout << "Edge \"" << source << "\"-->\"" << target << "\" added" << endl;
					}
				}

			}			

		}
		f.close();
	}

	G.save_dot ("end.dot");


	
   return 0;
}