Make the part of the grammar that depends on whether we swallow errors or not.
345848
def make_grammar(allow_errors):
  """"""
  if allow_errors in GRAMMAR_CACHE:
    return GRAMMAR_CACHE[allow_errors]

  tuple = p.Forward()
  catch_errors = p.Forward()
  catch_errors << (p.Regex('[^{};]*') - p.Optional(tuple) - p.Regex('[^;}]*'))

  def swallow_remainder():
    if allow_errors:
      return pattern('swallow_remainder', p.Suppress(catch_errors))
    return p.Empty()

  def swallow_errors(rule):
    """Extend the production rule by potentially eating errors.

    This does not return a p.NoMatch() because that messes up the error messages.
    """
    ret = rule
    if allow_errors:
      # Synchronize on the first semicolon or the first unbalanced closing curly
      ret = rule | pattern('catch_errors', parseWithLocation(p.Suppress(catch_errors), UnparseableNode))
    return ret

  class Grammar:
    keywords = ['and', 'or', 'not', 'if', 'then', 'else', 'include', 'inherit', 'null', 'true', 'false',
        'for', 'in']

    # This is a hack: this condition helps uselessly recursing into the grammar for
    # juxtapositions.
    early_abort_scan = ~p.oneOf([';', ',', ']', '}', 'for' ])

    expression = pattern('expression', p.Forward())

    comment = p.Regex('#') + ~p.FollowedBy(sym('.')) + p.restOfLine
    doc_comment = pattern('doc_comment', (sym('#.') - p.restOfLine))

    quotedIdentifier = pattern('quotedIdentifier', p.QuotedString('`', multiline=False))

    # - Must start with an alphascore
    # - May contain alphanumericscores and special characters such as : and -
    # - Must not end in a special character
    identifier = pattern('identifier', parseWithLocation(quotedIdentifier | p.Regex(r'[a-zA-Z_]([a-zA-Z0-9_:-]*[a-zA-Z0-9_])?'), Identifier))

    # Variable identifier (can't be any of the keywords, which may have lower matching priority)
    variable = pattern('variable', ~p.MatchFirst(p.oneOf(keywords)) + pattern('identifier', parseWithLocation(identifier.copy(), Var)))

    # Contants
    integer = pattern('integer', parseWithLocation(p.Word(p.nums), convertAndMake(int, Literal)))
    floating = pattern('floating', parseWithLocation(p.Regex(r'\d*\.\d+'), convertAndMake(float, Literal)))
    dq_string = pattern('dq_string', parseWithLocation(p.QuotedString('"', escChar='\\', unquoteResults=False, multiline=True), convertAndMake(unquote, Literal)))
    sq_string = pattern('sq_string', parseWithLocation(p.QuotedString("'", escChar='\\', unquoteResults=False, multiline=True), convertAndMake(unquote, Literal)))
    boolean = pattern('boolean', parseWithLocation(p.Keyword('true') | p.Keyword('false'), convertAndMake(mkBool, Literal)))
    null = pattern('null', parseWithLocation(p.Keyword('null'), Null))

    # List
    list_ = pattern('list', parseWithLocation(bracketedList('[', ']', ',', expression), List))

    # Tuple
    inherit = pattern('inherit', (kw('inherit') - p.ZeroOrMore(variable)).setParseAction(inheritNodes))
    schema_spec = pattern('schema_spec', parseWithLocation(p.Optional(p.Keyword('private').setParseAction(lambda: True), default=False)
                  - p.Optional(p.Keyword('required').setParseAction(lambda: True), default=False)
                  - p.Optional(expression, default=any_schema_expr), MemberSchemaNode))
    optional_schema = pattern('optional_schema', p.Optional(p.Suppress(':') - schema_spec, default=no_schema))

    expression_value = pattern('expression_value', sym('=') - swallow_errors(expression))
    void_value = pattern('void_value', parseWithLocation(p.FollowedBy(sym(';') | sym('}')), lambda loc: Void(loc, 'nonameyet')))
    member_value = pattern('member_value', swallow_errors(expression_value | void_value))
    named_member = pattern('named_member', parseWithLocation(identifier - optional_schema - member_value - swallow_remainder(), TupleMemberNode))
    documented_member = pattern('documented_member', parseWithLocation(parseWithLocation(p.ZeroOrMore(doc_comment), DocComment) + named_member, attach_doc_comment))
    tuple_member = early_abort_scan + pattern('tuple_member', swallow_errors(inherit | documented_member) - swallow_remainder())

    ErrorAwareTupleNode = functools.partial(TupleNode, allow_errors)
    tuple_members = pattern('tuple_members', parseWithLocation(listMembers(';', tuple_member), ErrorAwareTupleNode))
    tuple << pattern('tuple', parseWithLocation(bracketedList('{', '}', ';', tuple_member, allow_missing_close=allow_errors), ErrorAwareTupleNode))

    # Argument list will live by itself as a atom. Actually, it's a tuple, but we
    # don't call it that because we use that term for something else already :)
    arg_list = pattern('arg_list', bracketedList('(', ')', ',', expression).setParseAction(ArgList))

    parenthesized_expr = pattern('parenthesized_expr', (sym('(') - expression - ')').setParseAction(head))

    unary_op = pattern('unary_op', (p.oneOf(' '.join(functions.unary_operators.keys())) - expression).setParseAction(mkUnOp))

    if_then_else = pattern('if_then_else', parseWithLocation(kw('if') + expression +
                    kw('then') + expression +
                    kw('else') + expression, Condition))

    list_comprehension = pattern('list_comprehension', parseWithLocation(sym('[') + expression + kw('for') + variable + kw('in') +
        expression + p.Optional(kw('if') + expression) + sym(']'), ListComprehension))


    # We don't allow space-application here
    # Now our grammar is becoming very dirty and hackish
    deref = pattern('deref', p.Forward())
    include = pattern('include', parseWithLocation(kw('include') - deref, Include))

    atom = pattern('atom', (tuple
            | sq_string
            | dq_string
            | variable
            | floating
            | integer
            | boolean
            | list_
            | null
            | unary_op
            | parenthesized_expr
            | if_then_else
            | include
            | list_comprehension
            ))

    # We have two different forms of function application, so they can have 2
    # different precedences. This one: fn(args), which binds stronger than
    # dereferencing (fn(args).attr == (fn(args)).attr)
    applic1 = pattern('applic1', parseWithLocation(atom - p.ZeroOrMore(arg_list), mkApplications))

    # Dereferencing of an expression (obj.bar)
    deref << parseWithLocation(applic1 - p.ZeroOrMore(p.Suppress('.') - swallow_errors(identifier)), mkDerefs)

    # All binary operators at various precedence levels go here:
    # This piece of code does the moral equivalent of:
    #
    #     T = F*F | F/F | F
    #     E = T+T | T-T | T
    #
    # etc.
    term = deref
    for op_level in functions.binary_operators_before_juxtaposition:
      operator_syms = list(op_level.keys())
      term = (term - p.ZeroOrMore(p.oneOf(operator_syms) - term)).setParseAction(mkBinOps)

    # Juxtaposition function application (fn arg), must be 1-arg every time
    applic2 = pattern('applic2', parseWithLocation(term - p.ZeroOrMore(early_abort_scan + term), mkApplications))

    term = applic2
    for op_level in functions.binary_operators_after_juxtaposition:
      operator_syms = list(op_level.keys())
      term = (term - p.ZeroOrMore(p.oneOf(operator_syms) - term)).setParseAction(mkBinOps)

    expression << term

    # Two entry points: start at an arbitrary expression, or expect the top-level
    # scope to be a tuple.
    start = pattern('start', expression.copy().ignore(comment))
    start_tuple = tuple_members.ignore(comment)
  GRAMMAR_CACHE[allow_errors] = Grammar
  return Grammar
