bool IsKeyword(LexerNode next) { var isKey = false; switch (next.Token) { case LexerTokens.Keyword: // ==== examples ==== // //struct GSInputLS {} //cbuffer ProjectionBuffer {} // ==== ++++++++ ==== // isKey = true; break; case LexerTokens.Identifier: // ==== examples ==== // //GSInputLS VShaderLines(VSInputLS input) { // ==== ++++++++ ==== // if (semantic.NewKeys.Contains(next.Value)) { isKey = true; } break; } return(isKey); }
public static void ThrowIfEmpty(this IEnumerable <LexerNode> lexers, LexerNode node) { if (!lexers.Any()) { throw new SyntaxException(node); } }
public static void ThrowIfNot(this LexerNode node, LexerTokens token) { if (node.Token != token) { throw new SyntaxException(node); } }
public static void ThrowIfNot(this LexerNode node, string _case) { if (node.Value != _case) { throw new SyntaxException(node); } }
public void UpdateVariables(LexerNode typeLex, LexerNode nameLex) { var name = nameLex.Value; UpdateVariables(nameLex); var type = typeLex.Value; if (!VariableTypesMapper.ContainsKey(name)) { VariableTypesMapper.Add(name, type); } }
internal IDisposable RegisterStruct(LexerNode lexer, StructNode node) { if (!CanRegisterGlobalFunction()) { throw new SemanticException($"Unavailable struct declaration '{lexer.Value}' inside another function '{currentRegistration.Name}'"); } var str = new StructGloalObject { Name = lexer, Node = node }; global.Add(lexer.Value, str); currentRegistration = new ScopeRegistration(lexer.Value, str); return(currentRegistration); }
internal IDisposable RegisterFunction(LexerNode lexer, FunctionDeclarationNode node) { if (!CanRegisterGlobalFunction()) { throw new SemanticException($"Unavailable function declaration '{lexer.Value}' inside another function '{currentRegistration.Name}'"); } var f = new FuncGloalObject { Name = lexer, Node = node }; global.Add(lexer.Value, f); scopes.Add(lexer.Value, f); currentRegistration = new ScopeRegistration(lexer.Value, f); return(currentRegistration); }
public void UpdateVariables(LexerNode nameLex) { var names = nameLex.Value.Split('.'); var offset = 0; for (int i = 0; i < names.Length; i++) { var name = names[i]; if (!funcOrVarNameLexerMapper.TryGetValue(name, out var list)) { list = new List <LexerNode>(); funcOrVarNameLexerMapper.Add(name, list); } list.Add(new LexerNode(nameLex.Token, name, nameLex.StartPointer.GetPositionAtOffset(offset))); offset += name.Length + 1;//+1 is dot element } }
static void ApplyForegroundValue(LexerNode lexer) { var tp = lexer.StartPointer; var range = new TextRange(tp, tp.GetPositionAtOffset(lexer.Value.Length)); Brush brush; switch (lexer.Token) { case LexerTokens.Number: brush = NumereticBrush; break; case LexerTokens.String: brush = StringBrush; break; default: return; } range.ApplyPropertyValue(TextElement.ForegroundProperty, brush); }
Queue <LexerNode> SeparateExpression(Queue <LexerNode> lexers, out LexerNode op) { var left = new Queue <LexerNode>(); op = null;//custom.t = float2(dx / abs(dx), dy / abs(dy)); var bracket = 0; while (lexers.Any()) { var lex = lexers.Dequeue(); switch (lex.Token) { case LexerTokens.Punctuation: switch (lex.Value) { case ShaderSyntaxInfo.StartFuncDeclaration: bracket++; break; case ")": bracket--; break; } break; case LexerTokens.Operator: if (bracket == 0) { op = lex; return(left); } break; } left.Enqueue(lex); } return(left); }
static void ApplyFontWeight(LexerNode lexer, FontWeight ft) { GetRange(lexer).ApplyPropertyValue(TextElement.FontWeightProperty, ft); }
protected override void OnIgnored(LexerNode lex) { Comments.Add(lex); }
protected abstract void OnIgnored(LexerNode lex);
public SyntaxException(LexerNode current) { Lexer = current; }
public void UnHighlightSelection(LexerNode lexer) { ApplyFontWeight(lexer, FontWeights.Normal); //ApplyBackgroundValue(lexer, Brushes.Transparent); }
protected Boundary DelimitedBy(Queue <LexerNode> lexer, DelimeterParams _params, ListNode node, Func <Queue <LexerNode>, AbstractNode> parser) { var boundary = new Boundary(); boundary.StartPointer = lexer.Peek(); if (_params.IsStart != null && !_params.IsStart(lexer.Dequeue())) //incorect declaration { throw new SyntaxException(lexer.Peek()); } var blocks = new Queue <LexerNode>(); LexerNode next = null; var bracket = 1; do { lexer.ThrowIfEmpty(next ?? boundary.StartPointer); next = lexer.Dequeue(); if (next.Token == LexerTokens.Comment) { //OnIgnored(next); node.Add(new CommentsNode() { Lex = next }); continue; } if (_params.IsStart != null && _params.IsStart(next)) { bracket++; } if ((_params.IsSeparator(next) && bracket == 1) || !lexer.Any()) { if (blocks.Any()) { node.Add(parser(blocks)); blocks.ThrowIfAny(); } continue; } if (_params.IsStop(next)) { bracket--; if (bracket == 0) { if (blocks.Any()) { node.Add(parser(blocks)); blocks.ThrowIfAny(); } } } blocks.Enqueue(next); } while (bracket != 0 && lexer.Any()); boundary.EndPointer = next; return(boundary); }
static void ApplyBackgroundValue(LexerNode lexer, Brush brush) { GetRange(lexer).ApplyPropertyValue(TextElement.BackgroundProperty, brush); }
public static void ThrowSyntaxException(this LexerNode node) { throw new SyntaxException(node); }
static TextRange GetRange(LexerNode lexer) { var tp = lexer.StartPointer; return(new TextRange(tp, tp.GetTextPointAt(lexer.Value.Length)));// tp.GetPositionAtOffset(lexer.Value.Length)); }
public bool IsSemicolon(LexerNode lex) { return(Semicolon == lex.Value); }
public void HighlightSelection(LexerNode lexer) { ApplyFontWeight(lexer, FontWeights.Bold); //ApplyBackgroundValue(lexer, Brushes.LightBlue); }