Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Scala Macro Tools
提交
8e670a35
S
Scala Macro Tools
项目概览
梦境迷离
/
Scala Macro Tools
上一次同步 大约 1 年
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Scala Macro Tools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
8e670a35
编写于
6月 16, 2021
作者:
梦境迷离
提交者:
GitHub
6月 16, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test (#3)
* add test * add readme
上级
042a677a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
118 addition
and
11 deletion
+118
-11
.github/workflows/ScalaCI.yml
.github/workflows/ScalaCI.yml
+4
-3
.gitignore
.gitignore
+3
-1
README.md
README.md
+38
-4
build.sbt
build.sbt
+29
-1
examples212/src/main/scala/io/github/dreamylost/Main.scala
examples212/src/main/scala/io/github/dreamylost/Main.scala
+21
-0
examples213/src/main/scala/io/github/dreamylost/Main.scala
examples213/src/main/scala/io/github/dreamylost/Main.scala
+21
-0
project/Publishing.scala
project/Publishing.scala
+2
-2
未找到文件。
.github/workflows/ScalaCI.yml
浏览文件 @
8e670a35
name
:
Scala CI
name
:
Build
on
:
push
:
...
...
@@ -22,11 +22,12 @@ jobs:
with
:
java-version
:
1.8
-
name
:
Publish Local
run
:
sbt +publishLocal
-
name
:
Build
run
:
sbt +compile
-
name
:
Run Test
run
:
sbt test
-
name
:
Publish Local
run
:
sbt publishLocal
\ No newline at end of file
.gitignore
浏览文件 @
8e670a35
...
...
@@ -4,4 +4,6 @@
/target/
/target/scala-2.13/classes/
/target/scala-2.13/test-classes/
.idea/
\ No newline at end of file
.idea/
*.iml
.bsp
\ No newline at end of file
README.md
浏览文件 @
8e670a35
# scala-macro-tools
# scala-macro-tools [![Build](https://github.com/jxnu-liguobin/scala-macro-tools/actions/workflows/ScalaCI.yml/badge.svg)](https://github.com/jxnu-liguobin/scala-macro-tools/actions/workflows/ScalaCI.yml)
Motivation
--
scala macro and abstract syntax tree learning code.
# @toString
-
Argument
-
Note
-
`verbose`
Whether to enable detailed log.
-
`withFieldName`
Whether to include the name of the field in the toString.
-
`withInternalField`
Whether to include the fields defined within a class.
...
...
@@ -22,7 +25,38 @@ class TestClass(val i: Int = 0, var j: Int) {
println
(
new
TestClass
(
1
,
2
));
```
|
withInternalField / withFieldName
| false |true
|
withInternalField / withFieldName
| false |true
| ---- | ---- |----|
|false|
```TestClass(1, 2)```
|
```TestClass(i=0, j=2)```
|
|true|
```TestClass(1, 2, 0, hello, world)```
|
```TestClass(i=1, j=2, y=0, z=hello, x=world)```
|
\ No newline at end of file
|true|
```TestClass(1, 2, 0, hello, world)```
|
```TestClass(i=1, j=2, y=0, z=hello, x=world)```
|
# How to use
Add library dependency
```
scala
"io.github.jxnu-liguobin"
%%
"scala-macro-tools"
%
"<VERSION>"
```
The artefacts have been uploaded to Maven Central. Alternatively, they are also available on the GitHub registry.
| Library Version | Scala 2.11 | Scala 2.12 | Scala 2.13 |
|---------|------------|------------|------------|
|0.0.1|-|-|
[
![Maven Central
](
https://img.shields.io/maven-central/v/io.github.jxnu-liguobin/scala-macro-tools_2.13.svg?label=Maven%20Central
)
](https://search.maven.org/search?q=g:%22io.github.jxnu-liguobin%22%20AND%20a:%22scala-macro-tools_2.13%22)|
Importing the library into your build system (e.g gradle, sbt), is not enough. You need to follow an extra step.
| Scala 2.11 | Scala 2.12 | Scala 2.13 |
|------------|-------------|------------|
| Import macro paradise plugin | Import macro paradise plugin | Enable compiler flag
`-Ymacro-annotations`
required |
```
scala
addCompilerPlugin
(
"org.scalamacros"
%
"paradise_<your-scala-version>"
%
"<plugin-version>"
)
```
Where
`<your-scala-version>`
must be the full scala version. For example 2.12.13, and not 2.12.
If that doesn't work, google for alternatives.
In version scala
`2.13.x`
, the functionality of macro paradise has been included in the scala compiler directly.
However, you must still enable the compiler flag
`-Ymacro-annotations`
. Please see examples from
`examples212`
sub-project.
\ No newline at end of file
build.sbt
浏览文件 @
8e670a35
...
...
@@ -37,4 +37,32 @@ lazy val root = (project in file("."))
commitNextVersion
,
pushChanges
)
).
settings
(
Publishing
.
publishSettings
)
).
settings
(
Publishing
.
publishSettings
).
settings
(
libraryDependencies
++=
(
CrossVersion
.
partialVersion
(
scalaVersion
.
value
)
match
{
case
Some
((
2
,
n
))
=>
getParadise
(
n
)
case
_
=>
None
}).
fold
(
Seq
.
empty
[
ModuleID
])(
f
=>
Seq
(
compilerPlugin
(
f
)))
)
lazy
val
`
examples213` = (project in file("examples213")).settings(scalaVersion := scala213)
.settings(libraryDependencies ++= Seq(
"io.github.jxnu-liguobin" %% "scala-macro-tools" % (version in ThisBuild).value,
)).settings(Compile / scalacOptions += "-Ymacro-annotations")
lazy val `examples212
`
=
(
project
in
file
(
"examples212"
)).
settings
(
scalaVersion
:=
scala212
)
.
settings
(
libraryDependencies
++=
Seq
(
"io.github.jxnu-liguobin"
%%
"scala-macro-tools"
%
(
version
in
ThisBuild
).
value
,
)).
settings
(
libraryDependencies
++=
(
CrossVersion
.
partialVersion
(
scalaVersion
.
value
)
match
{
case
Some
((
2
,
n
))
=>
getParadise
(
n
)
case
_
=>
None
}).
fold
(
Seq
.
empty
[
ModuleID
])(
f
=>
Seq
(
compilerPlugin
(
f
))))
def
getParadise
(
n
:
Long
)
:
Option
[
ModuleID
]
=
{
if
(
n
==
12
)
Option
(
"org.scalamacros"
%
s
"paradise_$scala212"
%
"2.1.1"
)
else
if
(
n
==
11
)
Option
(
"org.scalamacros"
%
s
"paradise_$scala211"
%
"2.1.1"
)
else
None
None
}
examples212/src/main/scala/io/github/dreamylost/Main.scala
0 → 100644
浏览文件 @
8e670a35
package
io.github.dreamylost
/**
*
* @author 梦境迷离
* @since 2021/6/16
* @version 1.0
*/
object
Main
extends
App
{
@toString
(
withInternalField
=
true
,
withFieldName
=
true
)
class
TestClass
(
val
i
:
Int
=
0
,
var
j
:
Int
)
{
val
y
:
Int
=
0
var
z
:
String
=
"hello"
var
x
:
String
=
"world"
}
val
s
=
new
TestClass
(
1
,
2
).
toString
println
(
s
)
}
examples213/src/main/scala/io/github/dreamylost/Main.scala
0 → 100644
浏览文件 @
8e670a35
package
io.github.dreamylost
/**
*
* @author 梦境迷离
* @since 2021/6/16
* @version 1.0
*/
object
Main
extends
App
{
@toString
(
withInternalField
=
true
,
withFieldName
=
true
)
class
TestClass
(
val
i
:
Int
=
0
,
var
j
:
Int
)
{
val
y
:
Int
=
0
var
z
:
String
=
"hello"
var
x
:
String
=
"world"
}
val
s
=
new
TestClass
(
1
,
2
).
toString
println
(
s
)
}
project/Publishing.scala
浏览文件 @
8e670a35
...
...
@@ -37,8 +37,8 @@ object Publishing {
homepage
:=
Some
(
url
(
"https://github.com/jxnu-liguobin"
)),
scmInfo
:=
Some
(
ScmInfo
(
url
(
"https://github.com/
bitlap
/scala-macro-tools"
),
"scm:git@github.com:
bitlap
/scala-macro-tools.git"
url
(
"https://github.com/
jxnu-liguobin
/scala-macro-tools"
),
"scm:git@github.com:
jxnu-liguobin
/scala-macro-tools.git"
))
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录