Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e3944a5e
Commit
e3944a5e
authored
Apr 01, 2009
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The BDFL has retired! Long live the FLUFL (Friendly Language Uncle For Life)!
parent
4ed72acd
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
168 additions
and
121 deletions
+168
-121
Grammar/Grammar
Grammar/Grammar
+1
-1
Include/code.h
Include/code.h
+3
-1
Include/compile.h
Include/compile.h
+1
-0
Include/parsetok.h
Include/parsetok.h
+1
-0
Include/pythonrun.h
Include/pythonrun.h
+1
-1
Lib/__future__.py
Lib/__future__.py
+5
-0
Lib/test/test_flufl.py
Lib/test/test_flufl.py
+27
-0
Parser/parser.c
Parser/parser.c
+8
-0
Parser/parsetok.c
Parser/parsetok.c
+17
-21
Parser/tokenizer.c
Parser/tokenizer.c
+1
-0
Python/future.c
Python/future.c
+2
-0
Python/graminit.c
Python/graminit.c
+99
-97
Python/pythonrun.c
Python/pythonrun.c
+2
-0
No files found.
Grammar/Grammar
View file @
e3944a5e
...
...
@@ -87,7 +87,7 @@ or_test: and_test ('or' and_test)*
and_test: not_test ('and' not_test)*
not_test: 'not' not_test | comparison
comparison: star_expr (comp_op star_expr)*
comp_op: '<'|'>'|'=='|'>='|'<='|'!='|'in'|'not' 'in'|'is'|'is' 'not'
comp_op: '<'|'>'|'=='|'>='|'<='|'
<>'|'
!='|'in'|'not' 'in'|'is'|'is' 'not'
star_expr: ['*'] expr
expr: xor_expr ('|' xor_expr)*
xor_expr: and_expr ('^' and_expr)*
...
...
Include/code.h
View file @
e3944a5e
...
...
@@ -52,10 +52,12 @@ typedef struct {
#define CO_FUTURE_UNICODE_LITERALS 0x20000
#endif
#define CO_FUTURE_BARRY_AS_BDFL 0x40000
/* This should be defined if a future statement modifies the syntax.
For example, when a keyword is added.
*/
/* #define PY_PARSER_REQUIRES_FUTURE_KEYWORD */
#define PY_PARSER_REQUIRES_FUTURE_KEYWORD
#define CO_MAXBLOCKS 20
/* Max static block nesting within a function */
...
...
Include/compile.h
View file @
e3944a5e
...
...
@@ -26,6 +26,7 @@ typedef struct {
#define FUTURE_WITH_STATEMENT "with_statement"
#define FUTURE_PRINT_FUNCTION "print_function"
#define FUTURE_UNICODE_LITERALS "unicode_literals"
#define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
struct
_mod
;
/* Declare the existence of this type */
PyAPI_FUNC
(
PyCodeObject
*
)
PyAST_Compile
(
struct
_mod
*
,
const
char
*
,
...
...
Include/parsetok.h
View file @
e3944a5e
...
...
@@ -30,6 +30,7 @@ typedef struct {
#endif
#define PyPARSE_IGNORE_COOKIE 0x0010
#define PyPARSE_BARRY_AS_BDFL 0x0020
PyAPI_FUNC
(
node
*
)
PyParser_ParseString
(
const
char
*
,
grammar
*
,
int
,
perrdetail
*
);
...
...
Include/pythonrun.h
View file @
e3944a5e
...
...
@@ -7,7 +7,7 @@
extern
"C"
{
#endif
#define PyCF_MASK
0
#define PyCF_MASK
CO_FUTURE_BARRY_AS_BDFL
#define PyCF_MASK_OBSOLETE 0
#define PyCF_SOURCE_IS_UTF8 0x0100
#define PyCF_DONT_IMPLY_DEDENT 0x0200
...
...
Lib/__future__.py
View file @
e3944a5e
...
...
@@ -70,6 +70,7 @@ CO_FUTURE_ABSOLUTE_IMPORT = 0x4000 # perform absolute imports by default
CO_FUTURE_WITH_STATEMENT
=
0x8000
# with statement
CO_FUTURE_PRINT_FUNCTION
=
0x10000
# print function
CO_FUTURE_UNICODE_LITERALS
=
0x20000
# unicode string literals
CO_FUTURE_BARRY_AS_BDFL
=
0x40000
class
_Feature
:
def
__init__
(
self
,
optionalRelease
,
mandatoryRelease
,
compiler_flag
):
...
...
@@ -126,3 +127,7 @@ print_function = _Feature((2, 6, 0, "alpha", 2),
unicode_literals
=
_Feature
((
2
,
6
,
0
,
"alpha"
,
2
),
(
3
,
0
,
0
,
"alpha"
,
0
),
CO_FUTURE_UNICODE_LITERALS
)
barry_as_FLUFL
=
_Feature
((
3
,
1
,
0
,
"alpha"
,
2
),
(
3
,
9
,
0
,
"alpha"
,
0
),
CO_FUTURE_BARRY_AS_BDFL
)
Lib/test/test_flufl.py
0 → 100644
View file @
e3944a5e
import
__future__
import
unittest
class
FLUFLTests
(
unittest
.
TestCase
):
def
test_barry_as_bdfl
(
self
):
code
=
"from __future__ import barry_as_FLUFL; 2 {0} 3"
compile
(
code
.
format
(
'<>'
),
'<BDFL test>'
,
'exec'
,
__future__
.
CO_FUTURE_BARRY_AS_BDFL
)
self
.
assertRaises
(
SyntaxError
,
compile
,
code
.
format
(
'!='
),
'<FLUFL test>'
,
'exec'
,
__future__
.
CO_FUTURE_BARRY_AS_BDFL
)
def
test_guido_as_bdfl
(
self
):
code
=
'2 {0} 3'
compile
(
code
.
format
(
'!='
),
'<BDFL test>'
,
'exec'
)
self
.
assertRaises
(
SyntaxError
,
compile
,
code
.
format
(
'<>'
),
'<FLUFL test>'
,
'exec'
)
def
test_main
():
from
test.support
import
run_unittest
run_unittest
(
FLUFLTests
)
if
__name__
==
'__main__'
:
test_main
()
Parser/parser.c
View file @
e3944a5e
...
...
@@ -149,6 +149,7 @@ classify(parser_state *ps, int type, char *str)
strcmp
(
l
->
lb_str
,
s
)
!=
0
)
continue
;
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
#if 0
/* Leaving this in as an example */
if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) {
if (s[0] == 'w' && strcmp(s, "with") == 0)
...
...
@@ -156,6 +157,7 @@ classify(parser_state *ps, int type, char *str)
else if (s[0] == 'a' && strcmp(s, "as") == 0)
break; /* not a keyword yet */
}
#endif
#endif
D
(
printf
(
"It's a keyword
\n
"
));
return
n
-
i
;
...
...
@@ -178,6 +180,7 @@ classify(parser_state *ps, int type, char *str)
}
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
#if 0
/* Leaving this in as an example */
static void
future_hack(parser_state *ps)
...
...
@@ -218,6 +221,7 @@ future_hack(parser_state *ps)
}
}
}
#endif
#endif
/* future keyword */
int
...
...
@@ -278,10 +282,12 @@ PyParser_AddToken(register parser_state *ps, register int type, char *str,
d
->
d_name
,
ps
->
p_stack
.
s_top
->
s_state
));
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
#if 0
if (d->d_name[0] == 'i' &&
strcmp(d->d_name,
"import_stmt") == 0)
future_hack(ps);
#endif
#endif
s_pop
(
&
ps
->
p_stack
);
if
(
s_empty
(
&
ps
->
p_stack
))
{
...
...
@@ -296,9 +302,11 @@ PyParser_AddToken(register parser_state *ps, register int type, char *str,
if
(
s
->
s_accept
)
{
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
#if 0
if (d->d_name[0] == 'i' &&
strcmp(d->d_name, "import_stmt") == 0)
future_hack(ps);
#endif
#endif
/* Pop this dfa and try again */
s_pop
(
&
ps
->
p_stack
);
...
...
Parser/parsetok.c
View file @
e3944a5e
...
...
@@ -100,6 +100,7 @@ PyParser_ParseFileFlagsEx(FILE *fp, const char *filename,
}
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
#if 0
static char with_msg[] =
"%s:%d: Warning: 'with' will become a reserved keyword in Python 2.6\n";
...
...
@@ -114,6 +115,7 @@ warn(const char *msg, const char *filename, int lineno)
PySys_WriteStderr(msg, filename, lineno);
}
#endif
#endif
/* Parse input coming from the given tokenizer structure.
Return error code. */
...
...
@@ -133,8 +135,8 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
return
NULL
;
}
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
if
(
*
flags
&
PyPARSE_
WITH_IS_KEYWORD
)
ps
->
p_flags
|=
CO_FUTURE_
WITH_STATEMENT
;
if
(
*
flags
&
PyPARSE_
BARRY_AS_BDFL
)
ps
->
p_flags
|=
CO_FUTURE_
BARRY_AS_BDFL
;
#endif
for
(;;)
{
...
...
@@ -177,26 +179,20 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
str
[
len
]
=
'\0'
;
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
/* This is only necessary to support the "as" warning, but
we don't want to warn about "as" in import statements. */
if
(
type
==
NAME
&&
len
==
6
&&
str
[
0
]
==
'i'
&&
strcmp
(
str
,
"import"
)
==
0
)
handling_import
=
1
;
/* Warn about with as NAME */
if
(
type
==
NAME
&&
!
(
ps
->
p_flags
&
CO_FUTURE_WITH_STATEMENT
))
{
if
(
len
==
4
&&
str
[
0
]
==
'w'
&&
strcmp
(
str
,
"with"
)
==
0
)
warn
(
with_msg
,
err_ret
->
filename
,
tok
->
lineno
);
else
if
(
!
(
handling_import
||
handling_with
)
&&
len
==
2
&&
str
[
0
]
==
'a'
&&
strcmp
(
str
,
"as"
)
==
0
)
warn
(
as_msg
,
err_ret
->
filename
,
tok
->
lineno
);
if
(
type
==
NOTEQUAL
)
{
if
(
!
(
ps
->
p_flags
&
CO_FUTURE_BARRY_AS_BDFL
)
&&
strcmp
(
str
,
"!="
))
{
err_ret
->
error
=
E_SYNTAX
;
break
;
}
else
if
((
ps
->
p_flags
&
CO_FUTURE_BARRY_AS_BDFL
)
&&
strcmp
(
str
,
"<>"
))
{
err_ret
->
text
=
"with Barry as BDFL, use '<>' "
"instead of '!='"
;
err_ret
->
error
=
E_SYNTAX
;
break
;
}
}
else
if
(
type
==
NAME
&&
(
ps
->
p_flags
&
CO_FUTURE_WITH_STATEMENT
)
&&
len
==
4
&&
str
[
0
]
==
'w'
&&
strcmp
(
str
,
"with"
)
==
0
)
handling_with
=
1
;
#endif
if
(
a
>=
tok
->
line_start
)
col_offset
=
a
-
tok
->
line_start
;
...
...
Parser/tokenizer.c
View file @
e3944a5e
...
...
@@ -1040,6 +1040,7 @@ PyToken_TwoChars(int c1, int c2)
break
;
case
'<'
:
switch
(
c2
)
{
case
'>'
:
return
NOTEQUAL
;
case
'='
:
return
LESSEQUAL
;
case
'<'
:
return
LEFTSHIFT
;
}
...
...
Python/future.c
View file @
e3944a5e
...
...
@@ -39,6 +39,8 @@ future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename)
continue
;
}
else
if
(
strcmp
(
feature
,
FUTURE_UNICODE_LITERALS
)
==
0
)
{
continue
;
}
else
if
(
strcmp
(
feature
,
FUTURE_BARRY_AS_BDFL
)
==
0
)
{
ff
->
ff_features
|=
CO_FUTURE_BARRY_AS_BDFL
;
}
else
if
(
strcmp
(
feature
,
"braces"
)
==
0
)
{
PyErr_SetString
(
PyExc_SyntaxError
,
"not a chance"
);
...
...
Python/graminit.c
View file @
e3944a5e
This diff is collapsed.
Click to expand it.
Python/pythonrun.c
View file @
e3944a5e
...
...
@@ -1011,6 +1011,8 @@ static int PARSER_FLAGS(PyCompilerFlags *flags)
parser_flags
|=
PyPARSE_DONT_IMPLY_DEDENT
;
if
(
flags
->
cf_flags
&
PyCF_IGNORE_COOKIE
)
parser_flags
|=
PyPARSE_IGNORE_COOKIE
;
if
(
flags
->
cf_flags
&
CO_FUTURE_BARRY_AS_BDFL
)
parser_flags
|=
PyPARSE_BARRY_AS_BDFL
;
return
parser_flags
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment