Merge pull request #557 from Frassle/parser

Two small Parser changes
This commit is contained in:
varon 2017-07-04 21:31:53 +02:00 committed by GitHub
commit a21549aa71
3 changed files with 14 additions and 20 deletions

View file

@ -47,8 +47,6 @@ namespace OpenTK.Convert
static readonly Regex ExtensionRegex = new Regex( static readonly Regex ExtensionRegex = new Regex(
@"3DFX|(?!(?<=[1-4])D)[A-Z]{2,}$", @"3DFX|(?!(?<=[1-4])D)[A-Z]{2,}$",
RegexOptions.Compiled); RegexOptions.Compiled);
string EnumPrefix { get { return Prefix.ToUpper() + "_"; } }
string FuncPrefix { get { return Prefix; } }
public GLXmlParser() public GLXmlParser()
{ {
@ -448,16 +446,6 @@ namespace OpenTK.Convert
return ret; return ret;
} }
string TrimName(string name)
{
if (name.StartsWith(EnumPrefix))
return name.Remove(0, EnumPrefix.Length);
else if (name.StartsWith(FuncPrefix))
return name.Remove(0, FuncPrefix.Length);
else
return name;
}
static string Join(string left, string right) static string Join(string left, string right)
{ {
if (!String.IsNullOrEmpty(left) && !String.IsNullOrEmpty(right)) if (!String.IsNullOrEmpty(left) && !String.IsNullOrEmpty(right))

View file

@ -68,15 +68,12 @@ namespace OpenTK.Convert
{ {
bool showHelp = false; bool showHelp = false;
string prefix = "gl"; string prefix = "gl";
string version = null;
string path = null; string path = null;
OptionSet opts = new OptionSet OptionSet opts = new OptionSet
{ {
{ "p=", "The {PREFIX} to remove from parsed functions and constants. " + { "p=", "The {PREFIX} to remove from parsed functions and constants. " +
"Defaults to \"" + prefix + "\".", "Defaults to \"" + prefix + "\".",
v => prefix = v }, v => prefix = v },
{ "v:", "The {VERSION} of the specification being parsed.",
v => version = v },
{ "o:", "The {PATH} to the output file.", { "o:", "The {PATH} to the output file.",
v => path = v }, v => path = v },
{ "?|h|help", "Show this message and exit.", { "?|h|help", "Show this message and exit.",
@ -86,7 +83,7 @@ namespace OpenTK.Convert
var app = Path.GetFileName(Environment.GetCommandLineArgs()[0]); var app = Path.GetFileName(Environment.GetCommandLineArgs()[0]);
if (showHelp) if (showHelp)
{ {
Console.WriteLine("usage: {0} -p:PREFIX -v:VERSION SPECIFICATIONS", app); Console.WriteLine("usage: {0} -p:PREFIX SPECIFICATIONS", app);
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Options:"); Console.WriteLine("Options:");
opts.WriteOptionDescriptions(Console.Out); opts.WriteOptionDescriptions(Console.Out);
@ -101,7 +98,7 @@ namespace OpenTK.Convert
return; return;
} }
Parser parser = new GLXmlParser { Prefix = prefix, Version = version }; Parser parser = new GLXmlParser { Prefix = prefix };
var sigs = headers.Select(h => parser.Parse(h)).ToList(); var sigs = headers.Select(h => parser.Parse(h)).ToList();

View file

@ -33,9 +33,8 @@ namespace OpenTK.Convert
{ {
// Defines a prefix that should be removed from methods and tokens in the XML files, e.g. "gl", "cl", etc. // Defines a prefix that should be removed from methods and tokens in the XML files, e.g. "gl", "cl", etc.
public string Prefix { get; set; } public string Prefix { get; set; }
public string EnumPrefix { get { return Prefix.ToUpper() + "_"; } }
// Defines the version of the spec files (optional). public string FuncPrefix { get { return Prefix; } }
public string Version { get; set; }
// Implements the parsing logic for a specific input file. // Implements the parsing logic for a specific input file.
public abstract IEnumerable<XElement> Parse(string[] lines); public abstract IEnumerable<XElement> Parse(string[] lines);
@ -82,5 +81,15 @@ namespace OpenTK.Convert
return Parse(contents); return Parse(contents);
} }
public string TrimName(string name)
{
if (name.StartsWith(EnumPrefix))
return name.Remove(0, EnumPrefix.Length);
else if (name.StartsWith(FuncPrefix))
return name.Remove(0, FuncPrefix.Length);
else
return name;
}
} }
} }