Example #1
0
        public Type Resolve(TypeContext typeContext)
        {
            var index = _name.LastIndexOf('.');

            // if name contains dots, then this is a namespace qualified name
            if (index != -1)
            {
                Type type = typeContext.GetByFullName(_name);

                // throw if type wasn't found
                if (type == null)
                    throw new TypeNotFoundException("There is no type {0}", _name);
            }

            // check that this name not exists in global namespase:
            Type resolvedType = typeContext.GetByFullName(_name);
            if (resolvedType != null)
                return resolvedType;

            // try to find type walking through all usings
            foreach (var @using in _usings)
            {
                var typeName = Utils.ConcatNamespaces(@using, _name);
                Type type = typeContext.GetByFullName(typeName);
                if (type != null)
                    return type;
            }

            throw new TypeNotFoundException("There is no type {0}. The following namespaces were checked: {1}", _name, String.Join(", ", _usings));
        }
Example #2
0
 /// <summary>
 /// Protected initialization
 /// </summary>
 public FieldInfo(TypeContext typeContext, Int32 index, String name, TypeResolver typeResolver, FieldQualifier qualifier, Object defaultValue)
 {
     _typeContext = typeContext;
     _index = index;
     _name = name;
     _qualifier = qualifier;
     _typeResolver = typeResolver;
     _defaultValue = defaultValue;
 }
Example #3
0
        public TypeContext Build(String[] filePaths)
        {
            if (filePaths.Length <= 0)
                throw new SchematraException("Files were not specified");

            var typeContext = new TypeContext();
            var context = new Context(typeContext);

            foreach (var filePath in filePaths)
            {
                var tree = BuildParseTree(filePath);

                try
                {
                    ParseUnit(tree, context);
                    return typeContext;
                }
                catch (Exception ex)
                {
                    var errorMessage = "Unaxpected exception while parsing schema file";

                    if (_currentNode != null)
                        errorMessage = BuildErrorMessage(ex.Message, filePath, _currentNode.Span.Location.Line + 1, _currentNode.Span.Location.Column);

                    throw new SchematraException(errorMessage);
                }
            }

            throw new SchematraException("Files were not specified");
        }
Example #4
0
 public Context(TypeContext typeContext)
 {
     _typeContext = typeContext;
 }
Example #5
0
 protected EnumType(TypeContext typeContext)
     : base(typeContext)
 {
 }
Example #6
0
 /// <summary>
 /// Initialization
 /// </summary>
 protected Type(TypeContext typeContext)
 {
     _typeContext = typeContext;
 }
Example #7
0
 protected RecordType(TypeContext typeContext)
     : base(typeContext)
 {
 }
Example #8
0
 public EnumTypeBuilder(TypeContext typeContext)
     : base(typeContext)
 {
 }
Example #9
0
 public RecordTypeBuilder(TypeContext typeContext)
     : base(typeContext)
 {
 }
 public PrimitiveTypeBuilder(TypeContext typeContext)
     : base(typeContext)
 {
 }
Example #11
0
 /// <summary>
 /// Initialization
 /// </summary>
 public Parser(CompilationDefinition compilation)
 {
     _compilation = compilation;
     _context = new TypeContext();
 }