<commit_before>import AtRule from 'postcss/lib/at-rule';
import Comment from 'postcss/lib/comment';
import Parser from 'postcss/lib/parser';

import lessTokenizer from './less-tokenize';

const MixinDefinitionPattern = /^([#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+)\s*\(/;

export default class LessParser extends Parser {
    constructor (input, opts) {
        super(input);
        this.mixins = {};
    }

    tokenize () {
        this.tokens = lessTokenizer(this.input);
    }

    comment (token) {
        if (token[6] === 'inline') {
            const node = new Comment();

            this.init(node, token[2], token[3]);
            node.raws.inline = true;
            node.source.end = {line: token[4], column: token[5]};

            const text = token[1].slice(2);

            if (/^\s*$/.test(text)) {
                node.text = '';
                node.raws.left = text;
                node.raws.right = '';
            } else {
                const match = text.match(/^(\s*)([^]*[^\s])(\s*)$/);

                node.text = match[2];
                node.raws.left = match[1];
                node.raws.right = match[3];
            }
        } else {
            super.comment(token);
        }
    }

    rule (token) {
        super.rule(token);

        if (MixinDefinitionPattern.test(this.current.source.input.css)) {
            // this.current is the 'rule' node created in super.rule()
            this.current.name = token[0][1].slice(1);
            this.current.type = 'mixin';
            this.current.definition = true;
            this.current.params = [];<commit_msg>parser can now be opted in to parsing mixins as at rules<commit_after>import AtRule from 'postcss/lib/at-rule';
import Comment from 'postcss/lib/comment';
import Parser from 'postcss/lib/parser';

import lessTokenizer from './less-tokenize';

const MixinDefinitionPattern = /^([#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+)\s*\(/;

export default class LessParser extends Parser {
    constructor (input, opts) {
        super(input);
        this.mixins = {};
        this.mixinsAsAtRules = (opts || {}).mixinsAsAtRules;
    }

    tokenize () {
        this.tokens = lessTokenizer(this.input);
    }

    comment (token) {
        if (token[6] === 'inline') {
            const node = new Comment();

            this.init(node, token[2], token[3]);
            node.raws.inline = true;
            node.source.end = {line: token[4], column: token[5]};

            const text = token[1].slice(2);

            if (/^\s*$/.test(text)) {
                node.text = '';
                node.raws.left = text;
                node.raws.right = '';
            } else {
                const match = text.match(/^(\s*)([^]*[^\s])(\s*)$/);

                node.text = match[2];
                node.raws.left = match[1];
                node.raws.right = match[3];
            }
        } else {
            super.comment(token);
        }
    }

    rule (token) {
        super.rule(token);

        if (MixinDefinitionPattern.test(this.current.source.input.css)) {
            // this.current is the 'rule' node created in super.rule()
            this.current.name = token[0][1].slice(1);
            
            if (this.mixinsAsAtRules === true) {
                this.current.type = 'atrule';
                this.current.lessType = 'mixin';
            } else {
                this.current.type = 'mixin';
            }
            
            this.current.definition = true;
            this.current.params = [];
{'fraction_non_alphanumeric': 0.16746546377220187, 'fraction_numerical': 0.010713278827177897, 'mean_word_length': 1.6696764484574869, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2836367', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1083, 'n_words': 210}