Пример #1
0
        internal CompilerClass(TsonStringNode assemblyNode, Assembly assembly, Type type, Type interfaceType)
        {
            this.Assembly  = assembly;
            this.Type      = type;
            this.Interface = interfaceType;
            this.Instance  = Activator.CreateInstance(this.Type);

            compilerParameters = new Dictionary <string, AttributedProperty>();
            targetParameters   = new Dictionary <string, AttributedProperty>();

            foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (propertyInfo.Name == "Target")
                {
                    this.TargetProperty = propertyInfo;
                }
                else if (propertyInfo.Name == "Context")
                {
                    this.ContextProperty = propertyInfo;
                }
                else if (propertyInfo.Name == "Extensions")
                {
                    this.ExtensionsProperty = propertyInfo;
                }
                else
                {
                    object[] attributes = propertyInfo.GetCustomAttributes(typeof(ContentCompilerParameterAttribute), true);
                    ContentCompilerParameterAttribute attribute;

                    if (attributes.Length == 1)
                    {
                        attribute = (ContentCompilerParameterAttribute)attributes[0];
                    }
                    else
                    {
                        continue;
                    }

                    if (!(propertyInfo.CanRead && propertyInfo.CanWrite))
                    {
                        throw new ContentFileException(
                                  assemblyNode, "Settings property '{0}' on '{1}' compiler must be read/write".CultureFormat(propertyInfo.Name, this.Name));
                    }

                    var property = new AttributedProperty(attribute, propertyInfo);

                    if (attribute.ForCompiler)
                    {
                        compilerParameters.Add(propertyInfo.Name, property);
                    }
                    else
                    {
                        targetParameters.Add(propertyInfo.Name, property);
                    }
                }
            }
        }
Пример #2
0
        internal CompilerClass(TsonStringNode assemblyNode, Assembly assembly, Type type, Type interfaceType)
        {
            this.Assembly = assembly;
            this.Type = type;
            this.Interface = interfaceType;
            this.Instance = Activator.CreateInstance(this.Type);

            compilerParameters = new Dictionary<string, AttributedProperty>();
            targetParameters = new Dictionary<string, AttributedProperty>();

            foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (propertyInfo.Name == "Target")
                {
                    this.TargetProperty = propertyInfo;
                }
                else if (propertyInfo.Name == "Context")
                {
                    this.ContextProperty = propertyInfo;
                }
                else if (propertyInfo.Name == "Extensions")
                {
                    this.ExtensionsProperty = propertyInfo;
                }
                else
                {
                    object[] attributes = propertyInfo.GetCustomAttributes(typeof(ContentCompilerParameterAttribute), true);
                    ContentCompilerParameterAttribute attribute;

                    if (attributes.Length == 1)
                        attribute = (ContentCompilerParameterAttribute)attributes[0];
                    else
                        continue;

                    if (!(propertyInfo.CanRead && propertyInfo.CanWrite))
                        throw new ContentFileException(
                            assemblyNode, "Settings property '{0}' on '{1}' compiler must be read/write".CultureFormat(propertyInfo.Name, this.Name));

                    var property = new AttributedProperty(attribute, propertyInfo);

                    if (attribute.ForCompiler)
                        compilerParameters.Add(propertyInfo.Name, property);
                    else
                        targetParameters.Add(propertyInfo.Name, property);
                }
            }
        }
Пример #3
0
        private TsonObjectNode ParseObject()
        {
            TsonToken token = tokenizer.Next();

            if (!token.IsLeftCurlyBrace)
                throw new TsonParseException(token, "Expected a '{'");

            var node = new TsonObjectNode() { Token = token };

            token = tokenizer.Next();

            if (token.IsRightCurlyBrace)
                return node;

            while (true)
            {
                if (!token.IsString)
                    throw new TsonParseException(token, "Expected a string");

                TsonStringNode key = new TsonStringNode(token.Data as string);

                token = tokenizer.Next();

                if (!token.IsColon)
                    throw new TsonParseException(token, "Expected a ':'");

                TsonNode value = ParseValueArrayOrObject();

                node.Add(key, value);

                token = tokenizer.Next();

                if (token.IsComma)
                {
                    token = tokenizer.Next();
                    continue;
                }
                else if (token.IsRightCurlyBrace)
                    break;
                else
                    throw new TsonParseException(token, "Expected a '}'");
            }

            return node;
        }
