Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
96f126f3
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,发现更多精彩内容 >>
未验证
提交
96f126f3
编写于
1月 14, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: [python] make override success
上级
8d616647
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
68 addition
and
14 deletion
+68
-14
languages/python/python_base_lexer.go
languages/python/python_base_lexer.go
+36
-3
pkg/infrastructure/container/coll_stack.go
pkg/infrastructure/container/coll_stack.go
+9
-9
pkg/infrastructure/xmlparse/xml_parser.go
pkg/infrastructure/xmlparse/xml_parser.go
+2
-1
trial/pkg/application/pyapp/py_ident_app_test.go
trial/pkg/application/pyapp/py_ident_app_test.go
+4
-1
trial/pkg/application/pyapp/testdata/grammar/class_or_func_def_stmt.py
...lication/pyapp/testdata/grammar/class_or_func_def_stmt.py
+12
-0
trial/pkg/ast/pyast/python_ident_listener.go
trial/pkg/ast/pyast/python_ident_listener.go
+5
-0
未找到文件。
languages/python/python_base_lexer.go
浏览文件 @
96f126f3
package
parser
package
parser
import
"github.com/antlr/antlr4/runtime/Go/antlr"
import
(
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/pkg/infrastructure/container"
)
var
TabSize
=
8
var
indents
*
container
.
Stack
func
init
()
{
indents
=
container
.
NewStack
()
}
type
PythonBaseLexer
struct
{
type
PythonBaseLexer
struct
{
*
antlr
.
BaseLexer
*
antlr
.
BaseLexer
...
@@ -12,20 +22,43 @@ type PythonBaseLexer struct {
...
@@ -12,20 +22,43 @@ type PythonBaseLexer struct {
lastToken
antlr
.
Token
lastToken
antlr
.
Token
useStrictDefault
bool
useStrictDefault
bool
useStrictCurrent
bool
useStrictCurrent
bool
_opened
int
buffer
antlr
.
Token
}
}
func
(
l
*
PythonBaseLexer
)
IncIndentLevel
()
{
func
(
l
*
PythonBaseLexer
)
Emit
()
antlr
.
Token
{
emit
:=
l
.
BaseLexer
.
Emit
()
return
emit
}
func
(
l
*
PythonBaseLexer
)
IncIndentLevel
()
{
l
.
_opened
++
}
}
func
(
l
*
PythonBaseLexer
)
DecIndentLevel
()
{
func
(
l
*
PythonBaseLexer
)
DecIndentLevel
()
{
if
l
.
_opened
>
0
{
l
.
_opened
--
}
}
}
func
(
l
*
PythonBaseLexer
)
HandleNewLine
()
{
func
(
l
*
PythonBaseLexer
)
HandleNewLine
()
{
}
}
func
(
l
*
PythonBaseLexer
)
NextToken
()
antlr
.
Token
{
if
l
.
GetInputStream
()
.
LA
(
1
)
==
antlr
.
TokenEOF
&&
indents
.
Len
()
>
0
{
}
next
:=
l
.
BaseLexer
.
NextToken
()
// Get next token
if
next
.
GetChannel
()
==
antlr
.
TokenDefaultChannel
{
// Keep track of the last token on default channel
l
.
lastToken
=
next
}
return
next
}
func
(
l
*
PythonBaseLexer
)
HandleSpaces
()
{
func
(
l
*
PythonBaseLexer
)
HandleSpaces
()
{
}
}
pkg/infrastructure/
xmlparse
/coll_stack.go
→
pkg/infrastructure/
container
/coll_stack.go
浏览文件 @
96f126f3
package
xmlparse
package
container
import
(
import
(
l
"container/list"
l
"container/list"
"sync"
"sync"
)
)
type
s
tack
struct
{
type
S
tack
struct
{
list
*
l
.
List
list
*
l
.
List
mu
sync
.
Mutex
mu
sync
.
Mutex
}
}
func
NewStack
()
*
s
tack
{
func
NewStack
()
*
S
tack
{
list
:=
l
.
New
()
list
:=
l
.
New
()
return
&
s
tack
{
list
:
list
,}
return
&
S
tack
{
list
:
list
,}
}
}
func
(
s
*
s
tack
)
Push
(
t
interface
{}){
func
(
s
*
S
tack
)
Push
(
t
interface
{}){
s
.
mu
.
Lock
()
s
.
mu
.
Lock
()
defer
s
.
mu
.
Unlock
()
defer
s
.
mu
.
Unlock
()
s
.
list
.
PushFront
(
t
)
s
.
list
.
PushFront
(
t
)
}
}
func
(
s
*
s
tack
)
Pop
()
interface
{}
{
func
(
s
*
S
tack
)
Pop
()
interface
{}
{
s
.
mu
.
Lock
()
s
.
mu
.
Lock
()
defer
s
.
mu
.
Unlock
()
defer
s
.
mu
.
Unlock
()
ele
:=
s
.
list
.
Front
()
ele
:=
s
.
list
.
Front
()
...
@@ -33,17 +33,17 @@ func (s *stack) Pop() interface{} {
...
@@ -33,17 +33,17 @@ func (s *stack) Pop() interface{} {
return
nil
return
nil
}
}
func
(
s
*
s
tack
)
Peak
()
interface
{}
{
func
(
s
*
S
tack
)
Peak
()
interface
{}
{
s
.
mu
.
Lock
()
s
.
mu
.
Lock
()
defer
s
.
mu
.
Unlock
()
defer
s
.
mu
.
Unlock
()
ele
:=
s
.
list
.
Front
()
ele
:=
s
.
list
.
Front
()
return
ele
.
Value
return
ele
.
Value
}
}
func
(
s
*
s
tack
)
Len
()
int
{
func
(
s
*
S
tack
)
Len
()
int
{
return
s
.
list
.
Len
()
return
s
.
list
.
Len
()
}
}
func
(
s
*
s
tack
)
IsEmpty
()
bool
{
func
(
s
*
S
tack
)
IsEmpty
()
bool
{
return
s
.
list
.
Len
()
==
0
return
s
.
list
.
Len
()
==
0
}
}
pkg/infrastructure/xmlparse/xml_parser.go
浏览文件 @
96f126f3
...
@@ -2,6 +2,7 @@ package xmlparse
...
@@ -2,6 +2,7 @@ package xmlparse
import
(
import
(
"encoding/xml"
"encoding/xml"
"github.com/phodal/coca/pkg/infrastructure/container"
"io"
"io"
"strings"
"strings"
)
)
...
@@ -29,7 +30,7 @@ func ParseXML(r io.Reader) *XMLNode {
...
@@ -29,7 +30,7 @@ func ParseXML(r io.Reader) *XMLNode {
parser
:=
xml
.
NewDecoder
(
r
)
parser
:=
xml
.
NewDecoder
(
r
)
var
root
XMLNode
var
root
XMLNode
st
:=
NewStack
()
st
:=
container
.
NewStack
()
for
{
for
{
token
,
err
:=
parser
.
Token
()
token
,
err
:=
parser
.
Token
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
trial/pkg/application/pyapp/py_ident_app_test.go
浏览文件 @
96f126f3
...
@@ -2,6 +2,7 @@ package pyapp
...
@@ -2,6 +2,7 @@ package pyapp
import
(
import
(
.
"github.com/onsi/gomega"
.
"github.com/onsi/gomega"
"io/ioutil"
"testing"
"testing"
)
)
...
@@ -10,7 +11,9 @@ func Test_TypeScriptConsoleLog(t *testing.T) {
...
@@ -10,7 +11,9 @@ func Test_TypeScriptConsoleLog(t *testing.T) {
g
:=
NewGomegaWithT
(
t
)
g
:=
NewGomegaWithT
(
t
)
app
:=
new
(
PythonApiApp
)
app
:=
new
(
PythonApiApp
)
app
.
Analysis
(
"print('console.log')"
,
""
)
file
,
_
:=
ioutil
.
ReadFile
(
"testdata/grammar/class_or_func_def_stmt.py"
)
app
.
Analysis
(
string
(
file
),
""
)
g
.
Expect
(
1
)
.
To
(
Equal
(
1
))
g
.
Expect
(
1
)
.
To
(
Equal
(
1
))
}
}
...
...
trial/pkg/application/pyapp/testdata/grammar/class_or_func_def_stmt.py
0 → 100755
浏览文件 @
96f126f3
# class_or_func_def_stmt: decorator+ (classdef | funcdef);
# decorator classdef
@
decorator
class
foo
:
pass
# decorator decorator funcdef
@
accepts
(
int
,
int
)
@
returns
(
float
)
def
bar
(
low
,
high
):
pass
trial/pkg/ast/pyast/python_ident_listener.go
浏览文件 @
96f126f3
...
@@ -17,3 +17,8 @@ func (s *PythonIdentListener) EnterRoot(ctx *parser.RootContext) {
...
@@ -17,3 +17,8 @@ func (s *PythonIdentListener) EnterRoot(ctx *parser.RootContext) {
fmt
.
Println
(
ctx
)
fmt
.
Println
(
ctx
)
}
}
func
(
s
*
PythonIdentListener
)
EnterSingle_input
(
ctx
*
parser
.
Single_inputContext
)
{
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录