510645
def require(self, *kinds):
        """"""
        token = self.attempt()
        if not token:
            raise SyntaxError('Unexpected end of input')
        if kinds and token.kind not in kinds:
            raise SyntaxError.unexpected(token, kinds)
        return token
467844
def auto_correct_incomplete?(rule)
      todo_reader = Rubocop::TodoReader.new(options[:file_path])
      todo_reader.all_rules.include?(rule)
    end
1251801
def sentence_matches(self, sentence_text):
        """"""
        has_upstream = False
        has_downstream = False
        has_verb = False

        # Get the first word of the action type and assume this is the verb
        # (Ex. get depends for depends on)
        actiontype_words = word_tokenize(self.mention.actiontype)
        actiontype_verb_stemmed = stem(actiontype_words[0])

        words = word_tokenize(sentence_text)

        if self.string_matches_sans_whitespace(sentence_text.lower(),
            self.mention.upstream.lower()):
            has_upstream = True

        if self.string_matches_sans_whitespace(sentence_text.lower(),
            self.mention.downstream.lower()):
            has_downstream = True

        for word in words:
            if actiontype_verb_stemmed == stem(word):
                has_verb = True

        return has_upstream and has_downstream and has_verb
944431
protected boolean editorErrorMatches(final EditorError perror) {
    return perror != null && perror.getEditor() != null
        && (equals(perror.getEditor()) || perror.getEditor().equals(asEditor()));
  }
1173108
def detect_missing_verb(sentence):
    """"""
    # TODO: should this be relocated?
    doc = nlp(sentence)
    for w in doc:
        if w.tag_.startswith('VB') and w.dep_ == 'ROOT':
            return False # looks like there is at least 1 main verb
    return True
1265737
private void fixConstraints(IPattern p) {
        if (p instanceof FactPattern) {
            fixConstraints((FactPattern) p);
        } else if (p instanceof CompositeFactPattern) {
            fixConstraints((CompositeFactPattern) p);
        }
    }
