public TypeInspector(Snippets dataDeclaration)
        {
            string str    = dataDeclaration.ToString().Trim();
            int    length = str.LastIndexOfAny(new char[] { ' ', '\t', '\r', '\n' });

            if (length < 0)
            {
                this.Type = dataDeclaration;
            }
            else
            {
                this.Name = str.Substring(length + 1);
                if (!this.Name.ToString().ToCharArray().All <char>(delegate(char ch) {
                    if (!char.IsLetterOrDigit(ch) && (ch != '_'))
                    {
                        return(ch == '@');
                    }
                    return(true);
                }))
                {
                    this.Name = null;
                    this.Type = dataDeclaration;
                }
                else
                {
                    this.Type = str.Substring(0, length).Trim();
                }
            }
        }
 protected override void Visit(GlobalVariableChunk chunk)
 {
     if (!this._globalSymbols.ContainsKey((string)chunk.Name))
     {
         this._globalSymbols.Add((string)chunk.Name, null);
     }
     if (this._globalAdded.ContainsKey((string)chunk.Name))
     {
         if ((this._globalAdded[(string)chunk.Name].Type != chunk.Type) || (this._globalAdded[(string)chunk.Name].Value != chunk.Value))
         {
             throw new CompilerException(string.Format("The global named {0} cannot be declared repeatedly with different types or values", chunk.Name));
         }
     }
     else
     {
         Snippets snippets = chunk.Type ?? "object";
         string[] source   = snippets.ToString().Split(new char[] { ' ', '\t' });
         if (source.Contains <string>("const") || source.Contains <string>("readonly"))
         {
             this._source.WriteFormat("\r\n    {0} {1} = {2};", new object[] { snippets, chunk.Name, chunk.Value });
         }
         else
         {
             this._source.WriteFormat("\r\n    {0} _{1} = {2};\r\n    public {0} {1} {{ get {{return _{1};}} set {{_{1} = value;}} }}", new object[] { snippets, chunk.Name, chunk.Value });
         }
         this._source.WriteLine();
     }
 }
Пример #3
0
 public ForEachInspector(Snippets code)
 {
     var terms = code.ToString().Split(' ', '\r', '\n', '\t').ToList();
     var inIndex = terms.IndexOf("in");
     if (inIndex >= 1)
     {
         Recognized = true;
         VariableType = string.Join(" ", terms.ToArray(), 0, inIndex - 1);
         VariableName = terms[inIndex - 1];
         CollectionCode = string.Join(" ", terms.ToArray(), inIndex + 1, terms.Count - inIndex - 1);
     }
 }
        public ForEachInspector(Snippets code)
        {
            List <string> list  = code.ToString().Split(new char[] { ' ', '\r', '\n', '\t' }).ToList <string>();
            int           index = list.IndexOf("in");

            if (index >= 1)
            {
                this.Recognized     = true;
                this.VariableType   = string.Join(" ", list.ToArray(), 0, index - 1);
                this.VariableName   = list[index - 1];
                this.CollectionCode = string.Join(" ", list.ToArray(), index + 1, (list.Count - index) - 1);
            }
        }
Пример #5
0
        public ForEachInspector(Snippets code)
        {
            var terms   = code.ToString().Split(' ', '\r', '\n', '\t').ToList();
            var inIndex = terms.IndexOf("in");

            if (inIndex >= 1)
            {
                Recognized     = true;
                VariableType   = string.Join(" ", terms.ToArray(), 0, inIndex - 1);
                VariableName   = terms[inIndex - 1];
                CollectionCode = string.Join(" ", terms.ToArray(), inIndex + 1, terms.Count - inIndex - 1);
            }
        }
 private void Examine(Snippets code)
 {
     if (!Snippets.IsNullOrEmpty(code))
     {
         string str = code.ToString();
         foreach (Entry entry in this._entries)
         {
             if (!entry.Detected && str.Contains(entry.Expression))
             {
                 entry.Detected = true;
             }
         }
     }
 }
        public override Snippets Process(Chunk chunk, Snippets code)
        {
            if (code == null)
            {
                return(null);
            }

            var result = _grammar.ReformatCode(new Position(new SourceContext(code.ToString())));

            if (result == null)
            {
                return(code);
            }

            if (result.Rest.PotentialLength() == 0)
            {
                return(result.Value);
            }

            return(result.Value + result.Rest.Peek(result.Rest.PotentialLength()));
        }
Пример #8
0
        public TypeInspector(Snippets dataDeclaration)
        {
            var decl = dataDeclaration.ToString().Trim();
            var lastSpace = decl.LastIndexOfAny(new[] { ' ', '\t', '\r', '\n' });
            if (lastSpace < 0)
            {
                Type = dataDeclaration;
                return;
            }

            Name = decl.Substring(lastSpace + 1);

            if (!Name.ToString().ToCharArray().All(ch => char.IsLetterOrDigit(ch) || ch == '_' || ch == '@'))
            {
                Name = null;
                Type = dataDeclaration;
                return;
            }

            Type = decl.Substring(0, lastSpace).Trim();
        }
Пример #9
0
        void Examine(Snippets code)
        {
            if (Snippets.IsNullOrEmpty(code))
            {
                return;
            }

            var codeString = code.ToString();

            foreach (var entry in _entries)
            {
                if (entry.Detected)
                {
                    continue;
                }

                if (codeString.Contains(entry.Expression))
                {
                    entry.Detected = true;
                }
            }
        }
Пример #10
0
        public TypeInspector(Snippets dataDeclaration)
        {
            var decl      = dataDeclaration.ToString().Trim();
            var lastSpace = decl.LastIndexOfAny(new[] { ' ', '\t', '\r', '\n' });

            if (lastSpace < 0)
            {
                Type = dataDeclaration;
                return;
            }

            Name = decl.Substring(lastSpace + 1);

            if (!Name.ToString().ToCharArray().All(ch => char.IsLetterOrDigit(ch) || ch == '_' || ch == '@'))
            {
                Name = null;
                Type = dataDeclaration;
                return;
            }

            Type = decl.Substring(0, lastSpace).Trim();
        }
        void Examine(Snippets code)
        {
            if (Snippets.IsNullOrEmpty(code))
                return;

            var codeString = code.ToString();
            foreach(var entry in _entries)
            {
                if (entry.Detected)
                    continue;

                if (codeString.Contains(entry.Expression))
                    entry.Detected = true;
            }
        }