Beispiel #1
0
        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);
        }
Beispiel #2
0
 public static void ThrowIfEmpty(this IEnumerable <LexerNode> lexers, LexerNode node)
 {
     if (!lexers.Any())
     {
         throw new SyntaxException(node);
     }
 }
Beispiel #3
0
 public static void ThrowIfNot(this LexerNode node, LexerTokens token)
 {
     if (node.Token != token)
     {
         throw new SyntaxException(node);
     }
 }
Beispiel #4
0
 public static void ThrowIfNot(this LexerNode node, string _case)
 {
     if (node.Value != _case)
     {
         throw new SyntaxException(node);
     }
 }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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
            }
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
 static void ApplyFontWeight(LexerNode lexer, FontWeight ft)
 {
     GetRange(lexer).ApplyPropertyValue(TextElement.FontWeightProperty, ft);
 }
Beispiel #12
0
 protected override void OnIgnored(LexerNode lex)
 {
     Comments.Add(lex);
 }
Beispiel #13
0
 protected abstract void OnIgnored(LexerNode lex);
Beispiel #14
0
 public SyntaxException(LexerNode current)
 {
     Lexer = current;
 }
Beispiel #15
0
 public void UnHighlightSelection(LexerNode lexer)
 {
     ApplyFontWeight(lexer, FontWeights.Normal);
     //ApplyBackgroundValue(lexer, Brushes.Transparent);
 }
Beispiel #16
0
        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);
        }
Beispiel #17
0
 static void ApplyBackgroundValue(LexerNode lexer, Brush brush)
 {
     GetRange(lexer).ApplyPropertyValue(TextElement.BackgroundProperty, brush);
 }
Beispiel #18
0
 public static void ThrowSyntaxException(this LexerNode node)
 {
     throw new SyntaxException(node);
 }
Beispiel #19
0
        static TextRange GetRange(LexerNode lexer)
        {
            var tp = lexer.StartPointer;

            return(new TextRange(tp, tp.GetTextPointAt(lexer.Value.Length)));// tp.GetPositionAtOffset(lexer.Value.Length));
        }
Beispiel #20
0
 public bool IsSemicolon(LexerNode lex)
 {
     return(Semicolon == lex.Value);
 }
Beispiel #21
0
 public void HighlightSelection(LexerNode lexer)
 {
     ApplyFontWeight(lexer, FontWeights.Bold);
     //ApplyBackgroundValue(lexer, Brushes.LightBlue);
 }