Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
2ba6c2a9
wa
项目概览
wa-lang
/
wa
12 个月 前同步成功
通知
68
Star
655
Fork
45
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
wa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2ba6c2a9
编写于
9月 13, 2022
作者:
chai2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复并导出格式化函数
上级
782cab0d
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
53 addition
and
9 deletion
+53
-9
api/api.go
api/api.go
+10
-0
api/api_test.go
api/api_test.go
+14
-0
hello.wa
hello.wa
+1
-1
internal/ast/astutil/imports_test.go
internal/ast/astutil/imports_test.go
+3
-0
internal/ast/astutil/rewrite_test.go
internal/ast/astutil/rewrite_test.go
+3
-0
internal/ast/filter_test.go
internal/ast/filter_test.go
+3
-0
internal/format/format_test.go
internal/format/format_test.go
+2
-2
internal/printer/example_test.go
internal/printer/example_test.go
+3
-0
internal/printer/nodes.go
internal/printer/nodes.go
+10
-2
internal/printer/performance_test.go
internal/printer/performance_test.go
+2
-2
internal/printer/printer_test.go
internal/printer/printer_test.go
+2
-2
未找到文件。
api/api.go
浏览文件 @
2ba6c2a9
...
...
@@ -9,6 +9,7 @@ import (
"github.com/wa-lang/wa/internal/backends/compiler_wat"
"github.com/wa-lang/wa/internal/backends/target_spec"
"github.com/wa-lang/wa/internal/config"
"github.com/wa-lang/wa/internal/format"
"github.com/wa-lang/wa/internal/loader"
"github.com/wa-lang/wa/internal/logger"
)
...
...
@@ -115,3 +116,12 @@ func BuildVFS(vfs *config.PkgVFS, appPkg string, target Machine) (wat []byte, er
watOut
,
err
:=
compiler_wat
.
New
()
.
Compile
(
prog
,
target
)
return
[]
byte
(
watOut
),
err
}
// 格式化代码
func
FormatCode
(
filename
,
code
string
)
(
string
,
error
)
{
data
,
err
:=
format
.
File
(
nil
,
filename
,
code
)
if
err
!=
nil
{
return
""
,
err
}
return
string
(
data
),
nil
}
api/api_test.go
浏览文件 @
2ba6c2a9
// 版权 @2022 凹语言 作者。保留所有权利。
package
api_test
import
(
"fmt"
"github.com/wa-lang/wa/api"
)
func
ExampleFormatCode
()
{
s
,
_
:=
api
.
FormatCode
(
"hello.wa"
,
"fn add(a i32, b i32) i32 {return a+b}"
)
fmt
.
Println
(
s
)
// Output:
// fn add(a: i32, b: i32) => i32 { return a + b }
}
hello.wa
浏览文件 @
2ba6c2a9
...
...
@@ -10,5 +10,5 @@ fn main() {
}
fn add(a: i32, b: i32) => i32 {
return a
+
b
return a
+
b
}
internal/ast/astutil/imports_test.go
浏览文件 @
2ba6c2a9
...
...
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package
astutil
import
(
...
...
internal/ast/astutil/rewrite_test.go
浏览文件 @
2ba6c2a9
...
...
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package
astutil_test
import
(
...
...
internal/ast/filter_test.go
浏览文件 @
2ba6c2a9
...
...
@@ -4,6 +4,9 @@
// To avoid a cyclic dependency with github.com/wa-lang/wa/internal/parser, this file is in a separate package.
//go:build ignore
// +build ignore
package
ast_test
import
(
...
...
internal/format/format_test.go
浏览文件 @
2ba6c2a9
...
...
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build
!windows
// +build
!windows
//go:build
ignore
// +build
ignore
package
format
...
...
internal/printer/example_test.go
浏览文件 @
2ba6c2a9
...
...
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
package
printer_test
import
(
...
...
internal/printer/nodes.go
浏览文件 @
2ba6c2a9
...
...
@@ -363,6 +363,7 @@ func (p *printer) parameters(fields *ast.FieldList) {
// by a linebreak call after a type, or in the next multi-line identList
// will do the right thing.
p
.
identList
(
par
.
Names
,
ws
==
indent
)
p
.
print
(
token
.
COLON
)
p
.
print
(
blank
)
}
// parameter type
...
...
@@ -393,6 +394,9 @@ func (p *printer) signature(params, result *ast.FieldList) {
if
n
>
0
{
// result != nil
p
.
print
(
blank
)
p
.
print
(
token
.
ARROW
)
p
.
print
(
blank
)
if
n
==
1
&&
result
.
List
[
0
]
.
Names
==
nil
{
// single anonymous result; no ()'s
p
.
expr
(
stripParensAlways
(
result
.
List
[
0
]
.
Type
))
...
...
@@ -1459,11 +1463,14 @@ func (p *printer) spec(spec ast.Spec, n int, doIndent bool) {
switch
s
:=
spec
.
(
type
)
{
case
*
ast
.
ImportSpec
:
p
.
setComment
(
s
.
Doc
)
p
.
expr
(
sanitizeImportPath
(
s
.
Path
))
if
s
.
Name
!=
nil
{
p
.
expr
(
s
.
Name
)
p
.
print
(
blank
)
p
.
print
(
token
.
ARROW
)
p
.
print
(
blank
)
p
.
expr
(
s
.
Name
)
}
p
.
expr
(
sanitizeImportPath
(
s
.
Path
))
p
.
setComment
(
s
.
Comment
)
p
.
print
(
s
.
EndPos
)
...
...
@@ -1474,6 +1481,7 @@ func (p *printer) spec(spec ast.Spec, n int, doIndent bool) {
p
.
setComment
(
s
.
Doc
)
p
.
identList
(
s
.
Names
,
doIndent
)
// always present
if
s
.
Type
!=
nil
{
p
.
print
(
token
.
COLON
)
p
.
print
(
blank
)
p
.
expr
(
s
.
Type
)
}
...
...
internal/printer/performance_test.go
浏览文件 @
2ba6c2a9
...
...
@@ -5,8 +5,8 @@
// This file implements a simple printer performance benchmark:
// go test -bench=BenchmarkPrint
//go:build
!windows
// +build
!windows
//go:build
ignore
// +build
ignore
package
printer
...
...
internal/printer/printer_test.go
浏览文件 @
2ba6c2a9
...
...
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build
!windows
// +build
!windows
//go:build
ignore
// +build
ignore
package
printer
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录