Match one line or multiline, escaped or unescaped text

 @param parent [Array] Parent node element
 @param indent [Fixnum] Size of the current indentation
 @param multiline_or_print [Boolean] Allow only multiline text or print
338353
def text(parent, indent = nil, multiline_or_print = true)
      # Try to see if we can match a multiline operator. If we can accept_stripped only
      # multiline, which is the case for filters, undo the operation.
      if accept :multiline
        multiline = true
      elsif multiline_or_print
        return nil unless lookahead :print_lookahead
      end

      # Get text node type
      type = accept(:print) ? :print : :text

      # Get leading whitespace
      leading_whitespace = accept(:leading_whitespace)

      # Get trailing whitespace
      trailing_whitespace = accept(:trailing_whitespace)

      # Check if the text or print node is escaped or unescaped
      escaped = accept(:unescaped_value) ? false : true

      # Get text value
      value = accept :line_feed
      value = value[1..-1] if value[0] == '\\'

      # Create the text node using input data
      text_node = [
        :plain,
        type,
        {
          value: value.strip,
          escaped: escaped,
          leading_whitespace: leading_whitespace,
          trailing_whitespace: trailing_whitespace
        },
        nil,
        indent
      ]

      # If we have a multiline node, get all the text which has higher
      # indentation than our indentation node.
      if multiline
        text_node[@options][:value] += accept(:newline) || ''
        text_node[@options][:value] += get_indented_lines(indent)
        text_node[@options][:value].strip!
      elsif value.empty?
        # If our value is empty and we're not going to add any more lines to
        # our buffer, skip the node
        return nil
      end

      # Increase indentation if this is an inline text node
      text_node[@indent] += @settings[:indent] unless multiline_or_print

      # Add text node to the parent element
      parent[@children] << text_node
    end
110387
function print(str, indent, inline) {
        var lines = str.split('\n');

        for(var i=0; i<lines.length; i++) {
            if(lines[i]) {
                if((inline && i > 0) || !inline) {
                    for(var j=0; j<indent; j++) {
                        process.stdout.write(' ');
                    }
                }
            }

            if(i === lines.length-1) {
                process.stdout.write(lines[i]);
            }
            else {
                process.stdout.write(lines[i] + '\n');
            }
        }
    }
1056724
def check_indent(self, definition, docstring):
        
        if docstring:
            indent = self._get_docstring_indent(definition, docstring)
            lines = docstring.split('\n')
            if len(lines) > 1:
                lines = lines[1:]  # First line does not need indent.
                indents = [leading_space(l) for l in lines if not is_blank(l)]
                if set(' \t') == set(''.join(indents) + indent):
                    yield violations.D206()
                if (len(indents) > 1 and min(indents[:-1]) > indent or
                        indents[-1] > indent):
                    yield violations.D208()
                if min(indents) < indent:
                    yield violations.D207()
1000357
public CompositeGeneratorNode indent(final CompositeGeneratorNode parent, final String indentString) {
    final IndentNode indent = new IndentNode(indentString);
    List<IGeneratorNode> _children = parent.getChildren();
    _children.add(indent);
    return indent;
  }
182860
def parse_lines(self, lines):
        
        indent = ''
        level = 0

        if lines[0][0] == ' ' or lines[0][0] == '\t':
            raise CommandError("The first line in the file cannot start with a space or tab.")

        # This keeps track of the current parents at a given level
        current_parents = {0: None}

        for line in lines:
            if len(line) == 0:
                continue
            if line[0] == ' ' or line[0] == '\t':
                if indent == '':
                    indent = self.get_indent(line)
                elif not line[0] in indent:
                    raise CommandError("You can't mix spaces and tabs for indents")
                level = line.count(indent)
                current_parents[level] = self.make_category(line, parent=current_parents[level - 1])
            else:
                # We are back to a zero level, so reset the whole thing
                current_parents = {0: self.make_category(line)}
        current_parents[0]._tree_manager.rebuild()
