4 using System.Collections.Generic;
6 using System.Text.RegularExpressions;
7 using SiliconStudio.Shaders.Properties;
9 namespace SiliconStudio.Shaders.Convertor
19 private const string KeywordsFileName =
"keywords.glsl";
24 private static readonly Regex StripComments =
new Regex(
"//.*");
29 private static readonly HashSet<string>
Tokens =
new HashSet<string>();
44 var keywordFilePath = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(typeof (
GlslKeywords).Assembly.Location)), KeywordsFileName);
45 if (
File.Exists(keywordFilePath))
46 stream =
new FileStream(keywordFilePath,
FileMode.Open, FileAccess.Read);
48 if (stream == null) stream =
new MemoryStream(Resources.Keywords);
50 InitializeFromStream(stream);
53 Console.WriteLine(
"Unable to load keywords.glsl file. Reason: " + ex);
57 try { stream.Close(); }
catch {}
65 private static void InitializeFromStream(
Stream stream)
72 while ( (line = reader.ReadLine()) != null)
74 var newTokens = StripComments.Replace(line,
"").Trim().Split((
string[])null, StringSplitOptions.RemoveEmptyEntries);
75 foreach (var newToken
in newTokens)
89 return Tokens.Contains(identifier);
System.IO.FileMode FileMode
static bool IsReserved(string identifier)
Determines whether the specified identifier is a glsl reserved keyword.
Tokens
Summary Canonical example of MPLEX automaton