Exemplo n.º 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);
        }
Exemplo n.º 2
0
 public static void ThrowIfEmpty(this IEnumerable <LexerNode> lexers, LexerNode node)
 {
     if (!lexers.Any())
     {
         throw new SyntaxException(node);
     }
 }
Exemplo n.º 3
0
 public static void ThrowIfNot(this LexerNode node, LexerTokens token)
 {
     if (node.Token != token)
     {
         throw new SyntaxException(node);
     }
 }
Exemplo n.º 4
0
 public static void ThrowIfNot(this LexerNode node, string _case)
 {
     if (node.Value != _case)
     {
         throw new SyntaxException(node);
     }
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 11
0
 static void ApplyFontWeight(LexerNode lexer, FontWeight ft)
 {
     GetRange(lexer).ApplyPropertyValue(TextElement.FontWeightProperty, ft);
 }
Exemplo n.º 12
0
 protected override void OnIgnored(LexerNode lex)
 {
     Comments.Add(lex);
 }
Exemplo n.º 13
0
 protected abstract void OnIgnored(LexerNode lex);
Exemplo n.º 14
0
 public SyntaxException(LexerNode current)
 {
     Lexer = current;
 }
Exemplo n.º 15
0
 public void UnHighlightSelection(LexerNode lexer)
 {
     ApplyFontWeight(lexer, FontWeights.Normal);
     //ApplyBackgroundValue(lexer, Brushes.Transparent);
 }
Exemplo n.º 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);
        }
Exemplo n.º 17
0
 static void ApplyBackgroundValue(LexerNode lexer, Brush brush)
 {
     GetRange(lexer).ApplyPropertyValue(TextElement.BackgroundProperty, brush);
 }
Exemplo n.º 18
0
 public static void ThrowSyntaxException(this LexerNode node)
 {
     throw new SyntaxException(node);
 }
Exemplo n.º 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));
        }
Exemplo n.º 20
0
 public bool IsSemicolon(LexerNode lex)
 {
     return(Semicolon == lex.Value);
 }
Exemplo n.º 21
0
 public void HighlightSelection(LexerNode lexer)
 {
     ApplyFontWeight(lexer, FontWeights.Bold);
     //ApplyBackgroundValue(lexer, Brushes.LightBlue);
 }