250102
def error(message)
      (m = filter(message, :error)) && each {|l| l.error(m)}
    end
1013230
private void findErrors(final Span references[], final Span predictions[],
      final List<Span> falseNegatives, final List<Span> falsePositives) {

    falseNegatives.addAll(Arrays.asList(references));
    falsePositives.addAll(Arrays.asList(predictions));

    for (final Span referenceName : references) {

      for (final Span prediction : predictions) {
        if (referenceName.equals(prediction)) {
          // got it, remove from fn and fp
          falseNegatives.remove(referenceName);
          falsePositives.remove(prediction);
        }
      }
    }
  }
1317262
function validateSentence(parsed) {
  const sentences = parsed.sentences();
  return [
    !isSingleSentence(sentences) ? 'Must be one and only one sentence.' : null,
    !isNotTooShort(parsed) ? 'Must be at least two words long.' : null,
    !isNotPunctuated(sentences) ? 'Must not have any end punctuation.' : null,
  ].filter(Boolean);
}
1090659
def expect(self, f, *args):
        """"""
        match = self.accept(f, *args)
        if match:
            return match

        try:
            func_name = f.func_name
        except AttributeError:
            func_name = "<unnamed grammar function>"

        start, end = self.current_position()
        raise errors.EfilterParseError(
            query=self.tokenizer.source, start=start, end=end,
            message="Was expecting %s here." % (func_name))
648438
def validate(args):
    
    p = OptionParser(validate.__doc__)
    opts, args = p.parse_args(args)

    if len(args) != 2:
        sys.exit(not p.print_help())

    imputed, withheld = args
    register = {}
    fp = open(withheld)
    for row in fp:
        if row[0] == "#":
            continue
        v = VcfLine(row)
        register[(v.seqid, v.pos)] = v.genotype

    logging.debug("Imported {0} records from `{1}`".\
                    format(len(register), withheld))

    fp = must_open(imputed)
    hit = concordant = 0
    seen = set()
    for row in fp:
        if row[0] == "#":
            continue
        v = VcfLine(row)
        chr, pos, genotype = v.seqid, v.pos, v.genotype
        if (chr, pos) in seen:
            continue
        seen.add((chr, pos))
        if (chr, pos) not in register:
            continue
        truth = register[(chr, pos)]
        imputed = genotype.split(":")[0]
        if "|" in imputed:
            imputed = "/".join(sorted(genotype.split(":")[0].split("|")))
            #probs = [float(x) for x in genotype.split(":")[-1].split(",")]
            #imputed = max(zip(probs, ["0/0", "0/1", "1/1"]))[-1]
        hit += 1
        if truth == imputed:
            concordant += 1
        else:
            print(row.strip(), "truth={0}".format(truth), file=sys.stderr)

    logging.debug("Total concordant: {0}".\
            format(percentage(concordant, hit)))
545460
def _if(cls, verb):
        
        pred = verb.predicate
        data = verb.data
        groups = set(_get_groups(verb))

        # force predicate
        if isinstance(pred, str):
            if not pred.endswith('_dtype'):
                pred = '{}_dtype'.format(pred)
            pred = getattr(pdtypes, pred)
        elif pdtypes.is_bool_dtype(np.array(pred)):
            # Turn boolean array into a predicate function
            it = iter(pred)

            def pred(col):
                return next(it)

        return [col for col in data
                if pred(data[col]) and col not in groups]
1096918
def preferred_forms_check(text, list, err, msg, ignore_case=True, offset=0,
                          max_errors=float("inf")):
    """"""
    if ignore_case:
        flags = re.IGNORECASE
    else:
        flags = 0

    msg = " ".join(msg.split())

    errors = []
    regex = u"[\W^]{}[\W$]"
    for p in list:
        for r in p[1]:
            for m in re.finditer(regex.format(r), text, flags=flags):
                txt = m.group(0).strip()
                errors.append((
                    m.start() + 1 + offset,
                    m.end() + offset,
                    err,
                    msg.format(p[0], txt),
                    p[0]))

    errors = truncate_to_max(errors, max_errors)

    return errors
1206819
def ok(self, text=u"OK", err=False):
        """"""
        # Do not display spin text for ok state
        self._text = None

        _text = to_text(text) if text else u"OK"
        err = err or not self.write_to_stdout
        self._freeze(_text, err=err)
658625
def error(msg, delay=0.5, chevrons=True, verbose=True):
    """"""
    if verbose:
        if chevrons:
            click.secho("\n❯❯ " + msg, err=True, fg="red")
        else:
            click.secho(msg, err=True, fg="red")
        time.sleep(delay)
633539
function undeclaredGrammar(grammarName, namespace, interval) {
  var message = namespace ?
      'Grammar ' + grammarName + ' is not declared in namespace ' + Namespace.toString(namespace) :
      ' ' + grammarName;
  return createError(message, interval);
}