feat: [python] make override success

上级 8d616647
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 {
*antlr.BaseLexer
......@@ -12,20 +22,43 @@ type PythonBaseLexer struct {
lastToken antlr.Token
useStrictDefault 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() {
if l._opened > 0 {
l._opened--
}
}
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() {
}
package xmlparse
package container
import (
l "container/list"
"sync"
)
type stack struct {
type Stack struct {
list *l.List
mu sync.Mutex
}
func NewStack() *stack {
func NewStack() *Stack {
list := l.New()
return &stack{list: list,}
return &Stack{list: list,}
}
func (s *stack) Push(t interface{}){
func (s *Stack) Push(t interface{}){
s.mu.Lock()
defer s.mu.Unlock()
s.list.PushFront(t)
}
func (s *stack) Pop() interface{} {
func (s *Stack) Pop() interface{} {
s.mu.Lock()
defer s.mu.Unlock()
ele := s.list.Front()
......@@ -33,17 +33,17 @@ func (s *stack) Pop() interface{} {
return nil
}
func (s *stack) Peak() interface{} {
func (s *Stack) Peak() interface{} {
s.mu.Lock()
defer s.mu.Unlock()
ele := s.list.Front()
return ele.Value
}
func (s *stack) Len() int {
func (s *Stack) Len() int {
return s.list.Len()
}
func (s *stack) IsEmpty() bool {
func (s *Stack) IsEmpty() bool {
return s.list.Len() == 0
}
......@@ -2,6 +2,7 @@ package xmlparse
import (
"encoding/xml"
"github.com/phodal/coca/pkg/infrastructure/container"
"io"
"strings"
)
......@@ -29,7 +30,7 @@ func ParseXML(r io.Reader) *XMLNode {
parser := xml.NewDecoder(r)
var root XMLNode
st := NewStack()
st := container.NewStack()
for {
token, err := parser.Token()
if err != nil {
......
......@@ -2,6 +2,7 @@ package pyapp
import (
. "github.com/onsi/gomega"
"io/ioutil"
"testing"
)
......@@ -10,7 +11,9 @@ func Test_TypeScriptConsoleLog(t *testing.T) {
g := NewGomegaWithT(t)
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))
}
......
# 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
......@@ -17,3 +17,8 @@ func (s *PythonIdentListener) EnterRoot(ctx *parser.RootContext) {
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.
先完成此消息的编辑!
想要评论请 注册