922368
def parse(parent_node)

    # run element parser
    begin
      parent_node.parser.matching_negative if negative
      match = parser.call(parent_node)
    ensure
      parent_node.parser.unmatching_negative if negative
    end

    # Negative patterns (PEG: !element)
    match = match ? nil : EmptyNode.new(parent_node) if negative

    # Optional patterns (PEG: element?)
    match = EmptyNode.new(parent_node) if !match && optional

    # Could-match patterns (PEG: &element)
    match.match_length = 0 if match && could_match

    if !match && (terminal || negative)
      # log failures on Terminal patterns for debug output if overall parse fails
      parent_node.parser.log_parsing_failure parent_node.next, :pattern => self.to_s, :node => parent_node
    end

    match.delimiter = delimiter if match

    # return match
    match
  end
24516
function(str, indent) {
			var lines = str.split("\n");
			for (var i=0; i<lines.length; i++)
				lines[i] = indent + lines[i];
			return lines.join("\n");
		}
1136923
def html_text(parent, indent)
      return unless (text_feed = accept :html_text)

      text_node = [
        :plain,
        :text,
        {
          value: text_feed.strip,
          escaped: false
        },
        nil,
        indent
      ]

      parent[@children] << text_node
    end
149259
def on_multi(*exps)
      result = [:multi]
      # This variable is true if the previous line was
      # (1) a control code and (2) contained indented content.
      prev_indent = false

      exps.each do |exp|
        if control?(exp)
          raise(Temple::FilterError, 'Explicit end statements are forbidden') if exp[2] =~ END_RE

          # Two control code in a row. If this one is *not*
          # an else block, we should close the previous one.
          append_end(result) if prev_indent && exp[2] !~ ELSE_RE

          # Indent if the control code starts a block.
          prev_indent = exp[2] =~ IF_RE
        elsif exp[0] != :newline && prev_indent
          # This is *not* a control code, so we should close the previous one.
          # Ignores newlines because they will be inserted after each line.
          append_end(result)
          prev_indent = false
        end

        result << compile(exp)
      end

      # The last line can be a control code too.
      prev_indent ? append_end(result) : result
    end
291627
public static Matcher<Tree> parentNode(Matcher<? extends Tree> treeMatcher) {
    @SuppressWarnings("unchecked") // Safe contravariant cast
    Matcher<Tree> matcher = (Matcher<Tree>) treeMatcher;
    return new ParentNode(matcher);
  }
1127499
function AssignmentExpression(node, print, parent) {
  // Somewhere inside a for statement `init` node but doesn't usually
  // needs a paren except for `in` expressions: `for (a in b ? a : b;;)`
  var parens = this._inForStatementInit && node.operator === "in" && !_node2["default"].needsParens(node, parent);

  if (parens) {
    this.push("(");
  }

  // todo: add cases where the spaces can be dropped when in compact mode
  print.plain(node.left);

  var spaces = node.operator === "in" || node.operator === "instanceof";
  spaces = true; // todo: https://github.com/babel/babel/issues/1835
  this.space(spaces);

  this.push(node.operator);

  if (!spaces) {
    // space is mandatory to avoid outputting <!--
    // http://javascript.spec.whatwg.org/#comment-syntax
    spaces = node.operator === "<" && t.isUnaryExpression(node.right, { prefix: true, operator: "!" }) && t.isUnaryExpression(node.right.argument, { prefix: true, operator: "--" });
  }

  this.space(spaces);

  print.plain(node.right);

  if (parens) {
    this.push(")");
  }
}
598979
function or(matches, pattern, file) {
  var length = matches.length
  var note = pattern.note
  var id = pattern.id
  var index = -1
  var match
  var next
  var siblings
  var sibling
  var value
  var nodes
  var start
  var end

  while (++index < length) {
    match = matches[index]
    siblings = match.parent.children
    nodes = match.nodes
    value = toString(nodes)
    next = matches[index + 1]

    if (next && next.parent === match.parent && next.type !== match.type) {
      start = match.end
      end = next.start

      while (++start < end) {
        sibling = siblings[start]

        if (
          sibling.type === ws ||
          (sibling.type === word && /(and|or)/.test(normalize(sibling))) ||
          (sibling.type === punc && normalize(sibling) === '/')
        ) {
          continue
        }

        break
      }

      /* If we didn't break... */
      if (start === end) {
        index++
        continue
      }
    }

    warn(
      file,
      id,
      value,
      pattern.considerate,
      nodes[0],
      note,
      pattern.condition
    )
  }
}
1372873
function(offset, newline){
    var ast;
    offset = offset || 0;
    newline = newline ? '\n' : '';
    ast = this.buffer(newline + Array(this.indents + offset).join(this.pp));
    if (this.parentIndents) {

      push.apply(ast, this.ast_buffer(t.callExpression(
                                t.memberExpression(t.identifier('pug_indent'), t.identifier('join')),
                                [t.stringLiteral('')]
                              )));

    }
    return ast;
  }
