uid stringlengths 24 24 | split stringclasses 1
value | category stringclasses 2
values | content stringlengths 5 482k | signature stringlengths 1 14k | suffix stringlengths 1 482k | prefix stringlengths 9 14k | prefix_token_count int64 3 5.01k | prefix_token_budget int64 64 256 | element_token_count int64 1 292k | signature_token_count int64 1 5.01k | prefix_context_token_count int64 0 255 | repo stringlengths 7 112 | path stringlengths 4 208 | language stringclasses 1
value | name stringlengths 1 218 | qualname stringlengths 1 218 | start_line int64 1 26.7k | end_line int64 1 26.7k | signature_start_line int64 1 26.7k | signature_end_line int64 1 26.7k | source_hash stringlengths 40 40 | source_dataset stringclasses 1
value | source_split stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ac6f62d4f94484ca9b901086 | train | function | def p_return_statement(s):
# s.sy == 'return'
pos = s.position()
s.next()
if s.sy not in statement_terminators:
value = p_testlist(s)
else:
value = None
return Nodes.ReturnStatNode(pos, value = value)
| def p_return_statement(s):
# s.sy == 'return'
| pos = s.position()
s.next()
if s.sy not in statement_terminators:
value = p_testlist(s)
else:
value = None
return Nodes.ReturnStatNode(pos, value = value)
| = s.position()
s.next()
return Nodes.BreakStatNode(pos)
def p_continue_statement(s):
# s.sy == 'continue'
pos = s.position()
s.next()
return Nodes.ContinueStatNode(pos)
def p_return_statement(s):
# s.sy == 'return'
| 64 | 64 | 63 | 14 | 50 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_return_statement | p_return_statement | 1,621 | 1,629 | 1,621 | 1,622 | 8bd2d39dcd35bf527ac593167c04e80baccac101 | bigcode/the-stack | train |
73e606dd575d40988b7b7346 | train | function | def p_not_test(s):
if s.sy == 'not':
pos = s.position()
s.next()
return ExprNodes.NotNode(pos, operand = p_not_test(s))
else:
return p_comparison(s)
| def p_not_test(s):
| if s.sy == 'not':
pos = s.position()
s.next()
return ExprNodes.NotNode(pos, operand = p_not_test(s))
else:
return p_comparison(s)
| ' not_test)*
def p_and_test(s):
#return p_binop_expr(s, ('and',), p_not_test)
return p_rassoc_binop_expr(s, ('and',), p_not_test)
#not_test: 'not' not_test | comparison
def p_not_test(s):
| 64 | 64 | 49 | 6 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_not_test | p_not_test | 183 | 189 | 183 | 183 | 284ab8784361079049ea22cc79e605effdb496ab | bigcode/the-stack | train |
eeaa8c1f8c82aacbc6d20abd | train | function | def p_sizeof(s):
# s.sy == ident "sizeof"
pos = s.position()
s.next()
s.expect('(')
# Here we decide if we are looking at an expression or type
# If it is actually a type, but parsable as an expression,
# we treat it as an expression here.
if looking_at_expr(s):
operand = p_test(... | def p_sizeof(s):
# s.sy == ident "sizeof"
| pos = s.position()
s.next()
s.expect('(')
# Here we decide if we are looking at an expression or type
# If it is actually a type, but parsable as an expression,
# we treat it as an expression here.
if looking_at_expr(s):
operand = p_test(s)
node = ExprNodes.SizeofVarNode(pos,... | Node(pos, base_type_node=base_type, operand=operand)
return ExprNodes.TypecastNode(pos,
base_type = base_type,
declarator = declarator,
operand = operand,
typecheck = typecheck)
def p_sizeof(s):
# s.sy == ident "sizeof"
| 64 | 64 | 163 | 15 | 49 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_sizeof | p_sizeof | 340 | 357 | 340 | 341 | 17b78655cc1f2f8371f58003845a9f371508c446 | bigcode/the-stack | train |
dfc860f003f82029da906233 | train | function | def p_visibility(s, prev_visibility):
pos = s.position()
visibility = prev_visibility
if s.sy == 'IDENT' and s.systring in ('extern', 'public', 'readonly'):
visibility = s.systring
if prev_visibility != 'private' and visibility != prev_visibility:
s.error("Conflicting visibility ... | def p_visibility(s, prev_visibility):
| pos = s.position()
visibility = prev_visibility
if s.sy == 'IDENT' and s.systring in ('extern', 'public', 'readonly'):
visibility = s.systring
if prev_visibility != 'private' and visibility != prev_visibility:
s.error("Conflicting visibility options '%s' and '%s'"
... | , name=name, types=types)
def p_struct_enum(s, pos, ctx):
if s.systring == 'enum':
return p_c_enum_definition(s, pos, ctx)
else:
return p_c_struct_or_union_definition(s, pos, ctx)
def p_visibility(s, prev_visibility):
| 64 | 64 | 97 | 8 | 56 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_visibility | p_visibility | 3,255 | 3,264 | 3,255 | 3,255 | f0562342b9a0f1b551194d41652ea522c09da116 | bigcode/the-stack | train |
c5905ebefeb0ee469f06af18 | train | function | def p_compile_time_expr(s):
old = s.compile_time_expr
s.compile_time_expr = 1
expr = p_testlist(s)
s.compile_time_expr = old
return expr
| def p_compile_time_expr(s):
| old = s.compile_time_expr
s.compile_time_expr = 1
expr = p_testlist(s)
s.compile_time_expr = old
return expr
| .is_name and stat.expr.name == 'cdef':
s.error("The 'cdef' keyword is only allowed in Cython files (pyx/pxi/pxd)", pos)
s.expect_newline("Syntax error in simple statement list")
return stat
def p_compile_time_expr(s):
| 64 | 64 | 44 | 7 | 56 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_compile_time_expr | p_compile_time_expr | 2,176 | 2,181 | 2,176 | 2,176 | 7db93d24d57630e957566e3d55184f12e7f5f3a1 | bigcode/the-stack | train |
9b840e202b2cf0e1ef42cb27 | train | function | def p_c_enum_definition(s, pos, ctx):
# s.sy == ident 'enum'
s.next()
if s.sy == 'IDENT':
name = s.systring
s.next()
cname = p_opt_cname(s)
if cname is None and ctx.namespace is not None:
cname = ctx.namespace + "::" + name
else:
name = None
cn... | def p_c_enum_definition(s, pos, ctx):
# s.sy == ident 'enum'
| s.next()
if s.sy == 'IDENT':
name = s.systring
s.next()
cname = p_opt_cname(s)
if cname is None and ctx.namespace is not None:
cname = ctx.namespace + "::" + name
else:
name = None
cname = None
items = None
s.expect(':')
items = []
... | body = p_suite_with_docstring(s, ctx, True)
return Nodes.CDefExternNode(pos,
include_file = include_file,
verbatim_include = verbatim_include,
body = body,
namespace = ctx.namespace)
def p_c_enum_definition(s, pos, ctx):
# s.sy == ident 'enum'
| 69 | 69 | 233 | 20 | 49 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_c_enum_definition | p_c_enum_definition | 3,121 | 3,148 | 3,121 | 3,122 | 1d8c5a5eed7a949a2726bdfa3d18c30e95865742 | bigcode/the-stack | train |
6a98f8d3aa0c2c238a45b3d5 | train | function | def p_ident(s, message="Expected an identifier"):
if s.sy == 'IDENT':
name = s.context.intern_ustring(s.systring)
s.next()
return name
else:
s.error(message)
| def p_ident(s, message="Expected an identifier"):
| if s.sy == 'IDENT':
name = s.context.intern_ustring(s.systring)
s.next()
return name
else:
s.error(message)
| ):
self.__dict__.update(kwds)
def __call__(self, **kwds):
ctx = Ctx()
d = ctx.__dict__
d.update(self.__dict__)
d.update(kwds)
return ctx
def p_ident(s, message="Expected an identifier"):
| 64 | 64 | 49 | 11 | 52 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_ident | p_ident | 66 | 72 | 66 | 66 | ce8f49b013c0d03105f31f67e422b386137d470c | bigcode/the-stack | train |
936965d781a4f1825bb1add3 | train | function | def p_for_iterator(s, allow_testlist=True, is_async=False):
pos = s.position()
if allow_testlist:
expr = p_testlist(s)
else:
expr = p_or_test(s)
return (ExprNodes.AsyncIteratorNode if is_async else ExprNodes.IteratorNode)(pos, sequence=expr)
| def p_for_iterator(s, allow_testlist=True, is_async=False):
| pos = s.position()
if allow_testlist:
expr = p_testlist(s)
else:
expr = p_or_test(s)
return (ExprNodes.AsyncIteratorNode if is_async else ExprNodes.IteratorNode)(pos, sequence=expr)
| if s.sy != ',':
break
s.next()
return ExprNodes.TupleNode(pos, args = exprs)
else:
return expr
def p_for_target(s):
return p_target(s, 'in')
def p_for_iterator(s, allow_testlist=True, is_async=False):
| 64 | 64 | 69 | 15 | 49 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_for_iterator | p_for_iterator | 1,952 | 1,958 | 1,952 | 1,952 | 28b9ab312d4405c6f42553ebc9c94fc7e8512a1c | bigcode/the-stack | train |
d460a70b5ebbe17e1f0ead6e | train | function | def p_statement_list(s, ctx, first_statement = 0):
# Parse a series of statements separated by newlines.
pos = s.position()
stats = []
while s.sy not in ('DEDENT', 'EOF'):
stat = p_statement(s, ctx, first_statement = first_statement)
if isinstance(stat, Nodes.PassStatNode):
c... | def p_statement_list(s, ctx, first_statement = 0):
# Parse a series of statements separated by newlines.
| pos = s.position()
stats = []
while s.sy not in ('DEDENT', 'EOF'):
stat = p_statement(s, ctx, first_statement = first_statement)
if isinstance(stat, Nodes.PassStatNode):
continue
stats.append(stat)
first_statement = False
if not stats:
return Nodes.Pas... | functions or classes")
s.put_back('IDENT', ident_name) # re-insert original token
return p_simple_statement_list(s, ctx, first_statement=first_statement)
def p_statement_list(s, ctx, first_statement = 0):
# Parse a series of statements separated by newlines.
| 64 | 64 | 131 | 26 | 38 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_statement_list | p_statement_list | 2,326 | 2,341 | 2,326 | 2,327 | 6bdaf1877a26e28cff2bc4077298c52902dc5fcd | bigcode/the-stack | train |
cd80a5ad84d5e55e82ed82b1 | train | function | def p_memoryviewslice_access(s, base_type_node):
# s.sy == '['
pos = s.position()
s.next()
subscripts, _ = p_subscript_list(s)
# make sure each entry in subscripts is a slice
for subscript in subscripts:
if len(subscript) < 2:
s.error("An axis specification in memoryview decl... | def p_memoryviewslice_access(s, base_type_node):
# s.sy == '['
| pos = s.position()
s.next()
subscripts, _ = p_subscript_list(s)
# make sure each entry in subscripts is a slice
for subscript in subscripts:
if len(subscript) < 2:
s.error("An axis specification in memoryview declaration does not have a ':'.")
s.expect(']')
indexes = make... | saved.append((s.sy, s.systring))
s.next()
if s.sy == ':':
retval = True
for sv in saved[::-1]:
s.put_back(*sv)
return retval
def p_memoryviewslice_access(s, base_type_node):
# s.sy == '['
| 64 | 64 | 135 | 19 | 44 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_memoryviewslice_access | p_memoryviewslice_access | 2,640 | 2,654 | 2,640 | 2,641 | b34421505980d9acabbc3697f94be407acc9ab47 | bigcode/the-stack | train |
cb9b2fe398a7d263c4ba1f61 | train | function | def p_for_from_relation(s):
if s.sy in inequality_relations:
op = s.sy
s.next()
return op
else:
s.error("Expected one of '<', '<=', '>' '>='")
| def p_for_from_relation(s):
| if s.sy in inequality_relations:
op = s.sy
s.next()
return op
else:
s.error("Expected one of '<', '<=', '>' '>='")
| not match")
return dict(target = target,
bound1 = bound1,
relation1 = rel1,
relation2 = rel2,
bound2 = bound2,
step = step,
)
else:
s.expect('in')
return {}
def p_for_from... | 64 | 64 | 49 | 7 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_for_from_relation | p_for_from_relation | 1,914 | 1,920 | 1,914 | 1,914 | 4c7fa6069d86feb15f0e4202c76e504418cf2693 | bigcode/the-stack | train |
654d8aa117d5c98b2cbf54ba | train | function | def p_dotted_name(s, as_allowed):
pos = s.position()
target_name = p_ident(s)
as_name = None
names = [target_name]
while s.sy == '.':
s.next()
names.append(p_ident(s))
if as_allowed:
as_name = p_as_name(s)
return (pos, target_name, s.context.intern_ustring(u'.'.join(n... | def p_dotted_name(s, as_allowed):
| pos = s.position()
target_name = p_ident(s)
as_name = None
names = [target_name]
while s.sy == '.':
s.next()
names.append(p_ident(s))
if as_allowed:
as_name = p_as_name(s)
return (pos, target_name, s.context.intern_ustring(u'.'.join(names)), as_name)
| if is_cimport and s.systring in imported_name_kinds:
kind = s.systring
s.next()
name = p_ident(s)
as_name = p_as_name(s)
return (pos, name, as_name, kind)
def p_dotted_name(s, as_allowed):
| 64 | 64 | 93 | 10 | 54 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_dotted_name | p_dotted_name | 1,786 | 1,796 | 1,786 | 1,786 | ac6dc3e293abb068275aeb07ced97c70d4f0bc43 | bigcode/the-stack | train |
084026bc510d2eeadea50edc | train | function | def p_c_declarator(s, ctx = Ctx(), empty = 0, is_type = 0, cmethod_flag = 0,
assignable = 0, nonempty = 0,
calling_convention_allowed = 0):
# If empty is true, the declarator must be empty. If nonempty is true,
# the declarator must be nonempty. Otherwise we don't care.
... | def p_c_declarator(s, ctx = Ctx(), empty = 0, is_type = 0, cmethod_flag = 0,
assignable = 0, nonempty = 0,
calling_convention_allowed = 0):
# If empty is true, the declarator must be empty. If nonempty is true,
# the declarator must be nonempty. Otherwise we don't care.
... | pos = s.position()
if s.sy == '(':
s.next()
if s.sy == ')' or looking_at_name(s):
base = Nodes.CNameDeclaratorNode(pos, name=s.context.intern_ustring(u""), cname=None)
result = p_c_func_declarator(s, pos, ctx, base, cmethod_flag)
else:
result = p_c_dec... | cname
def p_c_declarator(s, ctx = Ctx(), empty = 0, is_type = 0, cmethod_flag = 0,
assignable = 0, nonempty = 0,
calling_convention_allowed = 0):
# If empty is true, the declarator must be empty. If nonempty is true,
# the declarator must be nonempty. Otherwise we don't ca... | 120 | 120 | 403 | 118 | 1 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_c_declarator | p_c_declarator | 2,775 | 2,808 | 2,775 | 2,781 | 14cb0887600a0742bda88c5bd432fd1b212fa4a3 | bigcode/the-stack | train |
c45e429b00798adab6b1c400 | train | function | def p_fused_definition(s, pos, ctx):
"""
c(type)def fused my_fused_type:
...
"""
# s.systring == 'fused'
if ctx.level not in ('module', 'module_pxd'):
error(pos, "Fused type definition not allowed here")
s.next()
name = p_ident(s)
s.expect(":")
s.expect_newline()
... | def p_fused_definition(s, pos, ctx):
| """
c(type)def fused my_fused_type:
...
"""
# s.systring == 'fused'
if ctx.level not in ('module', 'module_pxd'):
error(pos, "Fused type definition not allowed here")
s.next()
name = p_ident(s)
s.expect(":")
s.expect_newline()
s.expect_indent()
types = []
... | name = name, cname = cname, kind = kind, attributes = attributes,
typedef_flag = ctx.typedef_flag, visibility = ctx.visibility,
api = ctx.api, in_pxd = ctx.level == 'module_pxd', packed = packed)
def p_fused_definition(s, pos, ctx):
| 64 | 64 | 191 | 11 | 53 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_fused_definition | p_fused_definition | 3,215 | 3,247 | 3,215 | 3,215 | e04ed1b9d7ca58665cc0719c573b8427c4823d1e | bigcode/the-stack | train |
43e400d1f5f022555e980534 | train | function | def p_bracketed_base_type(s, base_type_node, nonempty, empty):
# s.sy == '['
if empty and not nonempty:
# sizeof-like thing. Only anonymous C arrays allowed (int[SIZE]).
return base_type_node
elif not empty and nonempty:
# declaration of either memoryview slice or buffer.
if... | def p_bracketed_base_type(s, base_type_node, nonempty, empty):
# s.sy == '['
| if empty and not nonempty:
# sizeof-like thing. Only anonymous C arrays allowed (int[SIZE]).
return base_type_node
elif not empty and nonempty:
# declaration of either memoryview slice or buffer.
if is_memoryviewslice_access(s):
return p_memoryviewslice_access(s, bas... | ])
result = Nodes.TemplatedTypeNode(pos,
positional_args = positional_args,
keyword_args = keyword_dict,
base_type_node = base_type_node)
return result
def p_bracketed_base_type(s, base_type_node, nonempty, empty):
# s.sy == '['
| 64 | 64 | 202 | 25 | 38 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_bracketed_base_type | p_bracketed_base_type | 2,598 | 2,617 | 2,598 | 2,599 | 938766d826a7ad6c9df454832fde836f34b3a2c2 | bigcode/the-stack | train |
8ba7b47ae99d2f0dd9bc0b9a | train | function | def p_comp_for(s, body):
pos = s.position()
# [async] for ...
is_async = False
if s.sy == 'async':
is_async = True
s.next()
# s.sy == 'for'
s.expect('for')
kw = p_for_bounds(s, allow_testlist=False, is_async=is_async)
kw.update(else_clause=None, body=p_comp_iter(s, body)... | def p_comp_for(s, body):
| pos = s.position()
# [async] for ...
is_async = False
if s.sy == 'async':
is_async = True
s.next()
# s.sy == 'for'
s.expect('for')
kw = p_for_bounds(s, allow_testlist=False, is_async=is_async)
kw.update(else_clause=None, body=p_comp_iter(s, body), is_async=is_async)
... | if s.sy in ('for', 'async'):
return p_comp_for(s, body)
elif s.sy == 'if':
return p_comp_if(s, body)
else:
# insert the 'append' operation into the loop
return body
def p_comp_for(s, body):
| 64 | 64 | 109 | 8 | 55 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_comp_for | p_comp_for | 1,247 | 1,259 | 1,247 | 1,247 | 2ef06df6800d3da098f8e028dc8804ddf1a40ba1 | bigcode/the-stack | train |
4f7916d6ce6a19e411092f85 | train | function | def p_comp_if(s, body):
# s.sy == 'if'
pos = s.position()
s.next()
test = p_test_nocond(s)
return Nodes.IfStatNode(pos,
if_clauses = [Nodes.IfClauseNode(pos, condition = test,
body = p_comp_iter(s, body))],
else_clause = None )
| def p_comp_if(s, body):
# s.sy == 'if'
| pos = s.position()
s.next()
test = p_test_nocond(s)
return Nodes.IfStatNode(pos,
if_clauses = [Nodes.IfClauseNode(pos, condition = test,
body = p_comp_iter(s, body))],
else_clause = None )
| = p_for_bounds(s, allow_testlist=False, is_async=is_async)
kw.update(else_clause=None, body=p_comp_iter(s, body), is_async=is_async)
return Nodes.ForStatNode(pos, **kw)
def p_comp_if(s, body):
# s.sy == 'if'
| 64 | 64 | 78 | 16 | 48 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_comp_if | p_comp_if | 1,261 | 1,269 | 1,261 | 1,262 | f22bbe9d0a5e6d920efa51005dff28c12442607f | bigcode/the-stack | train |
71c3ca4f12d6df543c2ba5dc | train | function | def _reject_cdef_modifier_in_py(s, name):
"""Step over incorrectly placed cdef modifiers (@see _CDEF_MODIFIERS) to provide a good error message for them.
"""
if s.sy == 'IDENT' and name in _CDEF_MODIFIERS:
# Special enough to provide a good error message.
s.error("Cannot use cdef modifier '%... | def _reject_cdef_modifier_in_py(s, name):
| """Step over incorrectly placed cdef modifiers (@see _CDEF_MODIFIERS) to provide a good error message for them.
"""
if s.sy == 'IDENT' and name in _CDEF_MODIFIERS:
# Special enough to provide a good error message.
s.error("Cannot use cdef modifier '%s' in Python function signature. Use a dec... | =decorator)
if s.sy == '(':
decorator = p_call(s, decorator)
decorators.append(Nodes.DecoratorNode(pos, decorator=decorator))
s.expect_newline("Expected a newline after decorator")
return decorators
def _reject_cdef_modifier_in_py(s, name):
| 64 | 64 | 120 | 12 | 51 | 0101011/cython | Cython/Compiler/Parsing.py | Python | _reject_cdef_modifier_in_py | _reject_cdef_modifier_in_py | 3,380 | 3,387 | 3,380 | 3,380 | 3ca7dde4144bab4235894680e2712dc364d1c557 | bigcode/the-stack | train |
959e9d87c92a02564d71b319 | train | function | def _append_escape_sequence(kind, builder, escape_sequence, s):
c = escape_sequence[1]
if c in u"01234567":
builder.append_charval(int(escape_sequence[1:], 8))
elif c in u"'\"\\":
builder.append(c)
elif c in u"abfnrtv":
builder.append(StringEncoding.char_from_escape_sequence(esca... | def _append_escape_sequence(kind, builder, escape_sequence, s):
| c = escape_sequence[1]
if c in u"01234567":
builder.append_charval(int(escape_sequence[1:], 8))
elif c in u"'\"\\":
builder.append(c)
elif c in u"abfnrtv":
builder.append(StringEncoding.char_from_escape_sequence(escape_sequence))
elif c == u'\n':
pass # line continua... | r" % bytes_value)
else:
bytes_value, unicode_value = chars.getstrings()
if (has_non_ascii_literal_characters
and is_python3_source and Future.unicode_literals in s.context.future_directives):
# Python 3 forbids literal non-ASCII characters in byte strings
if k... | 152 | 152 | 508 | 14 | 138 | 0101011/cython | Cython/Compiler/Parsing.py | Python | _append_escape_sequence | _append_escape_sequence | 971 | 1,014 | 971 | 971 | eb171a6c47ce7251dbf882e14df44699e5f08e5e | bigcode/the-stack | train |
143bd0f700b5a85932326295 | train | function | def p_cat_string_literal(s):
# A sequence of one or more adjacent string literals.
# Returns (kind, bytes_value, unicode_value)
# where kind in ('b', 'c', 'u', 'f', '')
pos = s.position()
kind, bytes_value, unicode_value = p_string_literal(s)
if kind == 'c' or s.sy != 'BEGIN_STRING':
ret... | def p_cat_string_literal(s):
# A sequence of one or more adjacent string literals.
# Returns (kind, bytes_value, unicode_value)
# where kind in ('b', 'c', 'u', 'f', '')
| pos = s.position()
kind, bytes_value, unicode_value = p_string_literal(s)
if kind == 'c' or s.sy != 'BEGIN_STRING':
return kind, bytes_value, unicode_value
bstrings, ustrings, positions = [bytes_value], [unicode_value], [pos]
bytes_value = unicode_value = None
while s.sy == 'BEGIN_STRING... | args:
return ExprNodes.TupleNode(pos, args=args)
else:
# error already reported
return None
elif not _IS_PY3 and isinstance(value, long):
return ExprNodes.IntNode(pos, value=rep.rstrip('L'), constant_result=value)
error(pos, "Invalid type for compile-time con... | 142 | 142 | 474 | 49 | 92 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_cat_string_literal | p_cat_string_literal | 804 | 845 | 804 | 807 | 34ad023071ae19ed30cfef8635dc8647550bdfd7 | bigcode/the-stack | train |
4f14583a56fcaa76261142e3 | train | function | def p_cmp_op(s):
if s.sy == 'not':
s.next()
s.expect('in')
op = 'not_in'
elif s.sy == 'is':
s.next()
if s.sy == 'not':
s.next()
op = 'is_not'
else:
op = 'is'
else:
op = s.sy
s.next()
if op == '<>':
... | def p_cmp_op(s):
| if s.sy == 'not':
s.next()
s.expect('in')
op = 'not_in'
elif s.sy == 'is':
s.next()
if s.sy == 'not':
s.next()
op = 'is_not'
else:
op = 'is'
else:
op = s.sy
s.next()
if op == '<>':
op = '!='
r... | )
n2 = p_starred_expr(s)
result = ExprNodes.CascadedCmpNode(pos,
operator = op, operand2 = n2)
if s.sy in comparison_ops:
result.cascade = p_cascaded_cmp(s)
return result
def p_cmp_op(s):
| 64 | 64 | 101 | 6 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_cmp_op | p_cmp_op | 234 | 251 | 234 | 234 | d4d04d93d2874558bf8b5c45b9f84ef89b669feb | bigcode/the-stack | train |
c96a516ccdbe922372882689 | train | function | def looking_at_expr(s):
if s.systring in base_type_start_words:
return False
elif s.sy == 'IDENT':
is_type = False
name = s.systring
dotted_path = []
s.next()
while s.sy == '.':
s.next()
dotted_path.append(s.systring)
s.expect(... | def looking_at_expr(s):
| if s.systring in base_type_start_words:
return False
elif s.sy == 'IDENT':
is_type = False
name = s.systring
dotted_path = []
s.next()
while s.sy == '.':
s.next()
dotted_path.append(s.systring)
s.expect('IDENT')
saved ... | ]')
indexes = make_slice_nodes(pos, subscripts)
result = Nodes.MemoryViewSliceTypeNode(pos,
base_type_node = base_type_node,
axes = indexes)
return result
def looking_at_name(s):
return s.sy == 'IDENT' and not s.systring in calling_convention_words
def looking_at_expr(s):
| 72 | 72 | 243 | 6 | 65 | 0101011/cython | Cython/Compiler/Parsing.py | Python | looking_at_expr | looking_at_expr | 2,659 | 2,697 | 2,659 | 2,659 | 7476cb3de15e3cd438212b598f731c004f7ae4f8 | bigcode/the-stack | train |
26d8ccc21a92880d1861ef84 | train | function | def p_call_parse_args(s, allow_genexp=True):
# s.sy == '('
pos = s.position()
s.next()
positional_args = []
keyword_args = []
starstar_seen = False
last_was_tuple_unpack = False
while s.sy != ')':
if s.sy == '*':
if starstar_seen:
s.error("Non-keyword ... | def p_call_parse_args(s, allow_genexp=True):
# s.sy == '('
| pos = s.position()
s.next()
positional_args = []
keyword_args = []
starstar_seen = False
last_was_tuple_unpack = False
while s.sy != ')':
if s.sy == '*':
if starstar_seen:
s.error("Non-keyword arg following keyword arg", pos=s.position())
s.nex... | # s.sy == '.'
s.next()
name = p_ident(s)
return ExprNodes.AttributeNode(pos,
obj=node1, attribute=name)
# arglist: argument (',' argument)* [',']
# argument: [test '='] test # Really [keyword '='] test
# since PEP 448:
# argument: ( test [comp_for] |
# test '='... | 116 | 116 | 388 | 19 | 97 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_call_parse_args | p_call_parse_args | 461 | 509 | 461 | 462 | 13ec2744e26162a942183de49a66858f7e52675d | bigcode/the-stack | train |
6cade2d4c75bf89970bdf87f | train | function | def _p_factor(s):
sy = s.sy
if sy in ('+', '-', '~'):
op = s.sy
pos = s.position()
s.next()
return ExprNodes.unop_node(pos, op, p_factor(s))
elif not s.in_python_file:
if sy == '&':
pos = s.position()
s.next()
arg = p_factor(s)
... | def _p_factor(s):
| sy = s.sy
if sy in ('+', '-', '~'):
op = s.sy
pos = s.position()
s.next()
return ExprNodes.unop_node(pos, op, p_factor(s))
elif not s.in_python_file:
if sy == '&':
pos = s.position()
s.next()
arg = p_factor(s)
return Exp... | ', '@', '/', '%', '//'), p_factor)
#factor: ('+'|'-'|'~'|'&'|typecast|sizeof) factor | power
def p_factor(s):
# little indirection for C-ification purposes
return _p_factor(s)
def _p_factor(s):
| 64 | 64 | 139 | 6 | 58 | 0101011/cython | Cython/Compiler/Parsing.py | Python | _p_factor | _p_factor | 294 | 311 | 294 | 294 | 86506b42b5308b274f871964f570dec433cea2ce | bigcode/the-stack | train |
e35119089b2d1362af0d74e0 | train | function | def p_c_complex_base_type(s, templates = None):
# s.sy == '('
pos = s.position()
s.next()
base_type = p_c_base_type(s, templates=templates)
declarator = p_c_declarator(s, empty=True)
type_node = Nodes.CComplexBaseTypeNode(
pos, base_type=base_type, declarator=declarator)
if s.sy == '... | def p_c_complex_base_type(s, templates = None):
# s.sy == '('
| pos = s.position()
s.next()
base_type = p_c_base_type(s, templates=templates)
declarator = p_c_declarator(s, empty=True)
type_node = Nodes.CComplexBaseTypeNode(
pos, base_type=base_type, declarator=declarator)
if s.sy == ',':
components = [type_node]
while s.sy == ',':
... | .systring in calling_convention_words:
result = s.systring
s.next()
return result
else:
return ""
calling_convention_words = cython.declare(
set, set(["__stdcall", "__cdecl", "__fastcall"]))
def p_c_complex_base_type(s, templates = None):
# s.sy == '('
| 73 | 74 | 249 | 19 | 54 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_c_complex_base_type | p_c_complex_base_type | 2,448 | 2,474 | 2,448 | 2,449 | 6cf7f7c75a0b76ad931000fc64a9389fbc583e7a | bigcode/the-stack | train |
6c1f7eb4fcc6d7eedb1a2a64 | train | function | def p_c_enum_line(s, ctx, items):
if s.sy != 'pass':
p_c_enum_item(s, ctx, items)
while s.sy == ',':
s.next()
if s.sy in ('NEWLINE', 'EOF'):
break
p_c_enum_item(s, ctx, items)
else:
s.next()
s.expect_newline("Syntax error in enum it... | def p_c_enum_line(s, ctx, items):
| if s.sy != 'pass':
p_c_enum_item(s, ctx, items)
while s.sy == ',':
s.next()
if s.sy in ('NEWLINE', 'EOF'):
break
p_c_enum_item(s, ctx, items)
else:
s.next()
s.expect_newline("Syntax error in enum item list")
| name = name, cname = cname, items = items,
typedef_flag = ctx.typedef_flag, visibility = ctx.visibility,
create_wrapper = ctx.overridable,
api = ctx.api, in_pxd = ctx.level == 'module_pxd')
def p_c_enum_line(s, ctx, items):
| 64 | 64 | 87 | 11 | 53 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_c_enum_line | p_c_enum_line | 3,150 | 3,160 | 3,150 | 3,150 | b145d0c3f75e48bd82ede21d97df848b6343f960 | bigcode/the-stack | train |
dce3be1263616c3849ea2d12 | train | function | def p_target(s, terminator):
pos = s.position()
expr = p_starred_expr(s)
if s.sy == ',':
s.next()
exprs = [expr]
while s.sy != terminator:
exprs.append(p_starred_expr(s))
if s.sy != ',':
break
s.next()
return ExprNodes.Tuple... | def p_target(s, terminator):
| pos = s.position()
expr = p_starred_expr(s)
if s.sy == ',':
s.next()
exprs = [expr]
while s.sy != terminator:
exprs.append(p_starred_expr(s))
if s.sy != ',':
break
s.next()
return ExprNodes.TupleNode(pos, args = exprs)
e... | IDENT' and s.systring == 'by':
s.next()
step = p_bit_expr(s)
return step
else:
return None
inequality_relations = cython.declare(set, set(['<', '<=', '>', '>=']))
def p_target(s, terminator):
| 63 | 64 | 93 | 8 | 55 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_target | p_target | 1,932 | 1,945 | 1,932 | 1,932 | b27ec4a980533564e666385782fe145f0e331c21 | bigcode/the-stack | train |
191b104b512111cab5079f49 | train | function | def p_global_statement(s):
# assume s.sy == 'global'
pos = s.position()
s.next()
names = p_ident_list(s)
return Nodes.GlobalNode(pos, names = names)
| def p_global_statement(s):
# assume s.sy == 'global'
| pos = s.position()
s.next()
names = p_ident_list(s)
return Nodes.GlobalNode(pos, names = names)
| ExpressionNode(expr.pos, loop=loop)
expr_terminators = cython.declare(set, set([
')', ']', '}', ':', '=', 'NEWLINE']))
#-------------------------------------------------------
#
# Statements
#
#-------------------------------------------------------
def p_global_statement(s):
# assume s.sy == 'global'
| 64 | 64 | 44 | 15 | 49 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_global_statement | p_global_statement | 1,477 | 1,482 | 1,477 | 1,478 | df59b4800b2c9971d3b7a5a58cf8d43889a494e3 | bigcode/the-stack | train |
0921c77b291d2ba7978ba06b | train | function | def p_else_clause(s):
if s.sy == 'else':
s.next()
return p_suite(s)
else:
return None
| def p_else_clause(s):
| if s.sy == 'else':
s.next()
return p_suite(s)
else:
return None
| _clauses = if_clauses, else_clause = else_clause)
def p_if_clause(s):
pos = s.position()
test = p_test(s)
body = p_suite(s)
return Nodes.IfClauseNode(pos,
condition = test, body = body)
def p_else_clause(s):
| 64 | 64 | 31 | 6 | 58 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_else_clause | p_else_clause | 1,841 | 1,846 | 1,841 | 1,841 | cf17e419c8db8d03658498d520142ebb0e0946ca | bigcode/the-stack | train |
a517a4a469fd785cef46da99 | train | function | def p_c_enum_item(s, ctx, items):
pos = s.position()
name = p_ident(s)
cname = p_opt_cname(s)
if cname is None and ctx.namespace is not None:
cname = ctx.namespace + "::" + name
value = None
if s.sy == '=':
s.next()
value = p_test(s)
items.append(Nodes.CEnumDefItemNod... | def p_c_enum_item(s, ctx, items):
| pos = s.position()
name = p_ident(s)
cname = p_opt_cname(s)
if cname is None and ctx.namespace is not None:
cname = ctx.namespace + "::" + name
value = None
if s.sy == '=':
s.next()
value = p_test(s)
items.append(Nodes.CEnumDefItemNode(pos,
name = name, cname ... | == ',':
s.next()
if s.sy in ('NEWLINE', 'EOF'):
break
p_c_enum_item(s, ctx, items)
else:
s.next()
s.expect_newline("Syntax error in enum item list")
def p_c_enum_item(s, ctx, items):
| 64 | 64 | 104 | 11 | 53 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_c_enum_item | p_c_enum_item | 3,162 | 3,173 | 3,162 | 3,162 | 35b19836a0241cb07a509009bfb5e0fd09bcbbbc | bigcode/the-stack | train |
57561b44557552f0cab352c0 | train | function | def p_suite_with_docstring(s, ctx, with_doc_only=False):
s.expect(':')
doc = None
if s.sy == 'NEWLINE':
s.next()
s.expect_indent()
if with_doc_only:
doc = p_doc_string(s)
body = p_statement_list(s, ctx)
s.expect_dedent()
else:
if ctx.api:
... | def p_suite_with_docstring(s, ctx, with_doc_only=False):
| s.expect(':')
doc = None
if s.sy == 'NEWLINE':
s.next()
s.expect_indent()
if with_doc_only:
doc = p_doc_string(s)
body = p_statement_list(s, ctx)
s.expect_dedent()
else:
if ctx.api:
s.error("'api' not allowed with this statement", f... | :
return stats[0]
else:
return Nodes.StatListNode(pos, stats = stats)
def p_suite(s, ctx=Ctx()):
return p_suite_with_docstring(s, ctx, with_doc_only=False)[1]
def p_suite_with_docstring(s, ctx, with_doc_only=False):
| 64 | 64 | 175 | 15 | 49 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_suite_with_docstring | p_suite_with_docstring | 2,348 | 2,368 | 2,348 | 2,348 | fe9b0f90019a5750f49143ab3d0424b2595d06c0 | bigcode/the-stack | train |
9afafcb4dd721b4787ecd405 | train | function | def p_for_from_step(s):
if s.sy == 'IDENT' and s.systring == 'by':
s.next()
step = p_bit_expr(s)
return step
else:
return None
| def p_for_from_step(s):
| if s.sy == 'IDENT' and s.systring == 'by':
s.next()
step = p_bit_expr(s)
return step
else:
return None
| s.expect('in')
return {}
def p_for_from_relation(s):
if s.sy in inequality_relations:
op = s.sy
s.next()
return op
else:
s.error("Expected one of '<', '<=', '>' '>='")
def p_for_from_step(s):
| 64 | 64 | 46 | 7 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_for_from_step | p_for_from_step | 1,922 | 1,928 | 1,922 | 1,922 | df35ce529a0e8c43d9c5356efa40f8d2460051d5 | bigcode/the-stack | train |
051bd58a9e033c35f67004dd | train | function | def p_binop_operator(s):
pos = s.position()
op = s.sy
s.next()
return op, pos
| def p_binop_operator(s):
| pos = s.position()
op = s.sy
s.next()
return op, pos
| []
while s.sy == 'IDENT':
names.append(s.context.intern_ustring(s.systring))
s.next()
if s.sy != ',':
break
s.next()
return names
#------------------------------------------
#
# Expressions
#
#------------------------------------------
def p_binop_operator(s):
| 64 | 64 | 29 | 7 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_binop_operator | p_binop_operator | 90 | 94 | 90 | 90 | 1c21409cb277f3161aa63a0a81d4e7fbcbabba7a | bigcode/the-stack | train |
6bcdd681b953a5bede4d0c2b | train | function | def wrap_compile_time_constant(pos, value):
rep = repr(value)
if value is None:
return ExprNodes.NoneNode(pos)
elif value is Ellipsis:
return ExprNodes.EllipsisNode(pos)
elif isinstance(value, bool):
return ExprNodes.BoolNode(pos, value=value)
elif isinstance(value, int):
... | def wrap_compile_time_constant(pos, value):
| rep = repr(value)
if value is None:
return ExprNodes.NoneNode(pos)
elif value is Ellipsis:
return ExprNodes.EllipsisNode(pos)
elif isinstance(value, bool):
return ExprNodes.BoolNode(pos, value=value)
elif isinstance(value, int):
return ExprNodes.IntNode(pos, value=rep... | ")
is_c_literal = False
return ExprNodes.IntNode(pos,
is_c_literal = is_c_literal,
value = value,
unsigned = unsigned,
longness = longness)
def p_name(s, name):
pos = s.position()
if... | 123 | 123 | 413 | 9 | 114 | 0101011/cython | Cython/Compiler/Parsing.py | Python | wrap_compile_time_constant | wrap_compile_time_constant | 763 | 801 | 763 | 763 | 3ef605766cf50ccfbff30f9236190d5da2035b84 | bigcode/the-stack | train |
ecdf02be700be40a029b9b54 | train | function | def p_ctypedef_statement(s, ctx):
# s.sy == 'ctypedef'
pos = s.position()
s.next()
visibility = p_visibility(s, ctx.visibility)
api = p_api(s)
ctx = ctx(typedef_flag = 1, visibility = visibility)
if api:
ctx.api = 1
if s.sy == 'class':
return p_c_class_definition(s, pos, ... | def p_ctypedef_statement(s, ctx):
# s.sy == 'ctypedef'
| pos = s.position()
s.next()
visibility = p_visibility(s, ctx.visibility)
api = p_api(s)
ctx = ctx(typedef_flag = 1, visibility = visibility)
if api:
ctx.api = 1
if s.sy == 'class':
return p_c_class_definition(s, pos, ctx)
elif s.sy == 'IDENT' and s.systring in struct_enum... | _type,
declarators = declarators,
in_pxd = ctx.level in ('module_pxd', 'c_class_pxd'),
doc = doc,
api = ctx.api,
modifiers = modifiers,
overridable = ctx.overridable)
return result
def p_ctypedef_statement(s, ctx):
# s.sy == 'ctypedef'
| 77 | 77 | 258 | 20 | 56 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_ctypedef_statement | p_ctypedef_statement | 3,337 | 3,360 | 3,337 | 3,338 | f10f6f45ff22627084299cf925f61a4c2857f43a | bigcode/the-stack | train |
c773c24b81e65e34f4026880 | train | function | def p_test(s):
if s.sy == 'lambda':
return p_lambdef(s)
pos = s.position()
expr = p_or_test(s)
if s.sy == 'if':
s.next()
test = p_or_test(s)
s.expect('else')
other = p_test(s)
return ExprNodes.CondExprNode(pos, test=test, true_val=expr, false_val=other)
... | def p_test(s):
| if s.sy == 'lambda':
return p_lambdef(s)
pos = s.position()
expr = p_or_test(s)
if s.sy == 'if':
s.next()
test = p_or_test(s)
s.expect('else')
other = p_test(s)
return ExprNodes.CondExprNode(pos, test=test, true_val=expr, false_val=other)
else:
... | ocond: 'lambda' [varargslist] ':' test_nocond
def p_lambdef_nocond(s):
return p_lambdef(s, allow_conditional=False)
#test: or_test ['if' or_test 'else' test] | lambdef
def p_test(s):
| 64 | 64 | 98 | 5 | 58 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_test | p_test | 138 | 150 | 138 | 138 | 1156c981cac5526fb4bbd51f658e5717c2da35df | bigcode/the-stack | train |
4b490934f321ec327ed28b89 | train | function | def p_for_statement(s, is_async=False):
# s.sy == 'for'
pos = s.position()
s.next()
kw = p_for_bounds(s, allow_testlist=True, is_async=is_async)
body = p_suite(s)
else_clause = p_else_clause(s)
kw.update(body=body, else_clause=else_clause, is_async=is_async)
return Nodes.ForStatNode(pos,... | def p_for_statement(s, is_async=False):
# s.sy == 'for'
| pos = s.position()
s.next()
kw = p_for_bounds(s, allow_testlist=True, is_async=is_async)
body = p_suite(s)
else_clause = p_else_clause(s)
kw.update(body=body, else_clause=else_clause, is_async=is_async)
return Nodes.ForStatNode(pos, **kw)
| = p_test(s)
body = p_suite(s)
else_clause = p_else_clause(s)
return Nodes.WhileStatNode(pos,
condition = test, body = body,
else_clause = else_clause)
def p_for_statement(s, is_async=False):
# s.sy == 'for'
| 64 | 64 | 91 | 18 | 46 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_for_statement | p_for_statement | 1,860 | 1,868 | 1,860 | 1,861 | c7caeeb93fccb7b46352a669c5c25cacaadd774f | bigcode/the-stack | train |
031b4ae5031f4136c778f840 | train | function | def p_string_literal(s, kind_override=None):
# A single string or char literal. Returns (kind, bvalue, uvalue)
# where kind in ('b', 'c', 'u', 'f', ''). The 'bvalue' is the source
# code byte sequence of the string literal, 'uvalue' is the
# decoded Unicode string. Either of the two may be None depen... | def p_string_literal(s, kind_override=None):
# A single string or char literal. Returns (kind, bvalue, uvalue)
# where kind in ('b', 'c', 'u', 'f', ''). The 'bvalue' is the source
# code byte sequence of the string literal, 'uvalue' is the
# decoded Unicode string. Either of the two may be None depen... | pos = s.position()
is_python3_source = s.context.language_level >= 3
has_non_ascii_literal_characters = False
kind_string = s.systring.rstrip('"\'').lower()
if len(kind_string) > 1:
if len(set(kind_string)) != len(kind_string):
error(pos, 'Duplicate string prefix character')
... | kind, bytes_value, unicode_value = p_string_literal(s, required_type)
if required_type == 'u':
if kind == 'f':
s.error("f-string not allowed here", pos)
return unicode_value
elif required_type == 'b':
return bytes_value
else:
s.error("internal parser configuratio... | 256 | 256 | 1,047 | 151 | 104 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_string_literal | p_string_literal | 870 | 968 | 870 | 879 | 1d5a4f220ea4c265c40491857df09af2a35965cc | bigcode/the-stack | train |
4f77f01202ca5faa2196f57e | train | function | def p_if_statement(s):
# s.sy == 'if'
pos = s.position()
s.next()
if_clauses = [p_if_clause(s)]
while s.sy == 'elif':
s.next()
if_clauses.append(p_if_clause(s))
else_clause = p_else_clause(s)
return Nodes.IfStatNode(pos,
if_clauses = if_clauses, else_clause = else_cla... | def p_if_statement(s):
# s.sy == 'if'
| pos = s.position()
s.next()
if_clauses = [p_if_clause(s)]
while s.sy == 'elif':
s.next()
if_clauses.append(p_if_clause(s))
else_clause = p_else_clause(s)
return Nodes.IfStatNode(pos,
if_clauses = if_clauses, else_clause = else_clause)
| p_test(s)
else:
value = None
return Nodes.AssertStatNode(pos, cond = cond, value = value)
statement_terminators = cython.declare(set, set([';', 'NEWLINE', 'EOF']))
def p_if_statement(s):
# s.sy == 'if'
| 63 | 64 | 93 | 14 | 49 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_if_statement | p_if_statement | 1,822 | 1,832 | 1,822 | 1,823 | 934da790252aa85058c953028840054e1ce3b843 | bigcode/the-stack | train |
45e0fb66a3ace0608d473cce | train | function | def p_api(s):
if s.sy == 'IDENT' and s.systring == 'api':
s.next()
return 1
else:
return 0
| def p_api(s):
| if s.sy == 'IDENT' and s.systring == 'api':
s.next()
return 1
else:
return 0
| = p_test(s)
return Nodes.CArgDeclNode(pos,
base_type = base_type,
declarator = declarator,
not_none = not_none,
or_none = or_none,
default = default,
annotation = annotation,
kw_only = kw_only)
def p_api(s):
| 64 | 64 | 38 | 5 | 59 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_api | p_api | 3,045 | 3,050 | 3,045 | 3,045 | 07c46102c17969de4e2be5cb53c3a50484cba926 | bigcode/the-stack | train |
27e56a5697692e41139b89c1 | train | function | def p_dict_or_set_maker(s):
# s.sy == '{'
pos = s.position()
s.next()
if s.sy == '}':
s.next()
return ExprNodes.DictNode(pos, key_value_pairs=[])
parts = []
target_type = 0
last_was_simple_item = False
while True:
if s.sy in ('*', '**'):
# merged set/... | def p_dict_or_set_maker(s):
# s.sy == '{'
| pos = s.position()
s.next()
if s.sy == '}':
s.next()
return ExprNodes.DictNode(pos, key_value_pairs=[])
parts = []
target_type = 0
last_was_simple_item = False
while True:
if s.sy in ('*', '**'):
# merged set/dict literal
if target_type == 0:
... | [async] for ...
is_async = False
if s.sy == 'async':
is_async = True
s.next()
# s.sy == 'for'
s.expect('for')
kw = p_for_bounds(s, allow_testlist=False, is_async=is_async)
kw.update(else_clause=None, body=p_comp_iter(s, body), is_async=is_async)
return Nodes.ForStatNode(pos... | 256 | 256 | 909 | 16 | 240 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_dict_or_set_maker | p_dict_or_set_maker | 1,278 | 1,384 | 1,278 | 1,279 | 16ac0f53d367acef5c3881ed56ecab72bc59b359 | bigcode/the-stack | train |
6bc35225b98797ab3a116546 | train | function | def p_c_func_declarator(s, pos, ctx, base, cmethod_flag):
# Opening paren has already been skipped
args = p_c_arg_list(s, ctx, cmethod_flag = cmethod_flag,
nonempty_declarators = 0)
ellipsis = p_optional_ellipsis(s)
s.expect(')')
nogil = p_nogil(s)
exc_val, exc_check = p... | def p_c_func_declarator(s, pos, ctx, base, cmethod_flag):
# Opening paren has already been skipped
| args = p_c_arg_list(s, ctx, cmethod_flag = cmethod_flag,
nonempty_declarators = 0)
ellipsis = p_optional_ellipsis(s)
s.expect(')')
nogil = p_nogil(s)
exc_val, exc_check = p_exception_value_clause(s)
with_gil = p_with_gil(s)
return Nodes.CFuncDeclaratorNode(pos,
... | list(s)
else:
dim = None
s.expect(']')
return Nodes.CArrayDeclaratorNode(pos, base = base, dimension = dim)
def p_c_func_declarator(s, pos, ctx, base, cmethod_flag):
# Opening paren has already been skipped
| 64 | 64 | 171 | 30 | 34 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_c_func_declarator | p_c_func_declarator | 2,820 | 2,832 | 2,820 | 2,821 | dff30500aa51b05b1a631dcc3f429898f95492c1 | bigcode/the-stack | train |
2bff23028e1c95ace52d73df | train | function | def p_c_modifiers(s):
if s.sy == 'IDENT' and s.systring in ('inline',):
modifier = s.systring
s.next()
return [modifier] + p_c_modifiers(s)
return []
| def p_c_modifiers(s):
| if s.sy == 'IDENT' and s.systring in ('inline',):
modifier = s.systring
s.next()
return [modifier] + p_c_modifiers(s)
return []
| readonly'):
visibility = s.systring
if prev_visibility != 'private' and visibility != prev_visibility:
s.error("Conflicting visibility options '%s' and '%s'"
% (prev_visibility, visibility), fatal=False)
s.next()
return visibility
def p_c_modifiers(s):
| 64 | 64 | 50 | 7 | 56 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_c_modifiers | p_c_modifiers | 3,266 | 3,271 | 3,266 | 3,266 | 24ae2f22aee7024d8e559e51c51961d0b9fa7869 | bigcode/the-stack | train |
9a9b128e03403d41c2f0c4b2 | train | function | def p_with_template(s):
pos = s.position()
templates = []
s.next()
s.expect('[')
templates.append(s.systring)
s.next()
while s.systring == ',':
s.next()
templates.append(s.systring)
s.next()
s.expect(']')
if s.sy == ':':
s.next()
s.expect_newli... | def p_with_template(s):
| pos = s.position()
templates = []
s.next()
s.expect('[')
templates.append(s.systring)
s.next()
while s.systring == ',':
s.next()
templates.append(s.systring)
s.next()
s.expect(']')
if s.sy == ':':
s.next()
s.expect_newline("Syntax error in temp... | if s.sy == ',':
s.next()
body = p_with_items(s, is_async=is_async)
else:
body = p_suite(s)
return Nodes.WithStatNode(pos, manager=manager, target=target, body=body, is_async=is_async)
def p_with_template(s):
| 64 | 64 | 154 | 6 | 58 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_with_template | p_with_template | 2,083 | 2,105 | 2,083 | 2,083 | 539925ccc6ecc3bcecd93221372518a121af336f | bigcode/the-stack | train |
f3857fc08c0413adb4d03cff | train | function | def p_cdef_statement(s, ctx):
pos = s.position()
ctx.visibility = p_visibility(s, ctx.visibility)
ctx.api = ctx.api or p_api(s)
if ctx.api:
if ctx.visibility not in ('private', 'public'):
error(pos, "Cannot combine 'api' with '%s'" % ctx.visibility)
if (ctx.visibility == 'extern'... | def p_cdef_statement(s, ctx):
| pos = s.position()
ctx.visibility = p_visibility(s, ctx.visibility)
ctx.api = ctx.api or p_api(s)
if ctx.api:
if ctx.visibility not in ('private', 'public'):
error(pos, "Cannot combine 'api' with '%s'" % ctx.visibility)
if (ctx.visibility == 'extern') and s.sy == 'from':
... | else:
error(pos, "default values cannot be specified in pxd files, use ? or *")
else:
default = p_test(s)
return Nodes.CArgDeclNode(pos,
base_type = base_type,
declarator = declarator,
not_none = not_none,
or_none = or_none,
default = defa... | 133 | 133 | 445 | 9 | 123 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_cdef_statement | p_cdef_statement | 3,052 | 3,091 | 3,052 | 3,052 | 00becf0bfa9ec1ca480e91cf68726bc7e147af7e | bigcode/the-stack | train |
458cb0d6862f30d06334c544 | train | function | def p_as_name(s):
if s.sy == 'IDENT' and s.systring == 'as':
s.next()
return p_ident(s)
else:
return None
| def p_as_name(s):
| if s.sy == 'IDENT' and s.systring == 'as':
s.next()
return p_ident(s)
else:
return None
| _name]
while s.sy == '.':
s.next()
names.append(p_ident(s))
if as_allowed:
as_name = p_as_name(s)
return (pos, target_name, s.context.intern_ustring(u'.'.join(names)), as_name)
def p_as_name(s):
| 64 | 64 | 39 | 6 | 58 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_as_name | p_as_name | 1,799 | 1,804 | 1,799 | 1,799 | 82d99fc37964ae60f985d6e6c951cfac55d7f039 | bigcode/the-stack | train |
3c4a51c46ac0d2ff1ffea0fa | train | function | def p_xor_expr(s):
return p_binop_expr(s, ('^',), p_and_expr)
| def p_xor_expr(s):
| return p_binop_expr(s, ('^',), p_and_expr)
| 'in', 'is', 'not'
]))
#expr: xor_expr ('|' xor_expr)*
def p_bit_expr(s):
return p_binop_expr(s, ('|',), p_xor_expr)
#xor_expr: and_expr ('^' and_expr)*
def p_xor_expr(s):
| 64 | 64 | 23 | 7 | 56 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_xor_expr | p_xor_expr | 265 | 266 | 265 | 265 | 2962d847e761c798b3074e40b48c970d0d7bb427 | bigcode/the-stack | train |
6584aed42c6113340d9c04b3 | train | function | def p_power(s):
if s.systring == 'new' and s.peek()[0] == 'IDENT':
return p_new_expr(s)
await_pos = None
if s.sy == 'await':
await_pos = s.position()
s.next()
n1 = p_atom(s)
while s.sy in ('(', '[', '.'):
n1 = p_trailer(s, n1)
if await_pos:
n1 = ExprNodes.... | def p_power(s):
| if s.systring == 'new' and s.peek()[0] == 'IDENT':
return p_new_expr(s)
await_pos = None
if s.sy == 'await':
await_pos = s.position()
s.next()
n1 = p_atom(s)
while s.sy in ('(', '[', '.'):
n1 = p_trailer(s, n1)
if await_pos:
n1 = ExprNodes.AwaitExprNode(aw... | s.next()
return p_with_items(s, is_async=True)
else:
s.error("expected one of 'def', 'for', 'with' after 'async'")
#power: atom_expr ('**' factor)*
#atom_expr: ['await'] atom trailer*
def p_power(s):
| 64 | 64 | 158 | 5 | 59 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_power | p_power | 410 | 427 | 410 | 410 | 25e9925c91bcb5f4e4654d36e31d49511d0e99c2 | bigcode/the-stack | train |
0cf81938ab150d8fb3727fbf | train | function | def p_rassoc_binop_expr(s, ops, p_subexpr):
n1 = p_subexpr(s)
if s.sy in ops:
pos = s.position()
op = s.sy
s.next()
n2 = p_rassoc_binop_expr(s, ops, p_subexpr)
n1 = ExprNodes.binop_node(pos, op, n1, n2)
return n1
| def p_rassoc_binop_expr(s, ops, p_subexpr):
| n1 = p_subexpr(s)
if s.sy in ops:
pos = s.position()
op = s.sy
s.next()
n2 = p_rassoc_binop_expr(s, ops, p_subexpr)
n1 = ExprNodes.binop_node(pos, op, n1, n2)
return n1
| (s)
else:
return p_or_test(s)
#or_test: and_test ('or' and_test)*
def p_or_test(s):
return p_rassoc_binop_expr(s, ('or',), p_and_test)
def p_rassoc_binop_expr(s, ops, p_subexpr):
| 64 | 64 | 89 | 15 | 49 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_rassoc_binop_expr | p_rassoc_binop_expr | 165 | 173 | 165 | 165 | 4448b59f3928153b8729112706ca85a779a7fe9a | bigcode/the-stack | train |
a334ad3f5744706928e58d20 | train | function | def p_cpp_class_definition(s, pos, ctx):
# s.sy == 'cppclass'
s.next()
module_path = []
class_name = p_ident(s)
cname = p_opt_cname(s)
if cname is None and ctx.namespace is not None:
cname = ctx.namespace + "::" + class_name
if s.sy == '.':
error(pos, "Qualified class name n... | def p_cpp_class_definition(s, pos, ctx):
# s.sy == 'cppclass'
| s.next()
module_path = []
class_name = p_ident(s)
cname = p_opt_cname(s)
if cname is None and ctx.namespace is not None:
cname = ctx.namespace + "::" + class_name
if s.sy == '.':
error(pos, "Qualified class name not allowed C++ class")
if s.sy == '[':
s.next()
... | 1)
if s.sy != 'EOF':
s.error("Syntax error in statement [%s,%s]" % (
repr(s.sy), repr(s.systring)))
return ModuleNode(pos, doc = doc, body = body,
full_module_name = full_module_name,
directive_comments = directive_comments)
def p_template_defini... | 136 | 136 | 454 | 21 | 114 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_cpp_class_definition | p_cpp_class_definition | 3,734 | 3,791 | 3,734 | 3,735 | 8881a0bd7d93c127c09488cf277c7c2f612afdec | bigcode/the-stack | train |
f6a34448582f5a5a65dbe5d6 | train | function | def p_and_test(s):
#return p_binop_expr(s, ('and',), p_not_test)
return p_rassoc_binop_expr(s, ('and',), p_not_test)
| def p_and_test(s):
#return p_binop_expr(s, ('and',), p_not_test)
| return p_rassoc_binop_expr(s, ('and',), p_not_test)
| p_subexpr)
n1 = ExprNodes.binop_node(pos, op, n1, n2)
return n1
#and_test: not_test ('and' not_test)*
def p_and_test(s):
#return p_binop_expr(s, ('and',), p_not_test)
| 64 | 64 | 41 | 23 | 40 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_and_test | p_and_test | 177 | 179 | 177 | 178 | 338b07dc3c6a9120ce758e36ba54c84b70a3f5f4 | bigcode/the-stack | train |
41e8ee1441e97e4fe43b5598 | train | function | def make_slice_nodes(pos, subscripts):
# Convert a list of subscripts as returned
# by p_subscript_list into a list of ExprNodes,
# creating SliceNodes for elements with 2 or
# more components.
result = []
for subscript in subscripts:
if len(subscript) == 1:
result.append(sub... | def make_slice_nodes(pos, subscripts):
# Convert a list of subscripts as returned
# by p_subscript_list into a list of ExprNodes,
# creating SliceNodes for elements with 2 or
# more components.
| result = []
for subscript in subscripts:
if len(subscript) == 1:
result.append(subscript[0])
else:
result.append(make_slice_node(pos, *subscript))
return result
| .expect('.')
s.expect('.')
s.expect('.')
def make_slice_nodes(pos, subscripts):
# Convert a list of subscripts as returned
# by p_subscript_list into a list of ExprNodes,
# creating SliceNodes for elements with 2 or
# more components.
| 64 | 64 | 100 | 51 | 12 | 0101011/cython | Cython/Compiler/Parsing.py | Python | make_slice_nodes | make_slice_nodes | 633 | 644 | 633 | 637 | 7cba0de306037df6332f6bbac15a90ecc4e9e949 | bigcode/the-stack | train |
1b0ba990c415a5a7789b8b94 | train | function | def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
assignable, nonempty):
pos = s.position()
calling_convention = p_calling_convention(s)
if s.sy == '*':
s.next()
if s.systring == 'const':
const_pos = s.position()
s.next()
... | def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
assignable, nonempty):
| pos = s.position()
calling_convention = p_calling_convention(s)
if s.sy == '*':
s.next()
if s.systring == 'const':
const_pos = s.position()
s.next()
const_base = p_c_declarator(s, ctx, empty = empty,
is_type = is_type... | , cmethod_flag = cmethod_flag,
nonempty_declarators = 0)
ellipsis = p_optional_ellipsis(s)
s.expect(')')
nogil = p_nogil(s)
exc_val, exc_check = p_exception_value_clause(s)
with_gil = p_with_gil(s)
return Nodes.CFuncDeclaratorNode(pos,
base = base, args = args, ha... | 234 | 234 | 783 | 27 | 207 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_c_simple_declarator | p_c_simple_declarator | 2,842 | 2,926 | 2,842 | 2,843 | edca5992698d35a030f0bed3362785f5a1fd59e7 | bigcode/the-stack | train |
40ae6520f4e2685e64f65d7f | train | function | def p_IF_statement(s, ctx):
pos = s.position()
saved_eval = s.compile_time_eval
current_eval = saved_eval
denv = s.compile_time_env
result = None
while 1:
s.next() # 'IF' or 'ELIF'
expr = p_compile_time_expr(s)
s.compile_time_eval = current_eval and bool(expr.compile_time... | def p_IF_statement(s, ctx):
| pos = s.position()
saved_eval = s.compile_time_eval
current_eval = saved_eval
denv = s.compile_time_env
result = None
while 1:
s.next() # 'IF' or 'ELIF'
expr = p_compile_time_expr(s)
s.compile_time_eval = current_eval and bool(expr.compile_time_value(denv))
body =... | denv)
#print "p_DEF_statement: %s = %r" % (name, value) ###
denv.declare(name, value)
s.expect_newline("Expected a newline", ignore_semicolon=True)
return Nodes.PassStatNode(pos)
def p_IF_statement(s, ctx):
| 64 | 64 | 197 | 8 | 56 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_IF_statement | p_IF_statement | 2,197 | 2,222 | 2,197 | 2,197 | 2c6143bd7ea2b1283cf41ba31cc65bc3ad659fb4 | bigcode/the-stack | train |
afceeaa01b7069b12b7fa468 | train | function | def p_positional_and_keyword_args(s, end_sy_set, templates = None):
"""
Parses positional and keyword arguments. end_sy_set
should contain any s.sy that terminate the argument list.
Argument expansion (* and **) are not allowed.
Returns: (positional_args, keyword_args)
"""
positional_args =... | def p_positional_and_keyword_args(s, end_sy_set, templates = None):
| """
Parses positional and keyword arguments. end_sy_set
should contain any s.sy that terminate the argument list.
Argument expansion (* and **) are not allowed.
Returns: (positional_args, keyword_args)
"""
positional_args = []
keyword_args = []
pos_idx = 0
while s.sy not in end... | body = p_statement_list(s, ctx)
s.expect_dedent()
else:
if ctx.api:
s.error("'api' not allowed with this statement", fatal=False)
if ctx.level in ('module', 'class', 'function', 'other'):
body = p_simple_statement_list(s, ctx)
else:
body = ... | 135 | 135 | 450 | 17 | 117 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_positional_and_keyword_args | p_positional_and_keyword_args | 2,371 | 2,425 | 2,371 | 2,371 | 626350de76f2da2999e4f85fefda3facfb9d6f73 | bigcode/the-stack | train |
0ce470bf3d3daeee741ab6d4 | train | function | def p_c_arg_decl(s, ctx, in_pyfunc, cmethod_flag = 0, nonempty = 0,
kw_only = 0, annotated = 1):
pos = s.position()
not_none = or_none = 0
default = None
annotation = None
if s.in_python_file:
# empty type declaration
base_type = Nodes.CSimpleBaseTypeNode(pos,
... | def p_c_arg_decl(s, ctx, in_pyfunc, cmethod_flag = 0, nonempty = 0,
kw_only = 0, annotated = 1):
| pos = s.position()
not_none = or_none = 0
default = None
annotation = None
if s.in_python_file:
# empty type declaration
base_type = Nodes.CSimpleBaseTypeNode(pos,
name = None, module_path = [],
is_basic_c_type = 0, signed = 0,
complex = 0, longnes... | ators:
args.append(p_c_arg_decl(s, ctx, in_pyfunc, is_self_arg,
nonempty = nonempty_declarators, kw_only = kw_only,
annotated = annotated))
if s.sy != ',':
break
s.next()
is_self_arg = 0
return args
def p_optional_ellipsis(s):
if s.sy == '.':
... | 139 | 139 | 466 | 38 | 100 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_c_arg_decl | p_c_arg_decl | 2,993 | 3,043 | 2,993 | 2,994 | b120f923c78ed5bd9c6261b0b95369e8f07ef92d | bigcode/the-stack | train |
c6e9f5b0bad048ad3d787d91 | train | function | def is_memoryviewslice_access(s):
# s.sy == '['
# a memoryview slice declaration is distinguishable from a buffer access
# declaration by the first entry in the bracketed list. The buffer will
# not have an unnested colon in the first entry; the memoryview slice will.
saved = [(s.sy, s.systring)]
... | def is_memoryviewslice_access(s):
# s.sy == '['
# a memoryview slice declaration is distinguishable from a buffer access
# declaration by the first entry in the bracketed list. The buffer will
# not have an unnested colon in the first entry; the memoryview slice will.
| saved = [(s.sy, s.systring)]
s.next()
retval = False
if s.systring == ':':
retval = True
elif s.sy == 'INT':
saved.append((s.sy, s.systring))
s.next()
if s.sy == ':':
retval = True
for sv in saved[::-1]:
s.put_back(*sv)
return retval
| def is_memoryviewslice_access(s):
# s.sy == '['
# a memoryview slice declaration is distinguishable from a buffer access
# declaration by the first entry in the bracketed list. The buffer will
# not have an unnested colon in the first entry; the memoryview slice will.
| 67 | 64 | 154 | 67 | 0 | 0101011/cython | Cython/Compiler/Parsing.py | Python | is_memoryviewslice_access | is_memoryviewslice_access | 2,619 | 2,638 | 2,619 | 2,623 | 49466686c1dc92257760123d93e21f90cdb879ac | bigcode/the-stack | train |
d493ae8824bd897704c98181 | train | function | def expect_ellipsis(s):
s.expect('.')
s.expect('.')
s.expect('.')
| def expect_ellipsis(s):
| s.expect('.')
s.expect('.')
s.expect('.')
| start, stop, step]
def p_slice_element(s, follow_set):
# Simple expression which may be missing iff
# it is followed by something in follow_set.
if s.sy not in follow_set:
return p_test(s)
else:
return None
def expect_ellipsis(s):
| 64 | 64 | 21 | 6 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | expect_ellipsis | expect_ellipsis | 628 | 631 | 628 | 628 | e5b674f183948fe2ea8d55fcd2996a5993f267e3 | bigcode/the-stack | train |
87d00bee7a3d5c6560b8c922 | train | function | def p_slice_element(s, follow_set):
# Simple expression which may be missing iff
# it is followed by something in follow_set.
if s.sy not in follow_set:
return p_test(s)
else:
return None
| def p_slice_element(s, follow_set):
# Simple expression which may be missing iff
# it is followed by something in follow_set.
| if s.sy not in follow_set:
return p_test(s)
else:
return None
| return [start, stop]
s.next()
step = p_slice_element(s, (':', ',', ']'))
return [start, stop, step]
def p_slice_element(s, follow_set):
# Simple expression which may be missing iff
# it is followed by something in follow_set.
| 64 | 64 | 52 | 30 | 34 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_slice_element | p_slice_element | 620 | 626 | 620 | 622 | b00a0e38ea84d1619ad8f396708d9365457e6591 | bigcode/the-stack | train |
2d04de147ab1b60e93f02d54 | train | function | def check_for_non_ascii_characters(string):
for c in string:
if c >= u'\x80':
return True
return False
| def check_for_non_ascii_characters(string):
| for c in string:
if c >= u'\x80':
return True
return False
| required_type == 'u':
if kind == 'f':
s.error("f-string not allowed here", pos)
return unicode_value
elif required_type == 'b':
return bytes_value
else:
s.error("internal parser configuration error")
def check_for_non_ascii_characters(string):
| 64 | 64 | 32 | 9 | 55 | 0101011/cython | Cython/Compiler/Parsing.py | Python | check_for_non_ascii_characters | check_for_non_ascii_characters | 863 | 867 | 863 | 863 | bcb43344feb86a388a20c6101bc8dcc21eeaf82d | bigcode/the-stack | train |
6e0542b4252f3693708ae255 | train | function | def p_nogil(s):
if s.sy == 'IDENT' and s.systring == 'nogil':
s.next()
return 1
else:
return 0
| def p_nogil(s):
| if s.sy == 'IDENT' and s.systring == 'nogil':
s.next()
return 1
else:
return 0
| fatal=False)
name = name + ' ' + op
s.next()
result = Nodes.CNameDeclaratorNode(pos,
name = name, cname = cname, default = rhs)
result.calling_convention = calling_convention
return result
def p_nogil(s):
| 64 | 64 | 41 | 7 | 56 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_nogil | p_nogil | 2,928 | 2,933 | 2,928 | 2,928 | 8be479c553de6d3ca2ddd8306ea1a413571ee6ec | bigcode/the-stack | train |
e968b15f1afbc09f71d21d56 | train | function | def p_doc_string(s):
if s.sy == 'BEGIN_STRING':
pos = s.position()
kind, bytes_result, unicode_result = p_cat_string_literal(s)
s.expect_newline("Syntax error in doc string", ignore_semicolon=True)
if kind in ('u', ''):
return unicode_result
warning(pos, "Python 3... | def p_doc_string(s):
| if s.sy == 'BEGIN_STRING':
pos = s.position()
kind, bytes_result, unicode_result = p_cat_string_literal(s)
s.expect_newline("Syntax error in doc string", ignore_semicolon=True)
if kind in ('u', ''):
return unicode_result
warning(pos, "Python 3 requires docstrings ... | """
if s.sy == 'BEGIN_STRING':
pos = s.position()
string_node = p_atom(s)
s.expect_newline("Syntax error in string", ignore_semicolon=True)
return Nodes.ExprStatNode(pos, expr=string_node)
return None
def p_doc_string(s):
| 64 | 64 | 95 | 6 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_doc_string | p_doc_string | 3,600 | 3,610 | 3,600 | 3,600 | ee3871da6d227ca80ac78acdeee1f07cf3fa1ffc | bigcode/the-stack | train |
8a725dbf310076c4c9607218 | train | function | def p_comp_iter(s, body):
if s.sy in ('for', 'async'):
return p_comp_for(s, body)
elif s.sy == 'if':
return p_comp_if(s, body)
else:
# insert the 'append' operation into the loop
return body
| def p_comp_iter(s, body):
| if s.sy in ('for', 'async'):
return p_comp_for(s, body)
elif s.sy == 'if':
return p_comp_if(s, body)
else:
# insert the 'append' operation into the loop
return body
| literal
if s.sy == ',':
s.next()
exprs = p_test_or_starred_expr_list(s, expr)
else:
exprs = [expr]
s.expect(']')
return ExprNodes.ListNode(pos, args=exprs)
def p_comp_iter(s, body):
| 64 | 64 | 64 | 8 | 56 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_comp_iter | p_comp_iter | 1,238 | 1,245 | 1,238 | 1,238 | 08919210d881698d09ce2bd85dbcec1632014b8f | bigcode/the-stack | train |
53f11cd3f3308d507a3fd3e2 | train | function | def looking_at_dotted_name(s):
if s.sy == 'IDENT':
name = s.systring
s.next()
result = s.sy == '.'
s.put_back('IDENT', name)
return result
else:
return 0
| def looking_at_dotted_name(s):
| if s.sy == 'IDENT':
name = s.systring
s.next()
result = s.sy == '.'
s.put_back('IDENT', name)
return result
else:
return 0
| and saved[0]
else:
return True
def looking_at_base_type(s):
#print "looking_at_base_type?", s.sy, s.systring, s.position()
return s.sy == 'IDENT' and s.systring in base_type_start_words
def looking_at_dotted_name(s):
| 64 | 64 | 56 | 8 | 55 | 0101011/cython | Cython/Compiler/Parsing.py | Python | looking_at_dotted_name | looking_at_dotted_name | 2,703 | 2,711 | 2,703 | 2,703 | 536538a7ec637e52560aacb13eca1901a05b02ac | bigcode/the-stack | train |
c4a8b1cebbc9d53104fffd26 | train | function | def p_atom(s):
pos = s.position()
sy = s.sy
if sy == '(':
s.next()
if s.sy == ')':
result = ExprNodes.TupleNode(pos, args = [])
elif s.sy == 'yield':
result = p_yield_expression(s)
else:
result = p_testlist_comp(s)
s.expect(')')
... | def p_atom(s):
| pos = s.position()
sy = s.sy
if sy == '(':
s.next()
if s.sy == ')':
result = ExprNodes.TupleNode(pos, args = [])
elif s.sy == 'yield':
result = p_yield_expression(s)
else:
result = p_testlist_comp(s)
s.expect(')')
return res... | else:
result.append(make_slice_node(pos, *subscript))
return result
def make_slice_node(pos, start, stop = None, step = None):
if not start:
start = ExprNodes.NoneNode(pos)
if not stop:
stop = ExprNodes.NoneNode(pos)
if not step:
step = ExprNodes.NoneNode(pos... | 151 | 151 | 504 | 5 | 146 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_atom | p_atom | 658 | 719 | 658 | 658 | 4ec87f1f69b832b3734bba57501285fcd3e29f9a | bigcode/the-stack | train |
2981c6454e8e439999e8c277 | train | function | def p_sign_and_longness(s):
signed = 1
longness = 0
while s.sy == 'IDENT' and s.systring in sign_and_longness_words:
if s.systring == 'unsigned':
signed = 0
elif s.systring == 'signed':
signed = 2
elif s.systring == 'short':
longness = -1
e... | def p_sign_and_longness(s):
| signed = 1
longness = 0
while s.sy == 'IDENT' and s.systring in sign_and_longness_words:
if s.systring == 'unsigned':
signed = 0
elif s.systring == 'signed':
signed = 2
elif s.systring == 'short':
longness = -1
elif s.systring == 'long':
... | thon.declare(
set,
basic_c_type_names
| sign_and_longness_words
| set(special_basic_c_types))
struct_enum_union = cython.declare(
set, set(["struct", "union", "enum", "packed"]))
def p_sign_and_longness(s):
| 63 | 64 | 113 | 8 | 55 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_sign_and_longness | p_sign_and_longness | 2,751 | 2,764 | 2,751 | 2,751 | 8ecd91d712719c7b5f4304d399bfdf91c3489c72 | bigcode/the-stack | train |
f6772564bc4528f67ecf8732 | train | function | def p_exec_statement(s):
# s.sy == 'exec'
pos = s.position()
s.next()
code = p_bit_expr(s)
if isinstance(code, ExprNodes.TupleNode):
# Py3 compatibility syntax
tuple_variant = True
args = code.args
if len(args) not in (2, 3):
s.error("expected tuple of len... | def p_exec_statement(s):
# s.sy == 'exec'
| pos = s.position()
s.next()
code = p_bit_expr(s)
if isinstance(code, ExprNodes.TupleNode):
# Py3 compatibility syntax
tuple_variant = True
args = code.args
if len(args) not in (2, 3):
s.error("expected tuple of length 2 or 3, got length %d" % len(args),
... | args.append(p_test(s))
arg_tuple = ExprNodes.TupleNode(pos, args=args)
return Nodes.PrintStatNode(pos,
arg_tuple=arg_tuple, stream=stream,
append_newline=not ends_with_comma)
def p_exec_statement(s):
# s.sy == 'exec'
| 64 | 64 | 200 | 14 | 50 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_exec_statement | p_exec_statement | 1,567 | 1,592 | 1,567 | 1,568 | b4700c5d8e11d7d2f3eb1cb8a797fafea8cd87fb | bigcode/the-stack | train |
7b4281e3d952205ae9a90955 | train | function | def p_opt_string_literal(s, required_type='u'):
if s.sy != 'BEGIN_STRING':
return None
pos = s.position()
kind, bytes_value, unicode_value = p_string_literal(s, required_type)
if required_type == 'u':
if kind == 'f':
s.error("f-string not allowed here", pos)
return un... | def p_opt_string_literal(s, required_type='u'):
| if s.sy != 'BEGIN_STRING':
return None
pos = s.position()
kind, bytes_value, unicode_value = p_string_literal(s, required_type)
if required_type == 'u':
if kind == 'f':
s.error("f-string not allowed here", pos)
return unicode_value
elif required_type == 'b':
... | , list):
unicode_value += u
else:
# non-f-string concatenated into the f-string
unicode_value.append(ExprNodes.UnicodeNode(pos, value=EncodedString(u)))
return kind, bytes_value, unicode_value
def p_opt_string_literal(s, required_type='u'):
| 64 | 64 | 105 | 12 | 51 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_opt_string_literal | p_opt_string_literal | 848 | 860 | 848 | 848 | 347b596f097b0da7f502078695567fc73d5d646b | bigcode/the-stack | train |
5aa8e3ba9f290a7d931cf825 | train | function | def p_trailer(s, node1):
pos = s.position()
if s.sy == '(':
return p_call(s, node1)
elif s.sy == '[':
return p_index(s, node1)
else: # s.sy == '.'
s.next()
name = p_ident(s)
return ExprNodes.AttributeNode(pos,
obj=node1, attribute=name)
| def p_trailer(s, node1):
| pos = s.position()
if s.sy == '(':
return p_call(s, node1)
elif s.sy == '[':
return p_index(s, node1)
else: # s.sy == '.'
s.next()
name = p_ident(s)
return ExprNodes.AttributeNode(pos,
obj=node1, attribute=name)
| ()
s.next()
cppclass = p_c_base_type(s)
return p_call(s, ExprNodes.NewExprNode(pos, cppclass = cppclass))
#trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
def p_trailer(s, node1):
| 64 | 64 | 83 | 9 | 54 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_trailer | p_trailer | 439 | 449 | 439 | 439 | 5d6bb59e3a07da8555d8eef83133f5f95fec0779 | bigcode/the-stack | train |
9ab3f60db27912427c9d618f | train | function | def p_exception_value_clause(s):
exc_val = None
exc_check = 0
if s.sy == 'except':
s.next()
if s.sy == '*':
exc_check = 1
s.next()
elif s.sy == '+':
exc_check = '+'
s.next()
if s.sy == 'IDENT':
name = s.systr... | def p_exception_value_clause(s):
| exc_val = None
exc_check = 0
if s.sy == 'except':
s.next()
if s.sy == '*':
exc_check = 1
s.next()
elif s.sy == '+':
exc_check = '+'
s.next()
if s.sy == 'IDENT':
name = s.systring
s.next()
... | ':
s.next()
return 1
else:
return 0
def p_with_gil(s):
if s.sy == 'with':
s.next()
s.expect_keyword('gil')
return 1
else:
return 0
def p_exception_value_clause(s):
| 64 | 64 | 159 | 7 | 56 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_exception_value_clause | p_exception_value_clause | 2,943 | 2,966 | 2,943 | 2,943 | 53986417844c3bc5854171d6b4e5a6822621205d | bigcode/the-stack | train |
fd97d32c0af8bebc98f42065 | train | function | def p_try_statement(s):
# s.sy == 'try'
pos = s.position()
s.next()
body = p_suite(s)
except_clauses = []
else_clause = None
if s.sy in ('except', 'else'):
while s.sy == 'except':
except_clauses.append(p_except_clause(s))
if s.sy == 'else':
s.next()
... | def p_try_statement(s):
# s.sy == 'try'
| pos = s.position()
s.next()
body = p_suite(s)
except_clauses = []
else_clause = None
if s.sy in ('except', 'else'):
while s.sy == 'except':
except_clauses.append(p_except_clause(s))
if s.sy == 'else':
s.next()
else_clause = p_suite(s)
b... | .position()
if allow_testlist:
expr = p_testlist(s)
else:
expr = p_or_test(s)
return (ExprNodes.AsyncIteratorNode if is_async else ExprNodes.IteratorNode)(pos, sequence=expr)
def p_try_statement(s):
# s.sy == 'try'
| 64 | 64 | 212 | 14 | 50 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_try_statement | p_try_statement | 1,961 | 1,986 | 1,961 | 1,962 | aa11ef20f512f31d113fc248658feb11488637bf | bigcode/the-stack | train |
c19cafc150ede7a24139abac | train | function | def p_c_array_declarator(s, base):
pos = s.position()
s.next() # '['
if s.sy != ']':
dim = p_testlist(s)
else:
dim = None
s.expect(']')
return Nodes.CArrayDeclaratorNode(pos, base = base, dimension = dim)
| def p_c_array_declarator(s, base):
| pos = s.position()
s.next() # '['
if s.sy != ']':
dim = p_testlist(s)
else:
dim = None
s.expect(']')
return Nodes.CArrayDeclaratorNode(pos, base = base, dimension = dim)
| _array_declarator(s, result)
else: # sy == '('
s.next()
result = p_c_func_declarator(s, pos, ctx, result, cmethod_flag)
cmethod_flag = 0
return result
def p_c_array_declarator(s, base):
| 64 | 64 | 70 | 11 | 52 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_c_array_declarator | p_c_array_declarator | 2,810 | 2,818 | 2,810 | 2,810 | d0086409e9fc65282dfec1d85a91444894cdece2 | bigcode/the-stack | train |
ad37f398b6bad87a0fc5184b | train | function | def p_cpp_class_attribute(s, ctx):
decorators = None
if s.sy == '@':
decorators = p_decorators(s)
if s.systring == 'cppclass':
return p_cpp_class_definition(s, s.position(), ctx)
elif s.systring == 'ctypedef':
return p_ctypedef_statement(s, ctx)
elif s.sy == 'IDENT' and s.sys... | def p_cpp_class_attribute(s, ctx):
| decorators = None
if s.sy == '@':
decorators = p_decorators(s)
if s.systring == 'cppclass':
return p_cpp_class_definition(s, s.position(), ctx)
elif s.systring == 'ctypedef':
return p_ctypedef_statement(s, ctx)
elif s.sy == 'IDENT' and s.systring in struct_enum_union:
... | C++ class definition")
return Nodes.CppClassNode(pos,
name = class_name,
cname = cname,
base_classes = base_classes,
visibility = ctx.visibility,
in_pxd = ctx.level == 'module_pxd',
attributes = attributes,
templates = templates)
def p_cpp_class_attribute(s, ... | 70 | 70 | 236 | 9 | 61 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_cpp_class_attribute | p_cpp_class_attribute | 3,793 | 3,815 | 3,793 | 3,793 | c858148b17152986d0ca3472ee61e6f2d23cbe06 | bigcode/the-stack | train |
8d3ffef4172552b9abba0e58 | train | function | def looking_at_base_type(s):
#print "looking_at_base_type?", s.sy, s.systring, s.position()
return s.sy == 'IDENT' and s.systring in base_type_start_words
| def looking_at_base_type(s):
#print "looking_at_base_type?", s.sy, s.systring, s.position()
| return s.sy == 'IDENT' and s.systring in base_type_start_words
| ('IDENT', p)
s.put_back('.', '.')
s.put_back('IDENT', name)
return not is_type and saved[0]
else:
return True
def looking_at_base_type(s):
#print "looking_at_base_type?", s.sy, s.systring, s.position()
| 64 | 64 | 44 | 26 | 37 | 0101011/cython | Cython/Compiler/Parsing.py | Python | looking_at_base_type | looking_at_base_type | 2,699 | 2,701 | 2,699 | 2,700 | a1e3437299298f1e5d1e82241fa424549722742c | bigcode/the-stack | train |
56be659d43cfa9efd8a568ed | train | function | def p_factor(s):
# little indirection for C-ification purposes
return _p_factor(s)
| def p_factor(s):
# little indirection for C-ification purposes
| return _p_factor(s)
| _term(s):
return p_binop_expr(s, ('*', '@', '/', '%', '//'), p_factor)
#factor: ('+'|'-'|'~'|'&'|typecast|sizeof) factor | power
def p_factor(s):
# little indirection for C-ification purposes
| 64 | 64 | 23 | 16 | 47 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_factor | p_factor | 290 | 292 | 290 | 291 | ec7b6b54482fc1f9f816955d8aeccec74b10deff | bigcode/the-stack | train |
dc943581c1bb932fe8a2faf3 | train | function | def p_and_expr(s):
return p_binop_expr(s, ('&',), p_shift_expr)
| def p_and_expr(s):
| return p_binop_expr(s, ('&',), p_shift_expr)
| ('|',), p_xor_expr)
#xor_expr: and_expr ('^' and_expr)*
def p_xor_expr(s):
return p_binop_expr(s, ('^',), p_and_expr)
#and_expr: shift_expr ('&' shift_expr)*
def p_and_expr(s):
| 64 | 64 | 22 | 6 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_and_expr | p_and_expr | 270 | 271 | 270 | 270 | 798af12423e94e0d1281fb5896b2e5aa6593e06a | bigcode/the-stack | train |
17140bdd102fd6b5409069d9 | train | function | def p_for_bounds(s, allow_testlist=True, is_async=False):
target = p_for_target(s)
if s.sy == 'in':
s.next()
iterator = p_for_iterator(s, allow_testlist, is_async=is_async)
return dict(target=target, iterator=iterator)
elif not s.in_python_file and not is_async:
if s.sy == 'f... | def p_for_bounds(s, allow_testlist=True, is_async=False):
| target = p_for_target(s)
if s.sy == 'in':
s.next()
iterator = p_for_iterator(s, allow_testlist, is_async=is_async)
return dict(target=target, iterator=iterator)
elif not s.in_python_file and not is_async:
if s.sy == 'from':
s.next()
bound1 = p_bit_expr... | _statement(s, is_async=False):
# s.sy == 'for'
pos = s.position()
s.next()
kw = p_for_bounds(s, allow_testlist=True, is_async=is_async)
body = p_suite(s)
else_clause = p_else_clause(s)
kw.update(body=body, else_clause=else_clause, is_async=is_async)
return Nodes.ForStatNode(pos, **kw)
de... | 103 | 103 | 346 | 15 | 88 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_for_bounds | p_for_bounds | 1,871 | 1,912 | 1,871 | 1,871 | 7d0481033fc7b319ba65d11d77276b4a85d3885a | bigcode/the-stack | train |
0b9f87dc263636726c8550fc | train | function | def p_property_decl(s):
pos = s.position()
s.next() # 'property'
name = p_ident(s)
doc, body = p_suite_with_docstring(
s, Ctx(level='property'), with_doc_only=True)
return Nodes.PropertyNode(pos, name=name, doc=doc, body=body)
| def p_property_decl(s):
| pos = s.position()
s.next() # 'property'
name = p_ident(s)
doc, body = p_suite_with_docstring(
s, Ctx(level='property'), with_doc_only=True)
return Nodes.PropertyNode(pos, name=name, doc=doc, body=body)
| , warn or error, found %r" % check_size)
if s.sy != ',':
break
s.next()
s.expect(']', "Expected 'object', 'type' or 'check_size'")
return objstruct_name, typeobj_name, check_size
def p_property_decl(s):
| 64 | 64 | 71 | 6 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_property_decl | p_property_decl | 3,579 | 3,585 | 3,579 | 3,579 | 75f8b64a591518ea394000c0c6eeb429981f2884 | bigcode/the-stack | train |
282f7931b7b6e4e22c4cf653 | train | function | def p_except_clause(s):
# s.sy == 'except'
pos = s.position()
s.next()
exc_type = None
exc_value = None
is_except_as = False
if s.sy != ':':
exc_type = p_test(s)
# normalise into list of single exception tests
if isinstance(exc_type, ExprNodes.TupleNode):
... | def p_except_clause(s):
# s.sy == 'except'
| pos = s.position()
s.next()
exc_type = None
exc_value = None
is_except_as = False
if s.sy != ':':
exc_type = p_test(s)
# normalise into list of single exception tests
if isinstance(exc_type, ExprNodes.TupleNode):
exc_type = exc_type.args
else:
... | try-finally
if s.sy == 'finally':
s.next()
finally_clause = p_suite(s)
return Nodes.TryFinallyStatNode(pos,
body = body, finally_clause = finally_clause)
else:
s.error("Expected 'except' or 'finally'")
def p_except_clause(s):
# s.sy == 'except'
| 73 | 74 | 248 | 14 | 60 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_except_clause | p_except_clause | 1,988 | 2,016 | 1,988 | 1,989 | 47bb976f34d3faf4a7bcf8f9d61fff267dd87803 | bigcode/the-stack | train |
bcac4ef849e9750fde1f06aa | train | function | def p_comparison(s):
n1 = p_starred_expr(s)
if s.sy in comparison_ops:
pos = s.position()
op = p_cmp_op(s)
n2 = p_starred_expr(s)
n1 = ExprNodes.PrimaryCmpNode(pos,
operator = op, operand1 = n1, operand2 = n2)
if s.sy in comparison_ops:
n1.cascade ... | def p_comparison(s):
| n1 = p_starred_expr(s)
if s.sy in comparison_ops:
pos = s.position()
op = p_cmp_op(s)
n2 = p_starred_expr(s)
n1 = ExprNodes.PrimaryCmpNode(pos,
operator = op, operand1 = n1, operand2 = n2)
if s.sy in comparison_ops:
n1.cascade = p_cascaded_cmp(s)
... | else:
return p_comparison(s)
#comparison: expr (comp_op expr)*
#comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
def p_comparison(s):
| 64 | 64 | 102 | 6 | 58 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_comparison | p_comparison | 194 | 204 | 194 | 194 | bf608d5b88ff8843458d33246e25235d86b92d81 | bigcode/the-stack | train |
34be3b33227e016fa9afa0d9 | train | function | def p_simple_statement(s, first_statement = 0):
#print "p_simple_statement:", s.sy, s.systring ###
if s.sy == 'global':
node = p_global_statement(s)
elif s.sy == 'nonlocal':
node = p_nonlocal_statement(s)
elif s.sy == 'print':
node = p_print_statement(s)
elif s.sy == 'exec':
... | def p_simple_statement(s, first_statement = 0):
#print "p_simple_statement:", s.sy, s.systring ###
| if s.sy == 'global':
node = p_global_statement(s)
elif s.sy == 'nonlocal':
node = p_nonlocal_statement(s)
elif s.sy == 'print':
node = p_print_statement(s)
elif s.sy == 'exec':
node = p_exec_statement(s)
elif s.sy == 'del':
node = p_del_statement(s)
elif s... | = Ctx()
body_ctx.templates = templates
func_or_var = p_c_func_or_var_declaration(s, pos, body_ctx)
s.expect_dedent()
return func_or_var
else:
error(pos, "Syntax error in template function declaration")
def p_simple_statement(s, first_statement = 0):
#print "p_simple_stat... | 84 | 84 | 281 | 27 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_simple_statement | p_simple_statement | 2,107 | 2,139 | 2,107 | 2,108 | 54ba33c2e973de43c4e432731503c6855008d353 | bigcode/the-stack | train |
52e0ce5060e2a13770dd570a | train | function | def p_varargslist(s, terminator=')', annotated=1):
args = p_c_arg_list(s, in_pyfunc = 1, nonempty_declarators = 1,
annotated = annotated)
star_arg = None
starstar_arg = None
if s.sy == '*':
s.next()
if s.sy == 'IDENT':
star_arg = p_py_arg_decl(s, annot... | def p_varargslist(s, terminator=')', annotated=1):
| args = p_c_arg_list(s, in_pyfunc = 1, nonempty_declarators = 1,
annotated = annotated)
star_arg = None
starstar_arg = None
if s.sy == '*':
s.next()
if s.sy == 'IDENT':
star_arg = p_py_arg_decl(s, annotated=annotated)
if s.sy == ',':
... | , args=args, star_arg=star_arg, starstar_arg=starstar_arg,
doc=doc, body=body, decorators=decorators, is_async_def=is_async_def,
return_type_annotation=return_type_annotation)
def p_varargslist(s, terminator=')', annotated=1):
| 64 | 64 | 210 | 16 | 48 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_varargslist | p_varargslist | 3,422 | 3,442 | 3,422 | 3,422 | 30f612d334af42a80472ff9ebec4fd86fc54b9a1 | bigcode/the-stack | train |
864eba7caff815e22162df84 | train | function | def p_testlist_comp(s):
pos = s.position()
expr = p_test_or_starred_expr(s)
if s.sy == ',':
s.next()
exprs = p_test_or_starred_expr_list(s, expr)
return ExprNodes.TupleNode(pos, args = exprs)
elif s.sy in ('for', 'async'):
return p_genexp(s, expr)
else:
return... | def p_testlist_comp(s):
| pos = s.position()
expr = p_test_or_starred_expr(s)
if s.sy == ',':
s.next()
exprs = p_test_or_starred_expr_list(s, expr)
return ExprNodes.TupleNode(pos, args = exprs)
elif s.sy in ('for', 'async'):
return p_genexp(s, expr)
else:
return expr
| _test_or_starred_expr_list(s, expr)
return ExprNodes.TupleNode(pos, args = exprs)
else:
return expr
# testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
def p_testlist_comp(s):
| 64 | 64 | 90 | 7 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_testlist_comp | p_testlist_comp | 1,449 | 1,459 | 1,449 | 1,449 | a365e5b0c4256ade979781e8cf8907a0fdd27495 | bigcode/the-stack | train |
a88fd8edb88cc98ea2444fd5 | train | function | def p_expression_or_assignment(s):
expr = p_testlist_star_expr(s)
if s.sy == ':' and (expr.is_name or expr.is_subscript or expr.is_attribute):
s.next()
expr.annotation = p_test(s)
if s.sy == '=' and expr.is_starred:
# This is a common enough error to make when learning Cython to let
... | def p_expression_or_assignment(s):
| expr = p_testlist_star_expr(s)
if s.sy == ':' and (expr.is_name or expr.is_subscript or expr.is_attribute):
s.next()
expr.annotation = p_test(s)
if s.sy == '=' and expr.is_starred:
# This is a common enough error to make when learning Cython to let
# it fail as early as possi... | Nodes.GeneratorExpressionNode(expr.pos, loop=loop)
expr_terminators = cython.declare(set, set([
')', ']', '}', ':', '=', 'NEWLINE']))
#-------------------------------------------------------
#
# Statements
#
#-------------------------------------------------------
def p_global_statement(s):
# assume s.sy ... | 140 | 140 | 469 | 7 | 133 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_expression_or_assignment | p_expression_or_assignment | 1,492 | 1,536 | 1,492 | 1,492 | 1289320888e7d544c51692a757c49a4f6c13b498 | bigcode/the-stack | train |
a45114a388c64f0d7317d7f0 | train | function | def p_module(s, pxd, full_module_name, ctx=Ctx):
pos = s.position()
directive_comments = p_compiler_directive_comments(s)
s.parse_comments = False
if s.context.language_level is None:
s.context.set_language_level('3str')
if pos[0].filename:
import warnings
warni... | def p_module(s, pxd, full_module_name, ctx=Ctx):
| pos = s.position()
directive_comments = p_compiler_directive_comments(s)
s.parse_comments = False
if s.context.language_level is None:
s.context.set_language_level('3str')
if pos[0].filename:
import warnings
warnings.warn(
"Cython directive 'lang... | )
if 'language_level' in new_directives:
# Make sure we apply the language level already to the first token that follows the comments.
s.context.set_language_level(new_directives['language_level'])
result.update(new_directives)
s.next()
return resul... | 75 | 75 | 253 | 16 | 58 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_module | p_module | 3,693 | 3,722 | 3,693 | 3,693 | 05131d80e487749ed6f25cc38e22dd3f567032f9 | bigcode/the-stack | train |
cc488424a265e84c204ed0f5 | train | function | def p_testlist_star_expr(s):
pos = s.position()
expr = p_test_or_starred_expr(s)
if s.sy == ',':
s.next()
exprs = p_test_or_starred_expr_list(s, expr)
return ExprNodes.TupleNode(pos, args = exprs)
else:
return expr
| def p_testlist_star_expr(s):
| pos = s.position()
expr = p_test_or_starred_expr(s)
if s.sy == ',':
s.next()
exprs = p_test_or_starred_expr_list(s, expr)
return ExprNodes.TupleNode(pos, args = exprs)
else:
return expr
| p_simple_expr_list(s, expr)
return ExprNodes.TupleNode(pos, args = exprs)
else:
return expr
# testlist_star_expr: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
def p_testlist_star_expr(s):
| 64 | 64 | 71 | 8 | 56 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_testlist_star_expr | p_testlist_star_expr | 1,437 | 1,445 | 1,437 | 1,437 | e18a2bbdd2995ffc33e4eb7f656b0bd67dca1089 | bigcode/the-stack | train |
f7db4606b62c2506a9542cb6 | train | function | def p_include_statement(s, ctx):
pos = s.position()
s.next() # 'include'
unicode_include_file_name = p_string_literal(s, 'u')[2]
s.expect_newline("Syntax error in include statement")
if s.compile_time_eval:
include_file_name = unicode_include_file_name
include_file_path = s.context.f... | def p_include_statement(s, ctx):
| pos = s.position()
s.next() # 'include'
unicode_include_file_name = p_string_literal(s, 'u')[2]
s.expect_newline("Syntax error in include statement")
if s.compile_time_eval:
include_file_name = unicode_include_file_name
include_file_path = s.context.find_include_file(include_file_nam... | Nodes.NameNode(pos2, name = name)
is_except_as = True
body = p_suite(s)
return Nodes.ExceptClauseNode(pos,
pattern = exc_type, target = exc_value,
body = body, is_except_as=is_except_as)
def p_include_statement(s, ctx):
| 64 | 64 | 181 | 8 | 56 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_include_statement | p_include_statement | 2,018 | 2,036 | 2,018 | 2,018 | ef3e606bc8df562e192e9260f83192ecc8daa78d | bigcode/the-stack | train |
8c0a4673596521e59b620a25 | train | function | def p_subscript_list(s):
is_single_value = True
items = [p_subscript(s)]
while s.sy == ',':
is_single_value = False
s.next()
if s.sy == ']':
break
items.append(p_subscript(s))
return items, is_single_value
| def p_subscript_list(s):
| is_single_value = True
items = [p_subscript(s)]
while s.sy == ',':
is_single_value = False
s.next()
if s.sy == ']':
break
items.append(p_subscript(s))
return items, is_single_value
| )
if is_single_value:
index = indexes[0]
else:
index = ExprNodes.TupleNode(pos, args = indexes)
result = ExprNodes.IndexNode(pos,
base = base, index = index)
s.expect(']')
return result
def p_subscript_list(s):
| 64 | 64 | 67 | 7 | 56 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_subscript_list | p_subscript_list | 591 | 600 | 591 | 591 | 5616670e0cc90b270f0eb871e7fc06557acfde76 | bigcode/the-stack | train |
1f69bcd9be6b36f0e5c261a8 | train | function | def p_buffer_or_template(s, base_type_node, templates):
# s.sy == '['
pos = s.position()
s.next()
# Note that buffer_positional_options_count=1, so the only positional argument is dtype.
# For templated types, all parameters are types.
positional_args, keyword_args = (
p_positional_and_k... | def p_buffer_or_template(s, base_type_node, templates):
# s.sy == '['
| pos = s.position()
s.next()
# Note that buffer_positional_options_count=1, so the only positional argument is dtype.
# For templated types, all parameters are types.
positional_args, keyword_args = (
p_positional_and_keyword_args(s, (']',), templates)
)
s.expect(']')
if s.sy == ... | if s.sy == '.':
s.next()
name = p_ident(s)
type_node = Nodes.CNestedBaseTypeNode(pos, base_type = type_node, name = name)
return type_node
def p_buffer_or_template(s, base_type_node, templates):
# s.sy == '['
| 64 | 64 | 200 | 20 | 43 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_buffer_or_template | p_buffer_or_template | 2,573 | 2,596 | 2,573 | 2,574 | e7f1875a9f58da2413e21abfad672257bb48f199 | bigcode/the-stack | train |
1d333faa201aed1bb7658173 | train | function | def p_test_or_starred_expr_list(s, expr=None):
exprs = expr is not None and [expr] or []
while s.sy not in expr_terminators:
exprs.append(p_test_or_starred_expr(s))
if s.sy != ',':
break
s.next()
return exprs
| def p_test_or_starred_expr_list(s, expr=None):
| exprs = expr is not None and [expr] or []
while s.sy not in expr_terminators:
exprs.append(p_test_or_starred_expr(s))
if s.sy != ',':
break
s.next()
return exprs
| = expr is not None and [expr] or []
while s.sy not in expr_terminators:
exprs.append( p_test(s) )
if s.sy != ',':
break
s.next()
return exprs
def p_test_or_starred_expr_list(s, expr=None):
| 64 | 64 | 69 | 13 | 50 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_test_or_starred_expr_list | p_test_or_starred_expr_list | 1,413 | 1,420 | 1,413 | 1,413 | 06966dc0994eb7f16d3c64fbac67ae83aac92010 | bigcode/the-stack | train |
b61da078b4afd83e8fc78fd3 | train | function | def p_name(s, name):
pos = s.position()
if not s.compile_time_expr and name in s.compile_time_env:
value = s.compile_time_env.lookup_here(name)
node = wrap_compile_time_constant(pos, value)
if node is not None:
return node
return ExprNodes.NameNode(pos, name=name)
| def p_name(s, name):
| pos = s.position()
if not s.compile_time_expr and name in s.compile_time_env:
value = s.compile_time_env.lookup_here(name)
node = wrap_compile_time_constant(pos, value)
if node is not None:
return node
return ExprNodes.NameNode(pos, name=name)
| _literal:
error(pos, "illegal integer literal syntax in Python source file")
is_c_literal = False
return ExprNodes.IntNode(pos,
is_c_literal = is_c_literal,
value = value,
unsigned = unsigned,
... | 64 | 64 | 72 | 7 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_name | p_name | 753 | 760 | 753 | 753 | 3d00a356377685b79df7c759e60fa04d4b0444ec | bigcode/the-stack | train |
a77b853174420c0c00fabf40 | train | function | def p_statement(s, ctx, first_statement = 0):
cdef_flag = ctx.cdef_flag
decorators = None
if s.sy == 'ctypedef':
if ctx.level not in ('module', 'module_pxd'):
s.error("ctypedef statement not allowed here")
#if ctx.api:
# error(s.position(), "'api' not allowed with 'cty... | def p_statement(s, ctx, first_statement = 0):
| cdef_flag = ctx.cdef_flag
decorators = None
if s.sy == 'ctypedef':
if ctx.level not in ('module', 'module_pxd'):
s.error("ctypedef statement not allowed here")
#if ctx.api:
# error(s.position(), "'api' not allowed with 'ctypedef'")
return p_ctypedef_statement(s... | : %s = %r" % (name, value) ###
denv.declare(name, value)
s.expect_newline("Expected a newline", ignore_semicolon=True)
return Nodes.PassStatNode(pos)
def p_IF_statement(s, ctx):
pos = s.position()
saved_eval = s.compile_time_eval
current_eval = saved_eval
denv = s.compile_time_env
r... | 256 | 256 | 1,030 | 13 | 242 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_statement | p_statement | 2,224 | 2,323 | 2,224 | 2,224 | 590b4b82005812932873e0dcf3b9e0229dbe0dbc | bigcode/the-stack | train |
123da66d6f0577ba1c57c64e | train | function | def p_term(s):
return p_binop_expr(s, ('*', '@', '/', '%', '//'), p_factor)
| def p_term(s):
| return p_binop_expr(s, ('*', '@', '/', '%', '//'), p_factor)
| ith_expr)
#arith_expr: term (('+'|'-') term)*
def p_arith_expr(s):
return p_binop_expr(s, ('+', '-'), p_term)
#term: factor (('*'|'@'|'/'|'%'|'//') factor)*
def p_term(s):
| 64 | 64 | 26 | 5 | 58 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_term | p_term | 285 | 286 | 285 | 285 | b59b9c2b51a850ef867fcabc3f982a6a9137858b | bigcode/the-stack | train |
084a57fd149e39aabbfd7121 | train | function | def p_f_string_expr(s, unicode_value, pos, starting_index, is_raw):
# Parses a {}-delimited expression inside an f-string. Returns a FormattedValueNode
# and the index in the string that follows the expression.
i = starting_index
size = len(unicode_value)
conversion_char = terminal_char = format_spe... | def p_f_string_expr(s, unicode_value, pos, starting_index, is_raw):
# Parses a {}-delimited expression inside an f-string. Returns a FormattedValueNode
# and the index in the string that follows the expression.
| i = starting_index
size = len(unicode_value)
conversion_char = terminal_char = format_spec = None
format_spec_str = None
NO_CHAR = 2**30
nested_depth = 0
quote_char = NO_CHAR
in_triple_quotes = False
while True:
if i >= size:
s.error("missing '}' in format strin... | == '\\':
if not is_raw and len(part) > 1:
_append_escape_sequence('f', builder, part, s)
else:
builder.append(part)
elif c == '{':
if part == '{{':
builder.append('{')
else:
# start of an expression
... | 256 | 256 | 1,060 | 52 | 203 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_f_string_expr | p_f_string_expr | 1,086 | 1,198 | 1,086 | 1,088 | 6ba62621687adba060b91a13e3fabbee3836cd72 | bigcode/the-stack | train |
a3a303af4a4c6e302255b287 | train | function | def p_compiler_directive_comments(s):
result = {}
while s.sy == 'commentline':
pos = s.position()
m = _match_compiler_directive_comment(s.systring)
if m:
directives_string = m.group(1).strip()
try:
new_directives = Options.parse_directive_list(dire... | def p_compiler_directive_comments(s):
| result = {}
while s.sy == 'commentline':
pos = s.position()
m = _match_compiler_directive_comment(s.systring)
if m:
directives_string = m.group(1).strip()
try:
new_directives = Options.parse_directive_list(directives_string, ignore_unknown=True)
... | s,%s]" % (
repr(s.sy), repr(s.systring)))
return body
_match_compiler_directive_comment = cython.declare(object, re.compile(
r"^#\s*cython\s*:\s*((\w|[.])+\s*=.*)$").match)
def p_compiler_directive_comments(s):
| 74 | 74 | 248 | 9 | 65 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_compiler_directive_comments | p_compiler_directive_comments | 3,660 | 3,690 | 3,660 | 3,660 | fbeec88bbfdd5e6f668cc96bae97e803d80e1d4e | bigcode/the-stack | train |
3555473f9fbe34796abd4ae1 | train | function | def p_simple_expr_list(s, expr=None):
exprs = expr is not None and [expr] or []
while s.sy not in expr_terminators:
exprs.append( p_test(s) )
if s.sy != ',':
break
s.next()
return exprs
| def p_simple_expr_list(s, expr=None):
| exprs = expr is not None and [expr] or []
while s.sy not in expr_terminators:
exprs.append( p_test(s) )
if s.sy != ',':
break
s.next()
return exprs
| _test(s))
s.expect('`')
if len(args) == 1:
arg = args[0]
else:
arg = ExprNodes.TupleNode(pos, args = args)
return ExprNodes.BackquoteNode(pos, arg = arg)
def p_simple_expr_list(s, expr=None):
| 64 | 64 | 64 | 10 | 54 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_simple_expr_list | p_simple_expr_list | 1,403 | 1,410 | 1,403 | 1,403 | f289e099b82456268afdb212f6b29d1587e2717a | bigcode/the-stack | train |
73a83f1908d20dc643fce7cc | train | function | def p_binop_expr(s, ops, p_sub_expr):
n1 = p_sub_expr(s)
while s.sy in ops:
op, pos = p_binop_operator(s)
n2 = p_sub_expr(s)
n1 = ExprNodes.binop_node(pos, op, n1, n2)
if op == '/':
if Future.division in s.context.future_directives:
n1.truedivision = T... | def p_binop_expr(s, ops, p_sub_expr):
| n1 = p_sub_expr(s)
while s.sy in ops:
op, pos = p_binop_operator(s)
n2 = p_sub_expr(s)
n1 = ExprNodes.binop_node(pos, op, n1, n2)
if op == '/':
if Future.division in s.context.future_directives:
n1.truedivision = True
else:
... | break
s.next()
return names
#------------------------------------------
#
# Expressions
#
#------------------------------------------
def p_binop_operator(s):
pos = s.position()
op = s.sy
s.next()
return op, pos
def p_binop_expr(s, ops, p_sub_expr):
| 64 | 64 | 116 | 13 | 50 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_binop_expr | p_binop_expr | 96 | 107 | 96 | 96 | 87f8d23810fca66e0200ca15231b30c7085d2d4d | bigcode/the-stack | train |
aae430d5c6a10d3e15d1c9b0 | train | function | def p_f_string(s, unicode_value, pos, is_raw):
# Parses a PEP 498 f-string literal into a list of nodes. Nodes are either UnicodeNodes
# or FormattedValueNodes.
values = []
next_start = 0
size = len(unicode_value)
builder = StringEncoding.UnicodeLiteralBuilder()
error_pos = list(pos) # [src... | def p_f_string(s, unicode_value, pos, is_raw):
# Parses a PEP 498 f-string literal into a list of nodes. Nodes are either UnicodeNodes
# or FormattedValueNodes.
| values = []
next_start = 0
size = len(unicode_value)
builder = StringEncoding.UnicodeLiteralBuilder()
error_pos = list(pos) # [src, line, column]
_parse_seq = _parse_escape_sequences_raw if is_raw else _parse_escape_sequences
while next_start < size:
end = next_start
error_... | NxuU]|' # detect invalid escape sequences that do not match above
)) +
br')?|'
# non-escape sequences:
br'\{\{?|'
br'\}\}?|'
br'[^\\{}]+)'
).decode('us-ascii')).match
for is_raw in (True, False)]
def p_f_string(s, unicode_value, pos, is_raw):
# Parses a PEP 498 f-string literal into... | 119 | 120 | 402 | 45 | 74 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_f_string | p_f_string | 1,038 | 1,083 | 1,038 | 1,040 | 04bbd5364ad0a66de729ef2e7ead9ce3c8c20be3 | bigcode/the-stack | train |
6031e21382aab8df35021048 | train | function | def p_lambdef(s, allow_conditional=True):
# s.sy == 'lambda'
pos = s.position()
s.next()
if s.sy == ':':
args = []
star_arg = starstar_arg = None
else:
args, star_arg, starstar_arg = p_varargslist(
s, terminator=':', annotated=False)
s.expect(':')
if allow... | def p_lambdef(s, allow_conditional=True):
# s.sy == 'lambda'
| pos = s.position()
s.next()
if s.sy == ':':
args = []
star_arg = starstar_arg = None
else:
args, star_arg, starstar_arg = p_varargslist(
s, terminator=':', annotated=False)
s.expect(':')
if allow_conditional:
expr = p_test(s)
else:
expr = p... | 1.truedivision = True
else:
n1.truedivision = None # unknown
return n1
#lambdef: 'lambda' [varargslist] ':' test
def p_lambdef(s, allow_conditional=True):
# s.sy == 'lambda'
| 64 | 64 | 146 | 20 | 43 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_lambdef | p_lambdef | 111 | 129 | 111 | 112 | b2f3b64c0933ee3e5e4ed4f6df99c6d1b2fff0bb | bigcode/the-stack | train |
751c40a872a6816342219b35 | train | function | def p_DEF_statement(s):
pos = s.position()
denv = s.compile_time_env
s.next() # 'DEF'
name = p_ident(s)
s.expect('=')
expr = p_compile_time_expr(s)
if s.compile_time_eval:
value = expr.compile_time_value(denv)
#print "p_DEF_statement: %s = %r" % (name, value) ###
denv... | def p_DEF_statement(s):
| pos = s.position()
denv = s.compile_time_env
s.next() # 'DEF'
name = p_ident(s)
s.expect('=')
expr = p_compile_time_expr(s)
if s.compile_time_eval:
value = expr.compile_time_value(denv)
#print "p_DEF_statement: %s = %r" % (name, value) ###
denv.declare(name, value)
... | _newline("Syntax error in simple statement list")
return stat
def p_compile_time_expr(s):
old = s.compile_time_expr
s.compile_time_expr = 1
expr = p_testlist(s)
s.compile_time_expr = old
return expr
def p_DEF_statement(s):
| 64 | 64 | 121 | 6 | 57 | 0101011/cython | Cython/Compiler/Parsing.py | Python | p_DEF_statement | p_DEF_statement | 2,183 | 2,195 | 2,183 | 2,183 | e0406fec12902737e9d6673fa84f9cf83434ba64 | bigcode/the-stack | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.