Parses and returns all sections in given CSS
as tree-like structure, e.g. provides nesting
info
@param  {String} content CSS content
@return {CSSSection}
180536
function(content) {
			var root = new CSSSection(null, content);
			var rules = this.findAllRules(content);

			// rules are sorted in order they appear in CSS source
			// so we can optimize their nesting routine
			var insert = function(range, ctx) {
				while (ctx && ctx.range) {
					if (ctx.range.contains(range)) {
						return ctx.addChild(range);
					}

					ctx = ctx.parent;
				}

				// if we are here then given range is a top-level section
				return root.addChild(range);
			};

			var ctx = root;
			rules.forEach(function(r) {
				ctx = insert(r, ctx);
			});

			return root;
		}
155700
function processSection(section, config, parentDepth) {
	const contentRelativePath = section.content

	// Try to load section content file
	let content
	if (contentRelativePath) {
		const contentAbsolutePath = path.resolve(config.configDir, contentRelativePath)
		if (!fs.existsSync(contentAbsolutePath)) {
			throw new Error(`Styleguidist: Section content file not found: ${contentAbsolutePath}`)
		}
		content = requireIt(`!!${examplesLoader}?customLangs=vue|js|jsx!${contentAbsolutePath}`)
	}

	let sectionDepth

	if (parentDepth === undefined) {
		sectionDepth = section.sectionDepth !== undefined ? section.sectionDepth : 0
	} else {
		sectionDepth = parentDepth === 0 ? 0 : parentDepth - 1
	}

	return {
		name: section.name,
		exampleMode: section.exampleMode || config.exampleMode,
		usageMode: section.usageMode || config.usageMode,
		sectionDepth,
		description: section.description,
		slug: slugger.slug(section.name),
		sections: getSections(section.sections || [], config, sectionDepth),
		filepath: contentRelativePath,
		href: section.href,
		components: getSectionComponents(section, config),
		content,
		external: section.external
	}
}
629665
function parseCSSSelector(selector) {
    const match = SELECTOR_RE.exec(selector);
    if (!match) {
        throw new Error("Unsupported or invalid CSS selector: " + selector);
    }
    const res = { nodeName: match[1].trim() };
    if (match[2]) {
        const attr = [match[2]];
        if (match[3]) { attr.push(match[3]); }
        // Decode the attribute value
        if(match[4]) {
            attr.push(match[4].replace(/\\([nrtf"\\])/g, function(_, k) {
                return valueDecodeTable[k];
            }));
        }
        res.attributes = [attr];
    }
    return res;
}
1042481
function (content) {

            content = helpers.replaceCustom(content, /<script.+src=['"](.+)["'][\/>]?><[\\]?\/script>/gm);

            content = helpers.replaceCustom(content, /<link[^\>]+href=['"]([^"']+)["']/gm);

            return content;
        }
863843
function parser(config) {
    chevrotain.Parser.call(this, cssTokens, config)

    var $ = this

    this.RULE("stylesheet", function() {
        // [ CHARSET_SYM STRING ';' ]?
        $.OPTION(function() {
            $.SUBRULE($.charsetHeader)
        })

        // [S|CDO|CDC]*
        $.SUBRULE($.cdcCdo)

        // [ import [ CDO S* | CDC S* ]* ]*
        $.MANY(function() {
            $.SUBRULE($.cssImport)
            $.SUBRULE2($.cdcCdo)
        })

        // [ [ ruleset | media | page ] [ CDO S* | CDC S* ]* ]*
        $.MANY2(function() {
            $.SUBRULE($.contents)
        })
    })

    this.RULE("charsetHeader", function() {
        $.CONSUME(CharsetSym)
        $.CONSUME(StringLiteral)
        $.CONSUME(SemiColon)
    })

    this.RULE("contents", function() {
        // prettier-ignore
        $.OR([
            {ALT: function() {$.SUBRULE($.ruleset)}},
            {ALT: function() {$.SUBRULE($.media)}},
            {ALT: function() {$.SUBRULE($.page)}}
        ])
        $.SUBRULE3($.cdcCdo)
    })

    // factor out repeating pattern for cdc/cdo
    this.RULE("cdcCdo", function() {
        $.MANY(function() {
            // prettier-ignore
            $.OR([
                {ALT: function() {$.CONSUME(Cdo)}},
                {ALT: function() {$.CONSUME(Cdc)}}
            ])
        })
    })

    // IMPORT_SYM S*
    // [STRING|URI] S* media_list? ';' S*
    this.RULE("cssImport", function() {
        $.CONSUME(ImportSym)
        // prettier-ignore
        $.OR([
            {ALT: function() {$.CONSUME(StringLiteral)}},
            {ALT: function() {$.CONSUME(Uri)}}
        ])

        $.OPTION(function() {
            $.SUBRULE($.media_list)
        })

        $.CONSUME(SemiColon)
    })

    // MEDIA_SYM S* media_list '{' S* ruleset* '}' S*
    this.RULE("media", function() {
        $.CONSUME(MediaSym)
        $.SUBRULE($.media_list)
        $.CONSUME(LCurly)
        $.SUBRULE($.ruleset)
        $.CONSUME(RCurly)
    })

    // medium [ COMMA S* medium]*
    this.RULE("media_list", function() {
        $.SUBRULE($.medium)
        $.MANY_SEP({
            SEP: Comma,
            DEF: function() {
                $.SUBRULE2($.medium)
            }
        })
    })

    // IDENT S*
    this.RULE("medium", function() {
        $.CONSUME(Ident)
    })

    // PAGE_SYM S* pseudo_page?
    // '{' S* declaration? [ ';' S* declaration? ]* '}' S*
    this.RULE("page", function() {
        $.CONSUME(PageSym)
        $.OPTION(function() {
            $.SUBRULE($.pseudo_page)
        })

        $.SUBRULE($.declarationsGroup)
    })

    // '{' S* declaration? [ ';' S* declaration? ]* '}' S*
    // factored out repeating grammar pattern
    this.RULE("declarationsGroup", function() {
        $.CONSUME(LCurly)
        $.OPTION(function() {
            $.SUBRULE($.declaration)
        })

        $.MANY(function() {
            $.CONSUME(SemiColon)
            $.OPTION2(function() {
                $.SUBRULE2($.declaration)
            })
        })
        $.CONSUME(RCurly)
    })

    // ':' IDENT S*
    this.RULE("pseudo_page", function() {
        $.CONSUME(Colon)
        $.CONSUME(Ident)
    })

    // '/' S* | ',' S*
    this.RULE("operator", function() {
        // prettier-ignore
        $.OR([
            {ALT: function() {$.CONSUME(Slash)}},
            {ALT: function() {$.CONSUME(Comma)}}
        ])
    })

    // '+' S* | '>' S*
    this.RULE("combinator", function() {
        // prettier-ignore
        $.OR([
            {ALT: function() {$.CONSUME(Plus)}},
            {ALT: function() {$.CONSUME(GreaterThan)}}
        ])
    })

    // '-' | '+'
    this.RULE("unary_operator", function() {
        // prettier-ignore
        $.OR([
            {ALT: function() {$.CONSUME(Minus)}},
            {ALT: function() {$.CONSUME(Plus)}}
        ])
    })

    // IDENT S*
    this.RULE("property", function() {
        $.CONSUME(Ident)
    })

    // selector [ ',' S* selector ]*
    // '{' S* declaration? [ ';' S* declaration? ]* '}' S*
    this.RULE("ruleset", function() {
        $.MANY_SEP({
            SEP: Comma,
            DEF: function() {
                $.SUBRULE($.selector)
            }
        })

        $.SUBRULE($.declarationsGroup)
    })

    // simple_selector [ combinator selector | S+ [ combinator? selector ]? ]?
    this.RULE("selector", function() {
        $.SUBRULE($.simple_selector)
        $.OPTION(function() {
            $.OPTION2(function() {
                $.SUBRULE($.combinator)
            })
            $.SUBRULE($.selector)
        })
    })

    // element_name [ HASH | class | attrib | pseudo ]*
    // | [ HASH | class | attrib | pseudo ]+
    this.RULE("simple_selector", function() {
        $.OR([
            {
                ALT: function() {
                    $.SUBRULE($.element_name)
                    $.MANY(function() {
                        $.SUBRULE($.simple_selector_suffix)
                    })
                }
            },
            {
                ALT: function() {
                    $.AT_LEAST_ONE(function() {
                        $.SUBRULE2($.simple_selector_suffix)
                    }, "selector suffix")
                }
            }
        ])
    })

    // helper grammar rule to avoid repetition
    // [ HASH | class | attrib | pseudo ]+
    this.RULE("simple_selector_suffix", function() {
        // prettier-ignore
        $.OR([
            {ALT: function() {$.CONSUME(Hash)}},
            {ALT: function() {$.SUBRULE($.class)}},
            {ALT: function() {$.SUBRULE($.attrib)}},
            {ALT: function() {$.SUBRULE($.pseudo)}}
        ])
    })

    // '.' IDENT
    this.RULE("class", function() {
        $.CONSUME(Dot)
        $.CONSUME(Ident)
    })

    // IDENT | '*'
    this.RULE("element_name", function() {
        // prettier-ignore
        $.OR([
            {ALT: function() {$.CONSUME(Ident)}},
            {ALT: function() {$.CONSUME(Star)}}
        ])
    })

    // '[' S* IDENT S* [ [ '=' | INCLUDES | DASHMATCH ] S* [ IDENT | STRING ] S* ]? ']'
    this.RULE("attrib", function() {
        $.CONSUME(LSquare)
        $.CONSUME(Ident)

        this.OPTION(function() {
            // prettier-ignore
            $.OR([
                {ALT: function() {$.CONSUME(Equals)}},
                {ALT: function() {$.CONSUME(Includes)}},
                {ALT: function() {$.CONSUME(Dasmatch)}}
            ])

            // prettier-ignore
            $.OR2([
                {ALT: function() {$.CONSUME2(Ident)}},
                {ALT: function() {$.CONSUME(StringLiteral)}}
            ])
        })
        $.CONSUME(RSquare)
    })

    // ':' [ IDENT | FUNCTION S* [IDENT S*]? ')' ]
    this.RULE("pseudo", function() {
        $.CONSUME(Colon)

        // prettier-ignore
        $.OR([
            {ALT: function() {$.CONSUME(Ident)}},
            {
                ALT: function() {
                    $.CONSUME(Func)
                    $.OPTION(function() {
                        $.CONSUME2(Ident)
                    })
                    $.CONSUME(RParen)
                }
            }
        ])
    })

    // property ':' S* expr prio?
    this.RULE("declaration", function() {
        $.SUBRULE($.property)
        $.CONSUME(Colon)
        $.SUBRULE($.expr)

        $.OPTION(function() {
            $.SUBRULE($.prio)
        })
    })

    // IMPORTANT_SYM S*
    this.RULE("prio", function() {
        $.CONSUME(ImportantSym)
    })

    // term [ operator? term ]*
    this.RULE("expr", function() {
        $.SUBRULE($.term)
        $.MANY(function() {
            $.OPTION(function() {
                $.SUBRULE($.operator)
            })
            $.SUBRULE2($.term)
        })
    })

    // unary_operator?
    // [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
    // TIME S* | FREQ S* ]
    // | STRING S* | IDENT S* | URI S* | hexcolor | function
    this.RULE("term", function() {
        $.OPTION(function() {
            $.SUBRULE($.unary_operator)
        })

        // prettier-ignore
        $.OR([
            {ALT: function() {$.CONSUME(Num)}},
            {ALT: function() {$.CONSUME(Percentage)}},
            {ALT: function() {$.CONSUME(Length)}},
            {ALT: function() {$.CONSUME(Ems)}},
            {ALT: function() {$.CONSUME(Exs)}},
            {ALT: function() {$.CONSUME(Angle)}},
            {ALT: function() {$.CONSUME(Time)}},
            {ALT: function() {$.CONSUME(Freq)}},
            {ALT: function() {$.CONSUME(StringLiteral)}},
            {ALT: function() {$.CONSUME(Ident)}},
            {ALT: function() {$.CONSUME(Uri)}},
            {ALT: function() {$.SUBRULE($.hexcolor)}},
            {ALT: function() {$.SUBRULE($.cssFunction)}}
        ])
    })

    // FUNCTION S* expr ')' S*
    this.RULE("cssFunction", function() {
        $.CONSUME(Func)
        $.SUBRULE($.expr)
        $.CONSUME(RParen)
    })

    this.RULE("hexcolor", function() {
        $.CONSUME(Hash)
    })

    // very important to call this after all the rules have been setup.
    // otherwise the parser may not work correctly as it will lack information
    // derived from the self analysis.
    this.performSelfAnalysis()
}
227762
function selectionRangesForCSSNode(node) {
	const ranges = [new Range(node.start, node.end)];

	if (node.type === 'property' && node.valueToken) {
		ranges.push(new Range(node.valueToken.start, node.valueToken.end));
	} else if (node.type === 'rule' || node.type === 'at-rule') {
		ranges.push(new Range(node.contentStartToken.end, node.contentEndToken.start));
	}

	return ranges;
}
658918
function parseJavascript(content) {
    var _return = {},
      parts = content.split("\n"),
      keys = [
        "name",
        "namespace",
        "type",
        "description",
        "example",
        "param",
        "event",
        "return",
        "main",
        "dependency"
      ];

    for (var pi in parts) {
      var p = parts[pi];

      for (var ki in keys) {
        var key = keys[ki];

        if (p.indexOf("@"+key) > -1 && p.indexOf("@events") < 0) {
          var pset = p.split("@"+key),
          part = pset[ pset.length - 1 ].trim();

          // Split down params, events and returns
          if ( ["param","event","return"].indexOf(key) > -1 ) {
            var parray = [];

            if (key !== "return") {
              parray = part.split(" ", 1);
              parray.push( part.replace(parray[0]+" ", "") );
              part = {
                "name": parray[0].trim()
              };
            } else {
              parray[0] = ''
              parray[1] = part;
              part = {};
            }

            if (parray[1]) {
              // 0 - all
              // 1 - type
              // 2 - default
              // 3 - description

              // Patterns: \[([^\]]*)\]|\<([^\]]*)\>|\"([^\]]*)\"
              var matches = parray[1].match(/\[([^\]]*)\]|\<([^\]]*)\>|\"([^\]]*)\"/g);

              for (var mi in matches) {
                var match = matches[mi];

                if (match.indexOf("[") === 0) {
                  part.type = match.replace("[", "").replace("]", "");
                }
                if (match.indexOf("<") === 0) {
                  part.default = match.replace("<", "").replace(">", "");
                }
                if (match.indexOf('"') === 0) {
                  part.description = match.replace(/"/g, "");
                }
              }
            }
          }

          if (key === "param") {
            if (!_return.params) {
              _return["params"] = [];
            }
            _return["params"].push(part);
          } else if (key === "example") {
            if (!_return.examples) {
              _return["examples"] = [];
            }
            _return["examples"].push(part);
          } else if (key === "event") {
            if (!_return.events) {
              _return["events"] = [];
            }
            _return["events"].push(part);
          } else if (key === "main") {
            if (!_return.main) {
              _return["main"] = [];
            }
            _return["main"].push(part);
          } else if (key === "dependency") {
            if (!_return.dependencies) {
              _return["dependencies"] = [];
            }
            _return["dependencies"].push(part);
          } else {
            _return[key] = part;
          }
        }
      }
    }

    return _return;
  }
920989
static final Element[] elements(Match... content) {
        Set<Element> result = new LinkedHashSet<Element>();

        for (Match x : content)
            result.addAll(x.get());

        return result.toArray(new Element[result.size()]);
    }
332363
function Converter(css) {
  var parse = require('css-parse');
  this.css = css;
  this.root = parse(css, { position: false });
  this.indents = 0;
}
740069
function(_content,_out){
        if (!_content) return;
        var _lines = _content.split('\n');
        if (!_lines||!_lines.length) return;
        for(var i=0,l=_lines.length,_line;i<l;i++){
            _line = _lines[i];
            if (!!_trim){
                _line = _line.trim();
                if (!_line) continue;
            } 
            _doParseSectionTextLine(_line,_out);
            if (!!_trim&&i<l-1) _out.push('__OUT.push(\'\\n\');');
        }
    }
147688
function(content) {
        var node = this.createElementNSPlus("atom:content", {
            attributes: {
                type: content.type || null
            }
        });
        if (content.src) {
            node.setAttribute("src", content.src);
        } else {
            if (content.type == "text" || content.type == null) {
                node.appendChild(
                    this.createTextNode(content.value)
                );
            } else if (content.type == "html") {
                if (typeof content.value != "string") {
                    throw "HTML content must be in form of an escaped string";
                }
                node.appendChild(
                    this.createTextNode(content.value)
                );
            } else if (content.type == "xhtml") {
                node.appendChild(content.value);
            } else if (content.type == "xhtml" ||
                           content.type.match(/(\+|\/)xml$/)) {
                node.appendChild(content.value);
            }
            else { // MUST be a valid Base64 encoding
                node.appendChild(
                    this.createTextNode(content.value)
                );
            }
        }
        return node;
    }
1354593
function getSections(sections, config, parentDepth) {
	return sections.map(section => processSection(section, config, parentDepth))
}
269359
function parse(content, relative, filep) {
    relative = relative || '';
    CONTENT = '';
    JS_Files = [];
    CSS_Files = [];
    content = css(content, relative, filep);
    content = js(content, relative, filep);
    return {
        // content:insertScript(recall(content)),
        content: recall(content),
        js: distinct(JS_Files),
        css: distinct(CSS_Files)
    };
}
494715
def parse_css(self, css):
        
        rulesets = self.ruleset_re.findall(css)
        for (selector, declarations) in rulesets:
            rule = Rule(self.parse_selector(selector))
            rule.properties = self.parse_declarations(declarations)
            self.rules.append(rule)
892321
def parse_snippet_css(path)
      return unless core.storage.file?(path)
      parser = ::CssParser::Parser.new
      parser.add_block! core.storage.read(path)
      apply_styles parser, "snippet"
    end
161431
function toRules (cssText) {
  const node = parseCss(cssText)
  let rules = []

  if (node.rules && node.rules.length > 0) {
    rules = node.rules
      .filter(filterUnusedVendorRule)
      .map((rule) => toCssText(rule))
  } else {
    const cssText = toCssText(node)
    if (cssText) {
      rules = [cssText]
    }
  }

  return rules
}
821198
function getRangesFromCSSNode(node) {
	let ranges;

	if (node.type === 'rule') {
		ranges = [ getRange(node.selectorToken) ].concat(node.parsedSelector.map(getRange));
	} else if (node.type === 'at-rule') {
		const nameEndToken = node.expressionToken || node.nameToken;
		ranges = [
			new Range(node.nameToken.start, nameEndToken.end),
			getRange(node.nameToken),
			getRange(node.expressionToken)
		];
		node.parsedExpression.forEach(token => {
			ranges.push(getRange(token));
			iterateCSSToken(token, t => {
				if (t.type === 'argument') {
					ranges.push(getRange(t));
				}
			});
		});
	} else if (node.type === 'property') {
		ranges = [
			getRange(node),
			getRange(node.nameToken),
			getRange(node.valueToken)
		];
		node.parsedValue.forEach(value => {
			// parsed value contains a comma-separated list of sub-values,
			// each of them, it turn, may contain space-separated parts
			ranges.push(getRange(value));

			for (let i = 0, il = value.size, token; i < il; i++) {
				token = value.item(i);
				if (token.type === 'url') {
					ranges.push(getRange(token), getRange(token.item(0)));
				} else if (token.type !== 'whitespace' && token !== 'comment') {
					ranges.push(getRange(token));

					iterateCSSToken(token, t => {
						if (t.type === 'argument') {
							ranges.push(getRange(t));
						}
					});
				}
			}
		});
	}

	return ranges ? uniqueRanges(ranges.filter(Boolean)) : [];
}