282554
def check_character(character, root)
      wrong_characters = character == :space ? 'tabs' : 'spaces'
      regex = INDENT_REGEX[character]
      dummy_node = Struct.new(:line)

      document.source_lines.each_with_index do |line, index|
        next if line =~ regex

        unless root.node_for_line(index).disabled?(self)
          record_lint dummy_node.new(index + 1), "Line contains #{wrong_characters} in indentation"
        end
      end
    end
125934
function print(str, indent, inline) {
  var lines = str.split('\n');

  lines.forEach((line, i) => {
    if (line && ((inline && i > 0) || !inline)) {
      process.stdout.write((' ').repeat(indent));
    }
    const nl = (i === lines.length - 1) ? '' : '\n';
    process.stdout.write(`${line}${nl}`);
  });
}
257337
def is_multiline?(text)
      text && text.length > 1 && text[-1] == MULTILINE_CHAR_VALUE && text[-2] == ?\s && text !~ BLOCK_WITH_SPACES
    end
739881
def control(parent, indent)
      # Accept eval or multiline eval syntax and return a new node,
      return unless (structure = accept(:control))
      structure = structure.to_sym

      # Handle each and the other control structures
      condition = accept(:line_feed).strip

      # Process each control structure condition
      if structure == :each
        # Check if arguments provided correctly
        unless condition.match Tokens[:each_pattern]
          Logger.error :parse, @code, @i, @j, :each_arguments
        end

        # Conditions for each iterator
        condition = [
          Regexp.last_match[1].split(' '),
          Regexp.last_match[2].split(/,(.+)$/).map(&:strip).map(&:to_sym)
        ]

        # Array loop as default
        condition[0].unshift '{}' if condition[0].length == 1
      end

      # Else and default structures are not allowed to have any condition
      # set and the other control structures require a condition
      if structure == :else
        unless condition.empty?
          Logger.error :parse, @code, @i, @j, :condition_exists
        end
      else
        if condition.empty?
          Logger.error :parse, @code, @i, @j, :condition_missing
        end
      end

      # Add the condition and create a new child to the control parent.
      # The control parent keeps condition -> children matches for our
      # document's content
      # add_options = proc do |control_parent|
      #   control_parent.value << condition
      #   control_parent.children << []
      #
      #   root control_parent
      # end

      # If the current control structure is a parent which allows multiple
      # branches, such as an if or case, we create an array of conditions
      # which can be matched and an array of children belonging to each
      # conditional branch
      if [:if, :unless].include? structure
        # Create the control structure and get its child nodes
        control_structure = [structure, [condition], {}, [], indent]
        root control_structure, indent

        # Turn children into an array because we allow multiple branches
        control_structure[@children] = [control_structure[@children]]

        # Add it to the parent node
        parent[@children] << control_structure

      elsif structure == :case
        # Create the control structure and get its child nodes
        control_structure = [
          structure,
          [],
          { condition: condition },
          [],
          indent
        ]

        # Add it to the parent node
        parent[@children] << control_structure

      # If the control structure is a child structure, we need to find the
      # node it belongs to amont the current parent. Search from end to
      # beginning until we find the node parent
      elsif control_child structure
        # During the search, we try to find the matching parent type
        unless control_parent(structure).include? parent[@children][-1][@type]
          Logger.error :parse,
                       @code,
                       @i,
                       @j,
                       :control_child,
                       control_parent(structure)
        end

        # Gather child elements for current structure
        control_structure = [structure, [condition], {}, [], indent]
        root control_structure, indent

        # Add the new condition and children to our parent structure
        parent[@children][-1][@value] << condition
        parent[@children][-1][@children] << control_structure[@children]

      # When our control structure isn't a complex composite, we create
      # it the same way as a normal node
      else
        control_structure = [structure, condition, {}, [], indent]
        root control_structure, indent

        parent[@children] << control_structure
      end
    end