structure refactored
Этот коммит содержится в:
		
							родитель
							
								
									44714fb932
								
							
						
					
					
						коммит
						1efd46aaba
					
				
					 16 изменённых файлов: 89 добавлений и 43 удалений
				
			
		
							
								
								
									
										4
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								Makefile
									
										
									
									
									
								
							|  | @ -6,7 +6,7 @@ all: clean test build install | |||
| 
 | ||||
| build/$(APPNAME): | ||||
| 	@echo $(TS) Building $(APPAME) ... | ||||
| 	@go build -ldflags $(LDFLAGS) -o build/$(APPNAME) platform/main/main.go | ||||
| 	@go build -ldflags $(LDFLAGS) -o build/$(APPNAME) main.go | ||||
| 	@echo $(TS) Done. | ||||
| 
 | ||||
| build: build/$(APPNAME) | ||||
|  | @ -20,7 +20,7 @@ install: | |||
| 	@echo $(TS) Installing $(APPNAME) ... | ||||
| 	@cp build/$(APPNAME) $(GOPATH)/bin/ | ||||
| 	@mkdir -p $(HOME)/esp32/ | ||||
| 	@cp infrastructure/ino/mapping.json $(HOME)/esp32/mapping.json | ||||
| 	@cp mapping.json $(HOME)/esp32/mapping.json | ||||
| 	@echo $(TS) Done. | ||||
| 
 | ||||
| packages: | ||||
|  |  | |||
							
								
								
									
										7
									
								
								api/worker/mapping.go
									
										
									
									
									
										Обычный файл
									
								
							
							
						
						
									
										7
									
								
								api/worker/mapping.go
									
										
									
									
									
										Обычный файл
									
								
							|  | @ -0,0 +1,7 @@ | |||
| package worker | ||||
| 
 | ||||
| // Mapping specifies the api logic to apply transformation to a specific identifier. | ||||
| type Mapping interface { | ||||
| 	Apply(ident string) string | ||||
| 	Read() error | ||||
| } | ||||
							
								
								
									
										6
									
								
								api/worker/worker.go
									
										
									
									
									
										Обычный файл
									
								
							
							
						
						
									
										6
									
								
								api/worker/worker.go
									
										
									
									
									
										Обычный файл
									
								
							|  | @ -0,0 +1,6 @@ | |||
| package worker | ||||
| 
 | ||||
| // Worker specifies the api logic of transforming a source code format into another target format. | ||||
| type Worker interface { | ||||
| 	Start() error | ||||
| } | ||||
|  | @ -1,7 +0,0 @@ | |||
| package worker | ||||
| 
 | ||||
| // Mapping specifies the business logic to apply transformation to a specific identifier. | ||||
| type Mapping interface { | ||||
| 	Apply(ident string) string | ||||
| 	Read() error | ||||
| } | ||||
|  | @ -1,6 +0,0 @@ | |||
| package worker | ||||
| 
 | ||||
| // Worker specifies the business logic of transforming a source code format into another target format. | ||||
| type Worker interface { | ||||
| 	Start() error | ||||
| } | ||||
|  | @ -2,8 +2,8 @@ package transpile | |||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"github.com/andygeiss/esp32-transpiler/business/transpiler" | ||||
| 	"github.com/andygeiss/esp32-transpiler/business/worker" | ||||
| 	"github.com/andygeiss/esp32-transpiler/api/transpiler" | ||||
| 	"github.com/andygeiss/esp32-transpiler/api/worker" | ||||
| ) | ||||
| 
 | ||||
| // Transpiler uses a given worker to main source code. | ||||
|  | @ -3,8 +3,8 @@ package transpile_test | |||
| import ( | ||||
| 	"bytes" | ||||
| 	. "github.com/andygeiss/assert" | ||||
| 	"github.com/andygeiss/esp32-transpiler/application/transpile" | ||||
| 	"github.com/andygeiss/esp32-transpiler/business/worker" | ||||
| 	"github.com/andygeiss/esp32-transpiler/impl/transpile" | ||||
| 	"github.com/andygeiss/esp32-transpiler/api/worker" | ||||
| 	"io" | ||||
| 	"testing" | ||||
| ) | ||||
|  | @ -1,12 +1,12 @@ | |||
| package ino | ||||
| package worker | ||||
| 
 | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"github.com/andygeiss/esp32-transpiler/business/worker" | ||||
| 	"github.com/andygeiss/esp32-transpiler/api/worker" | ||||
| 	"io/ioutil" | ||||
| ) | ||||
| 
 | ||||
