コード例 #1
0
        //
        // An @import directive
        //
        //     @import "lib";
        //
        // Depending on our environemnt, importing is done differently:
        // In the browser, it's an XHR request, in Node, it would be a
        // file-system operation. The function used for importing is
        // stored in `import`, which we pass to the Import constructor.
        //
        public Import Import(Parser parser)
        {
            Node path = null;

            var index = parser.Tokenizer.Location.Index;

            if (parser.Tokenizer.Match(@"@import\s+") && (path = Quoted(parser) || Url(parser)))
            {
                if (!parser.Tokenizer.Match(';'))
                {
                    throw new ParsingException("Expected ';'", parser.Tokenizer.Location.Index);
                }

                if (path is Quoted)
                {
                    return(NodeProvider.Import(path as Quoted, parser.Importer, index));
                }

                if (path is Url)
                {
                    return(NodeProvider.Import(path as Url, parser.Importer, index));
                }
            }

            return(null);
        }
コード例 #2
0
        //
        // An @import directive
        //
        //     @import "lib";
        //
        // Depending on our environemnt, importing is done differently:
        // In the browser, it's an XHR request, in Node, it would be a
        // file-system operation. The function used for importing is
        // stored in `import`, which we pass to the Import constructor.
        //
        public Import Import(Parser parser)
        {
            Node path = null;

            var index = parser.Tokenizer.Location.Index;

            if (parser.Tokenizer.Match(@"@import\s+") && (path = Quoted(parser) || Url(parser)))
            {
                var features = MediaFeatures(parser);

                if (!parser.Tokenizer.Match(';'))
                {
                    throw new ParsingException("Expected ';' (possibly unrecognised media sequence)", parser.Tokenizer.Location.Index);
                }

                if (path is Quoted)
                {
                    return(NodeProvider.Import(path as Quoted, parser.Importer, features, index));
                }

                if (path is Url)
                {
                    return(NodeProvider.Import(path as Url, parser.Importer, features, index));
                }

                throw new ParsingException("unrecognised @import format", index);
            }

            return(null);
        }