Пример #4
0
        private TsonNode ParseValue()
        {
            var token = tokenizer.Next();

            if (!token.IsString)
                throw new TsonParseException(token, "Expected a string");

            TsonStringNode stringNode = new TsonStringNode((string)token.Data) { Token = token };

            // See if we can more strongly type the node
            if (stringNode.IsQuoted)
                return stringNode;

            if (stringNode.Value == "null")
                return new TsonNullNode() { Token = token };

            if (stringNode.Value == "true")
                return new TsonBooleanNode(true) { Token = token };

            if (stringNode.Value == "false")
                return new TsonBooleanNode(false) { Token = token };

            double n;

            if (Double.TryParse(stringNode.Value, out n))
                return new TsonNumberNode(n) { Token = token };

            return stringNode;
        }
Пример #5
0
        private TsonObjectNode ParseRootObject()
        {
            TsonToken token = tokenizer.Next();
            bool hasLeftBrace = false;
            var node = new TsonObjectNode() { Token = token };

            if (token.IsLeftCurlyBrace)
            {
                hasLeftBrace = true;

                token = tokenizer.Next();

                if (token.IsRightCurlyBrace)
                    return node;
            }
            else if (token.IsEnd)
            {
                return node;
            }

            while (true)
            {
                if (!token.IsString)
                    throw new TsonParseException(token, "Expected a string");

                TsonStringNode key = new TsonStringNode(token.Data as string) { Token = token };

                token = tokenizer.Next();

                if (!token.IsColon)
                    throw new TsonParseException(token, "Expected a ':'");

                TsonNode value = ParseValueArrayOrObject();

                node.Add(key, value);

                token = tokenizer.Next();

                if (token.IsComma)
                {
                    token = tokenizer.Next();
                    continue;
                }
                else if (token.IsRightCurlyBrace)
                {
                    if (!hasLeftBrace)
                        throw new TsonParseException(token, "Root object did not have a '{' to match '}'");

                    break;
                }
                else if (token.IsEnd)
                {
                    if (hasLeftBrace)
                        throw new TsonParseException(token, "Expected '}'");

                    break;
                }
                else
                    throw new TsonParseException(token, "Expected ',' or EOF" + (hasLeftBrace ? ", or '}'" : ""));
            }

            return node;
        }
Пример #6
0
        protected override TsonNode VisitString(TsonStringNode node)
        {
            string s = node.Value.ToString()
                .Replace("\"", "\\\"")
                .Replace("\\", "\\\\")
                .Replace("/", "\\/")
                .Replace("\b", "\\b")
                .Replace("\f", "\\f")
                .Replace("\n", "\\n")
                .Replace("\r", "\\r")
                .Replace("\t", "\\t");

            sb.AppendFormat("\"{0}\"", s);

            return node;
        }
Пример #7
0
 public CompilerSetting(TsonStringNode name, TsonObjectNode parameters, List <ContentFileV4.CompilerExtension> extensions)
 {
     Name               = name;
     Parameters         = parameters;
     CompilerExtensions = extensions;
 }
Пример #8
0
        protected override TsonNode VisitString(TsonStringNode node)
        {
            if (node.IsQuoted)
                sb.AppendFormat("\"{0}\"", node.Value.ToString());
            else
                sb.Append(node.Value.ToString());

            return node;
        }
Пример #9
0
        protected override TsonNode VisitString(TsonStringNode node)
        {
            string s = node.Value.ToString()
                .Replace("\"", "&quot;")
                .Replace("'", "&apos;")
                .Replace("&", "&amp;")
                .Replace("<", "&lt;")
                .Replace(">", "&gt;")
                .Replace("\b", "&#x8;")
                .Replace("\f", "&#xC;")
                .Replace("\n", "&#xA;")
                .Replace("\r", "&#xD;")
                .Replace("\t", "&#x9");

            sb.AppendFormat("\"{0}\"", s);

            return node;
        }
Пример #10
0
 protected override TsonNode VisitString(TsonStringNode node)
 {
     action(node);
     return node;
 }
Пример #11
0
 protected virtual TsonNode VisitString(TsonStringNode node)
 {
     return node;
 }