| // Mapping specifies the business logic to apply transformation to a specific Golang identifier by reading simple JSON map. | ||||
| // Mapping specifies the api logic to apply transformation to a specific Golang identifier by reading simple JSON map. | ||||
| type Mapping struct { | ||||
| 	Filename string            `json:"filename"` | ||||
| 	Rules    map[string]string `json:"rules"` | ||||
|  | @ -1,8 +1,8 @@ | |||
| package ino | ||||
| package worker | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"github.com/andygeiss/esp32-transpiler/business/worker" | ||||
| 	"github.com/andygeiss/esp32-transpiler/api/worker" | ||||
| 	"go/ast" | ||||
| 	"go/parser" | ||||
| 	"go/token" | ||||
|  | @ -19,7 +19,7 @@ const ( | |||
| 
 | ||||
| var mapping worker.Mapping | ||||
| 
 | ||||
| // Worker specifies the business logic of transforming a source code format into another target format. | ||||
| // Worker specifies the api logic of transforming a source code format into another target format. | ||||
| type Worker struct { | ||||
| 	in  io.Reader | ||||
| 	out io.Writer | ||||
|  | @ -1,9 +1,8 @@ | |||
| package ino_test | ||||
| package worker | ||||
| 
 | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	. "github.com/andygeiss/assert" | ||||
| 	"github.com/andygeiss/esp32-transpiler/infrastructure/ino" | ||||
| 	"strings" | ||||
| 	"testing" | ||||
| ) | ||||
|  | @ -21,10 +20,10 @@ func Trim(s string) string { | |||
| // The Worker will be started and used to transform the source into an Arduino sketch format. | ||||
| func Validate(source, expected string, t *testing.T) { | ||||
| 	var in, out bytes.Buffer | ||||
| 	mapping := ino.NewMapping("mapping.json") | ||||
| 	mapping := NewMapping("mapping.json") | ||||
| 	Assert(t, mapping.Read(), IsNil()) | ||||
| 	in.WriteString(source) | ||||
| 	worker := ino.NewWorker(&in, &out, mapping) | ||||
| 	worker := NewWorker(&in, &out, mapping) | ||||
| 	Assert(t, worker.Start(), IsNil()) | ||||
| 	code := out.String() | ||||
| 	tcode, texpected := Trim(code), Trim(expected) | ||||
|  | @ -222,10 +221,10 @@ func TestFunctionWithFunctionParam(t *testing.T) { | |||
| 
 | ||||
| func TestPackageImport(t *testing.T) { | ||||
| 	source := `package test | ||||
| 	import "github.com/andygeiss/esp32-mqtt/business/controller" | ||||
| 	import "github.com/andygeiss/esp32-mqtt/business/controller/serial" | ||||
| 	import "github.com/andygeiss/esp32/business/controller/timer" | ||||
| 	import wifi "github.com/andygeiss/esp32/business/controller/wifi" | ||||
| 	import "github.com/andygeiss/esp32-mqtt/api/controller" | ||||
| 	import "github.com/andygeiss/esp32-mqtt/api/controller/serial" | ||||
| 	import "github.com/andygeiss/esp32/api/controller/timer" | ||||
| 	import wifi "github.com/andygeiss/esp32/api/controller/wifi" | ||||
| 	` | ||||
| 	expected := ` | ||||
| 	#include <WiFi.h> | ||||
|  | @ -236,9 +235,9 @@ func TestPackageImport(t *testing.T) { | |||
| func TestPackageImport_ButIgnoreController(t *testing.T) { | ||||
| 	source := `package test | ||||
| 	import controller "github.com/andygeiss/esp32-controller" | ||||
| 	import "github.com/andygeiss/esp32-mqtt/business/controller/serial" | ||||
| 	import "github.com/andygeiss/esp32/business/controller/timer" | ||||
| 	import wifi "github.com/andygeiss/esp32/business/controller/wifi" | ||||
| 	import "github.com/andygeiss/esp32-mqtt/api/controller/serial" | ||||
| 	import "github.com/andygeiss/esp32/api/controller/timer" | ||||
| 	import wifi "github.com/andygeiss/esp32/api/controller/wifi" | ||||
| 	` | ||||
| 	expected := ` | ||||
| 	#include <WiFi.h> | ||||
|  | @ -1,11 +1,11 @@ | |||
| package main | ||||
| package esp32_transpiler | ||||
| 
 | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"github.com/andygeiss/esp32-transpiler/application/transpile" | ||||
| 	"github.com/andygeiss/esp32-transpiler/infrastructure/ino" | ||||
| 	"github.com/andygeiss/log" | ||||
| 	"github.com/andygeiss/esp32-transpiler/impl/transpile" | ||||
| 	"github.com/andygeiss/esp32-transpiler/impl/worker" | ||||
| 	log "github.com/andygeiss/log/impl" | ||||
| 	"os" | ||||
| ) | ||||
| 
 | ||||
|  | @ -36,7 +36,7 @@ func printUsage() { | |||
| 	flag.PrintDefaults() | ||||
| 	fmt.Print("\n") | ||||
| 	fmt.Print("Example:\n") | ||||
| 	fmt.Printf("\tesp32 -source application/blink/controller.go -target application/blink/controller.ino\n\n") | ||||
| 	fmt.Printf("\tesp32 -source impl/blink/controller.go -target impl/blink/controller.worker\n\n") | ||||
| } | ||||
| 
 | ||||
| func safeTranspile(mapping, source, target string) { | ||||
|  | @ -53,11 +53,11 @@ func safeTranspile(mapping, source, target string) { | |||
| 		log.Fatal("Arduino sketch file [%s] could not be opened! %v", target, err) | ||||
| 	} | ||||
| 	// Transpiles the Golang source into Arduino sketch. | ||||
| 	m := ino.NewMapping(mapping) | ||||
| 	m := worker.NewMapping(mapping) | ||||
| 	if err := m.Read(); err != nil { | ||||
| 		log.Fatal("%v", err) | ||||
| 	} | ||||
| 	worker := ino.NewWorker(in, out, m) | ||||
| 	worker := worker.NewWorker(in, out, m) | ||||
| 	trans := transpile.NewTranspiler(worker) | ||||
| 	if err := trans.Transpile(); err != nil { | ||||
| 		log.Fatal("%v", err) | ||||
							
								
								
									
										47
									
								
								mapping.json
									
										
									
									
									
										Обычный файл
									
								
							
							
						
						
									
										47
									
								
								mapping.json
									
										
									
									
									
										Обычный файл
									
								
							|  | @ -0,0 +1,47 @@ | |||
| { | ||||
|     "digital.Low": "LOW", | ||||
|     "digital.High": "HIGH", | ||||
|     "digital.ModeInput": "INPUT", | ||||
|     "digital.ModeOutput": "OUTPUT", | ||||
|     "digital.PinMode": "pinMode", | ||||
|     "digital.Write": "digitalWrite", | ||||
|     "random.Num": "random", | ||||
|     "random.NumBetween": "random", | ||||
|     "random.Seed": "randomSeed", | ||||
|     "serial.Available": "Serial.available", | ||||
|     "serial.BaudRate300": "300", | ||||
|     "serial.BaudRate600": "600", | ||||
|     "serial.BaudRate1200": "1200", | ||||
|     "serial.BaudRate2400": "2400", | ||||
|     "serial.BaudRate4800": "4800", | ||||
|     "serial.BaudRate9600": "9600", | ||||
|     "serial.BaudRate14400": "14400", | ||||
|     "serial.BaudRate28800": "28800", | ||||
|     "serial.BaudRate38400": "38400", | ||||
|     "serial.BaudRate57600": "57600", | ||||
|     "serial.BaudRate115200": "115200", | ||||
|     "serial.Begin": "Serial.begin", | ||||
|     "serial.Print": "Serial.print", | ||||
|     "serial.Println": "Serial.println", | ||||
|     "timer.Delay": "delay", | ||||
|     "wifi": "WiFi", | ||||
|     "wifi.Begin": "WiFi.begin", | ||||
|     "wifi.BeginEncrypted": "WiFi.begin", | ||||
|     "wifi.BSSID": "WiFi.BSSID", | ||||
|     "wifi.Disconnect": "WiFi.disconnect", | ||||
|     "wifi.EncryptionType": "WiFi.encryptionType", | ||||
|     "wifi.EncryptionTypeAuto": "8", | ||||
|     "wifi.EncryptionTypeCCMP": "4", | ||||
|     "wifi.EncryptionTypeNone": "7", | ||||
|     "wifi.EncryptionTypeTKIP": "2", | ||||
|     "wifi.EncryptionTypeWEP": "5", | ||||
|     "wifi.LocalIP": "WiFi.localIP", | ||||
|     "wifi.RSSI": "WiFi.RSSI", | ||||
|     "wifi.ScanNetworks": "WiFi.scanNetworks", | ||||
|     "wifi.SetDNS": "WiFi.setDNS", | ||||
|     "wifi.SSID": "WiFi.SSID", | ||||
|     "wifi.StatusConnected": "WL_CONNECTED", | ||||
|     "wifi.StatusIdle": "WL_IDLE", | ||||
|     "Loop": "void loop", | ||||
|     "Setup": "void setup" | ||||
| } | ||||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче
	
	 andygeiss
						andygeiss