Beispiel #1
0
        private PathToken GetPropPathOrMath(Chunk chunk, List <string> propChain)
        {
            PathToken pathToken = null;

            if (propChain.Count() == 2 && propChain[0] == "Math")
            {
                pathToken = new MathToken(chunk.Start, chunk.End, propChain[1]);
            }
            else
            {
                pathToken = new PropertyPathToken(chunk.Start, chunk.End, propChain);
            }

            return(pathToken);
        }
        private PathToken GetPropPathOrMath(Chunk chunk, List <string> propChain, string relativeSourceDef)
        {
            PathToken pathToken = null;

            if (propChain.Count() == 2 && propChain[0] == "Math")
            {
                pathToken = new MathToken(chunk.Start, chunk.End, propChain[1]);
            }
            else
            {
                pathToken = new PropertyPathToken(chunk.Start, chunk.End, propChain);
            }
            pathToken.Id.RelativeSourceDef = relativeSourceDef;
            return(pathToken);
        }
Beispiel #3
0
        private bool GetPath(Chunk chunk, out PathToken pathToken)
        {
            var str = (string)chunk.Value;

            if (Keywords.Contains(str))
            {
                pathToken = null;
                return(false);
            }

            var colonPos = str.IndexOf(':');

            if (colonPos > 0)
            {
                var left = SubStr(str, 0, colonPos - 1);

                if (IsIdentifier(left))
                {
                    List <string> propChain;
                    if (GetPropChain(SubStr(str, colonPos + 1, str.Length - 1), out propChain))
                    {
                        if (propChain.Count() > 1)
                        {
                            pathToken = GetEnumOrStaticProperty(chunk, left, propChain);
                            return(true);
                        }
                    }
                }
            }
            else
            {
                List <string> propChain;
                if (GetPropChain(str, out propChain))
                {
                    pathToken = GetPropPathOrMath(chunk, propChain);
                    return(true);
                }
            }

            pathToken = null;
            return(false);
        }
Beispiel #4
0
        private PathToken GetEnumOrStaticProperty(Chunk chunk, string @namespace, List <string> identifierChain)
        {
            PathToken pathToken = null;
            Type      enumType;
            var       className     = identifierChain[0];
            string    fullClassName = string.Format("{0}:{1}", @namespace, className);

            var propertyChain = identifierChain.Skip(1).ToList();

            if (propertyChain.Count == 1 && ((enumType = TakeEnum(fullClassName)) != null))
            {
                // enum output
                var enumMember = propertyChain.Single();
                pathToken = new EnumToken(chunk.Start, chunk.End, @namespace, enumType, enumMember);
            }
            else
            {
                //static property path output
                pathToken = new StaticPropertyPathToken(chunk.Start, chunk.End, @namespace, className, propertyChain);
            }
            return(pathToken);
        }
Beispiel #5
0
 private void TracePath(PathToken path)
 {
     Tracer.TraceDebug(string.Format("Read {0} ({1}) ({2}-{3})", path.Id.Value, path.Id.PathType, path.Start, path.End));
 }
        private bool GetPath(Chunk chunk, out PathToken pathToken)
        {
            var str = (string)chunk.Value;

            if (Keywords.Contains(str))
            {
                pathToken = null;
                return(false);
            }

            // error check
            var    spiltByTypeDefArray = str.Split(new char[] { '@' });
            string relativeSourceDef   = null;

            if (spiltByTypeDefArray.Length == 1)
            {
            }
            else if (spiltByTypeDefArray.Length == 2)
            {
                if (spiltByTypeDefArray[0].Length == 0 || spiltByTypeDefArray[1].Length == 0)
                {
                    throw new Exception($"Wrong grammar on '{str}'");
                }

                str = spiltByTypeDefArray[0];
                relativeSourceDef = spiltByTypeDefArray[1];
            }
            else if (spiltByTypeDefArray.Length > 2)
            {
                throw new Exception($"Wrong grammar on '{str}'");
            }
            // no error


            var colonPos = str.IndexOf(':');

            if (colonPos > 0)
            {
                var left = SubStr(str, 0, colonPos - 1);

                if (IsIdentifier(left))
                {
                    List <string> propChain;
                    if (GetPropChain(SubStr(str, colonPos + 1, str.Length - 1), out propChain))
                    {
                        if (propChain.Count() > 1)
                        {
                            pathToken = GetEnumOrStaticProperty(chunk, left, propChain);
                            return(true);
                        }
                    }
                }
            }
            else
            {
                List <string> propChain;
                if (GetPropChain(str, out propChain))
                {
                    pathToken = GetPropPathOrMath(chunk, propChain, relativeSourceDef);
                    return(true);
                }
            }

            pathToken = null;
            return(false);
        }
Beispiel #7
0
 private void TracePath(PathToken path)
 {
     Debug.WriteLine(string.Format("PropertyPathAnalyzer: read {0} ({1}) ({2}-{3})", path.Id.Value, path.Id.PathType, path.Start, path.End));
 }