Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
NShaderScanner.cs
Go to the documentation of this file.
1 #region Header Licence
2 // ---------------------------------------------------------------------
3 //
4 // Copyright (c) 2009 Alexandre Mutel and Microsoft Corporation.
5 // All rights reserved.
6 //
7 // This code module is part of NShader, a plugin for visual studio
8 // to provide syntax highlighting for shader languages (hlsl, glsl, cg)
9 //
10 // ------------------------------------------------------------------
11 //
12 // This code is licensed under the Microsoft Public License.
13 // See the file License.txt for the license details.
14 // More info on: http://nshader.codeplex.com
15 //
16 // ------------------------------------------------------------------
17 #endregion
18 using NShader.Lexer;
19 using Microsoft.VisualStudio.Package;
20 
21 namespace NShader
22 {
23  public class NShaderScanner : IScanner
24  {
25  private Scanner lex;
26 
27  public NShaderScanner(IShaderTokenProvider tokenProvider)
28  {
29  lex = new Scanner();
30  lex.ShaderTokenProvider = tokenProvider;
31  }
32 
33  public void SetSource(string source, int offset)
34  {
35  lex.SetSource(source, offset);
36  }
37 
38  public Scanner Lexer
39  {
40  get
41  {
42  return lex;
43  }
44  }
45 
46  public bool ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state)
47  {
48 
49  int start, end;
50  ShaderToken token = (ShaderToken)lex.GetNext(ref state, out start, out end);
51 
52  // !EOL and !EOF
53  if (token != ShaderToken.EOF)
54  {
55  tokenInfo.StartIndex = start;
56  tokenInfo.EndIndex = end;
57 
58  switch (token)
59  {
60  case ShaderToken.KEYWORD:
61  case ShaderToken.TYPE:
62  case ShaderToken.KEYWORD_FX:
63  tokenInfo.Color = TokenColor.Keyword;
64  tokenInfo.Type = TokenType.Keyword;
65  break;
66  case ShaderToken.COMMENT:
67  tokenInfo.Color = TokenColor.Comment;
68  tokenInfo.Type = TokenType.Comment;
69  break;
70  case ShaderToken.COMMENT_LINE:
71  tokenInfo.Color = TokenColor.Comment;
72  tokenInfo.Type = TokenType.LineComment;
73  break;
74  case ShaderToken.NUMBER:
75  case ShaderToken.FLOAT:
76  tokenInfo.Color = TokenColor.Number;
77  tokenInfo.Type = TokenType.Literal;
78  break;
79  case ShaderToken.STRING_LITERAL:
80  tokenInfo.Color = TokenColor.String;
81  tokenInfo.Type = TokenType.Literal;
82  break;
83  case ShaderToken.INTRINSIC:
84  // hugly. TODO generate a NShaderTokenColor to keep tracks of 6-7-8 TokenColors
85  tokenInfo.Color = (TokenColor)6;
86  tokenInfo.Type = TokenType.Identifier;
87  break;
88  case ShaderToken.KEYWORD_SPECIAL:
89  tokenInfo.Color = (TokenColor)7;
90  tokenInfo.Type = TokenType.Identifier;
91  break;
92  case ShaderToken.PREPROCESSOR:
93  tokenInfo.Color = (TokenColor)8;
94  tokenInfo.Type = TokenType.Keyword;
95  break;
96  default:
97  tokenInfo.Color = TokenColor.Text;
98  tokenInfo.Type = TokenType.Text;
99  break;
100  }
101  return true;
102  }
103  return false;
104  }
105  }
106 }
void SetSource(string source, int offset)
int GetNext(ref int state, out int start, out int end)
NShaderScanner(IShaderTokenProvider tokenProvider)
bool ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state)