Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
70c852ca
C
Coca
项目概览
Phodal
/
Coca
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coca
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
70c852ca
编写于
1月 15, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: [python] change grammer for better fetch value
上级
83e06482
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
1546 addition
and
1321 deletion
+1546
-1321
languages/g4/PythonParser.g4
languages/g4/PythonParser.g4
+7
-5
languages/python/PythonParser.interp
languages/python/PythonParser.interp
+3
-1
languages/python/python_parser.go
languages/python/python_parser.go
+1506
-1306
languages/python/pythonparser_base_listener.go
languages/python/pythonparser_base_listener.go
+12
-0
languages/python/pythonparser_listener.go
languages/python/pythonparser_listener.go
+12
-0
trial/pkg/application/pyapp/py_ident_app_test.go
trial/pkg/application/pyapp/py_ident_app_test.go
+2
-1
trial/pkg/ast/pyast/python_ident_listener.go
trial/pkg/ast/pyast/python_ident_listener.go
+4
-8
未找到文件。
languages/g4/PythonParser.g4
浏览文件 @
70c852ca
...
...
@@ -144,7 +144,7 @@ simple_stmt
small_stmt
: testlist_star_expr assign_part? #expr_stmt
| {p.CheckVersion(2)}? PRINT ((test (COMMA test)* COMMA?)
| RIGHT_SHIFT test ((COMMA test)+ COMMA?)) {p.SetVersion(2);}
#print_stmt // Python 2
| RIGHT_SHIFT test ((COMMA test)+ COMMA?)) {p.SetVersion(2);} #print_stmt // Python 2
| DEL exprlist #del_stmt
| PASS #pass_stmt
| BREAK #break_stmt
...
...
@@ -153,14 +153,16 @@ small_stmt
| RAISE (test (COMMA test (COMMA test)?)?)? (FROM test)? #raise_stmt
| yield_expr #yield_stmt
| IMPORT dotted_as_names #import_stmt
| FROM ((DOT | ELLIPSIS)* dotted_name | (DOT | ELLIPSIS)+)
IMPORT (STAR | OPEN_PAREN import_as_names CLOSE_PAREN | import_as_names) #from_stmt
| FROM from_stmt_source IMPORT from_stmt_as_names #from_stmt
| GLOBAL name (COMMA name)* #global_stmt
| {p.CheckVersion(2)}? EXEC expr (IN test (COMMA test)?)? {p.SetVersion(2);}
#exec_stmt // Python 2
| {p.CheckVersion(2)}? EXEC expr (IN test (COMMA test)?)? {p.SetVersion(2);} #exec_stmt // Python 2
| ASSERT test (COMMA test)? #assert_stmt
| {p.CheckVersion(3)}? NONLOCAL name (COMMA name)* {p.SetVersion(3);}
#nonlocal_stmt // Python 3
| {p.CheckVersion(3)}? NONLOCAL name (COMMA name)* {p.SetVersion(3);} #nonlocal_stmt // Python 3
;
from_stmt_as_names : (STAR | OPEN_PAREN import_as_names CLOSE_PAREN | import_as_names);
from_stmt_source : ((DOT | ELLIPSIS)* dotted_name | (DOT | ELLIPSIS)+) ;
testlist_star_expr
: ((test | star_expr) COMMA)+ (test | star_expr)?
| testlist
...
...
languages/python/PythonParser.interp
浏览文件 @
70c852ca
此差异已折叠。
点击以展开。
languages/python/python_parser.go
浏览文件 @
70c852ca
此差异已折叠。
点击以展开。
languages/python/pythonparser_base_listener.go
浏览文件 @
70c852ca
...
...
@@ -273,6 +273,18 @@ func (s *BasePythonParserListener) EnterNonlocal_stmt(ctx *Nonlocal_stmtContext)
// ExitNonlocal_stmt is called when production nonlocal_stmt is exited.
func
(
s
*
BasePythonParserListener
)
ExitNonlocal_stmt
(
ctx
*
Nonlocal_stmtContext
)
{}
// EnterFrom_stmt_as_names is called when production from_stmt_as_names is entered.
func
(
s
*
BasePythonParserListener
)
EnterFrom_stmt_as_names
(
ctx
*
From_stmt_as_namesContext
)
{}
// ExitFrom_stmt_as_names is called when production from_stmt_as_names is exited.
func
(
s
*
BasePythonParserListener
)
ExitFrom_stmt_as_names
(
ctx
*
From_stmt_as_namesContext
)
{}
// EnterFrom_stmt_source is called when production from_stmt_source is entered.
func
(
s
*
BasePythonParserListener
)
EnterFrom_stmt_source
(
ctx
*
From_stmt_sourceContext
)
{}
// ExitFrom_stmt_source is called when production from_stmt_source is exited.
func
(
s
*
BasePythonParserListener
)
ExitFrom_stmt_source
(
ctx
*
From_stmt_sourceContext
)
{}
// EnterTestlist_star_expr is called when production testlist_star_expr is entered.
func
(
s
*
BasePythonParserListener
)
EnterTestlist_star_expr
(
ctx
*
Testlist_star_exprContext
)
{}
...
...
languages/python/pythonparser_listener.go
浏览文件 @
70c852ca
...
...
@@ -134,6 +134,12 @@ type PythonParserListener interface {
// EnterNonlocal_stmt is called when entering the nonlocal_stmt production.
EnterNonlocal_stmt
(
c
*
Nonlocal_stmtContext
)
// EnterFrom_stmt_as_names is called when entering the from_stmt_as_names production.
EnterFrom_stmt_as_names
(
c
*
From_stmt_as_namesContext
)
// EnterFrom_stmt_source is called when entering the from_stmt_source production.
EnterFrom_stmt_source
(
c
*
From_stmt_sourceContext
)
// EnterTestlist_star_expr is called when entering the testlist_star_expr production.
EnterTestlist_star_expr
(
c
*
Testlist_star_exprContext
)
...
...
@@ -368,6 +374,12 @@ type PythonParserListener interface {
// ExitNonlocal_stmt is called when exiting the nonlocal_stmt production.
ExitNonlocal_stmt
(
c
*
Nonlocal_stmtContext
)
// ExitFrom_stmt_as_names is called when exiting the from_stmt_as_names production.
ExitFrom_stmt_as_names
(
c
*
From_stmt_as_namesContext
)
// ExitFrom_stmt_source is called when exiting the from_stmt_source production.
ExitFrom_stmt_source
(
c
*
From_stmt_sourceContext
)
// ExitTestlist_star_expr is called when exiting the testlist_star_expr production.
ExitTestlist_star_expr
(
c
*
Testlist_star_exprContext
)
...
...
trial/pkg/application/pyapp/py_ident_app_test.go
浏览文件 @
70c852ca
...
...
@@ -99,6 +99,7 @@ func Test_PythonImport(t *testing.T) {
file
,
_
:=
ioutil
.
ReadFile
(
"testdata/grammar/import_stmt.py"
)
codeFile
:=
app
.
Analysis
(
string
(
file
),
"import_stmt"
)
fmt
.
Println
(
codeFile
.
Imports
)
g
.
Expect
(
len
(
codeFile
.
Imports
))
.
To
(
Equal
(
8
))
g
.
Expect
(
len
(
codeFile
.
Imports
[
2
]
.
UsageName
))
.
To
(
Equal
(
2
))
g
.
Expect
(
len
(
codeFile
.
Imports
[
2
]
.
UsageName
))
.
To
(
Equal
(
10
))
}
trial/pkg/ast/pyast/python_ident_listener.go
浏览文件 @
70c852ca
...
...
@@ -53,15 +53,11 @@ func (s *PythonIdentListener) EnterImport_stmt(ctx *parser.Import_stmtContext) {
}
func
(
s
*
PythonIdentListener
)
EnterFrom_stmt
(
ctx
*
parser
.
From_stmtContext
)
{
if
ctx
.
Dotted_name
()
!=
nil
{
asNameText
:=
ctx
.
Dotted_name
()
.
GetText
()
codeImport
:=
&
trial
.
CodeImport
{
Source
:
asNameText
,
AsName
:
""
,
}
codeImport
:=
&
trial
.
CodeImport
{}
codeImport
.
Source
=
ctx
.
From_stmt_source
()
.
GetText
()
codeImport
.
UsageName
=
append
(
codeImport
.
UsageName
,
ctx
.
From_stmt_as_names
()
.
GetText
())
currentCodeFile
.
Imports
=
append
(
currentCodeFile
.
Imports
,
*
codeImport
)
}
currentCodeFile
.
Imports
=
append
(
currentCodeFile
.
Imports
,
*
codeImport
)
}
func
(
s
*
PythonIdentListener
)
EnterClassdef
(
ctx
*
parser
.
ClassdefContext
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录