Сценарий: Блок переменных
Этот коммит содержится в:
родитель
0addf00c20
коммит
bd58013fcd
3 изменённых файлов: 24 добавлений и 8 удалений
|
@ -19,4 +19,23 @@ const int c1 = 4;
|
||||||
const int c2 = 5;
|
const int c2 = 5;
|
||||||
const double c3 = 5.5;
|
const double c3 = 5.5;
|
||||||
const std::string s1 = "privet";
|
const std::string s1 = "privet";
|
||||||
|
```
|
||||||
|
|
||||||
|
Сценарий: Блок переменных
|
||||||
|
* Исходник:
|
||||||
|
```
|
||||||
|
package test
|
||||||
|
var (
|
||||||
|
c1 = 4
|
||||||
|
c2 = 5
|
||||||
|
c3 = 5.5
|
||||||
|
s1 = "privet"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
* Результат:
|
||||||
|
```
|
||||||
|
int c1 = 4;
|
||||||
|
int c2 = 5;
|
||||||
|
double c3 = 5.5;
|
||||||
|
std::string s1 = "privet";
|
||||||
```
|
```
|
||||||
|
|
|
@ -21,8 +21,7 @@ func handleGenDecl(decl ast.Decl) string {
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSpecs(specs []ast.Spec) string {
|
func handleSpecs(specs []ast.Spec) (code string) {
|
||||||
code := ""
|
|
||||||
for _, spec := range specs {
|
for _, spec := range specs {
|
||||||
if InConstBlock {
|
if InConstBlock {
|
||||||
code += "const "
|
code += "const "
|
||||||
|
@ -37,7 +36,7 @@ func handleSpecs(specs []ast.Spec) string {
|
||||||
code += handleTypeSpec(spec)
|
code += handleTypeSpec(spec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return code
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleImportSpec(spec ast.Spec) string {
|
func handleImportSpec(spec ast.Spec) string {
|
||||||
|
|
|
@ -35,7 +35,6 @@ func addTypeByValue(s *ast.ValueSpec) (code string) {
|
||||||
|
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case *ast.BasicLit:
|
case *ast.BasicLit:
|
||||||
code += " "
|
|
||||||
code += handleBasicLitType(v)
|
code += handleBasicLitType(v)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -56,8 +55,7 @@ func handleValueSpecNames(names []*ast.Ident) (code string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleValueSpecType(expr ast.Expr) string {
|
func handleValueSpecType(expr ast.Expr) (code string) {
|
||||||
code := ""
|
|
||||||
switch t := expr.(type) {
|
switch t := expr.(type) {
|
||||||
case *ast.SelectorExpr:
|
case *ast.SelectorExpr:
|
||||||
code += handleSelectorExpr(t)
|
code += handleSelectorExpr(t)
|
||||||
|
@ -66,7 +64,7 @@ func handleValueSpecType(expr ast.Expr) string {
|
||||||
case *ast.StarExpr:
|
case *ast.StarExpr:
|
||||||
code += handleStarExpr(t)
|
code += handleStarExpr(t)
|
||||||
}
|
}
|
||||||
return code
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleValueSpecValues(values []ast.Expr) string {
|
func handleValueSpecValues(values []ast.Expr) string {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче