Skip to content

Commit

Permalink
Refactor: move normal package out of tosca
Browse files Browse the repository at this point in the history
* Also improve `puccini-tosca parse`
  • Loading branch information
tliron committed Aug 14, 2023
1 parent 162b14d commit 8b17f08
Show file tree
Hide file tree
Showing 117 changed files with 409 additions and 407 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ other tools, [`puccini-csar`](puccini-csar/).

### Design Principles

Puccini's TOSCA parser comprises 5 multi-threaded [phases](tosca/parser/) that handle validation,
Puccini's TOSCA parser comprises 6 multi-threaded [phases](tosca/parser/) that handle validation,
inheritance, assignment, and normalization of TOSCA's many types and templates, resulting in a
[flat, serializable data structure](tosca/normal/) that can be directly consumed by your program.
[flat, serializable data structure](normal/) that can be directly consumed by your program.
Validation error messages are precise and useful.


Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/tliron/puccini
go 1.21

require (
github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127
github.com/fxamacker/cbor/v2 v2.4.0
github.com/dop251/goja v0.0.0-20230812105242-81d76064690d
github.com/fxamacker/cbor/v2 v2.5.0
github.com/klauspost/compress v1.16.7
github.com/klauspost/pgzip v1.2.6
github.com/segmentio/ksuid v1.0.4
Expand All @@ -13,7 +13,7 @@ require (
github.com/tliron/commonlog v0.1.1
github.com/tliron/exturl v0.2.4
github.com/tliron/go-ard v0.1.1
github.com/tliron/kutil v0.2.8
github.com/tliron/kutil v0.2.9
github.com/tliron/yamlkeys v1.3.6
github.com/vmihailenco/msgpack/v5 v5.3.5
)
Expand Down Expand Up @@ -71,13 +71,13 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/tools v0.8.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/docker/docker v23.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bc
github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A=
github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0=
github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 h1:qwcF+vdFrvPSEUDSX5RVoRccG8a5DhOdWdQ4zN62zzo=
github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4=
github.com/dop251/goja v0.0.0-20230812105242-81d76064690d h1:9aaGwVf4q+kknu+mROAXUApJ1DoOwhE8dGj/XLBYzWg=
github.com/dop251/goja v0.0.0-20230812105242-81d76064690d/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4=
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM=
github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0=
Expand All @@ -52,8 +52,8 @@ github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88=
github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/fxamacker/cbor/v2 v2.5.0 h1:oHsG0V/Q6E/wqTS2O1Cozzsy69nqCiguo5Q1a1ADivE=
github.com/fxamacker/cbor/v2 v2.5.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
Expand Down Expand Up @@ -172,8 +172,8 @@ github.com/tliron/exturl v0.2.4 h1:/7lvJUrfJgxNyzMaeS6lKXj6NbDJf3BenoncgVzZChY=
github.com/tliron/exturl v0.2.4/go.mod h1:lMm4XTcIMul+BIMein+aeDEkdpkcHMyJyWL4Sr3J/e4=
github.com/tliron/go-ard v0.1.1 h1:Z0JD63j387RmjiJNuMHEmj6+ht3Aj0/tY3sSbv/MzRU=
github.com/tliron/go-ard v0.1.1/go.mod h1:b8BG7fxGd/trwh9zD6FH797xgRLa9g6SN+sR4xrkzEA=
github.com/tliron/kutil v0.2.8 h1:vk8WNyZUsHBL1i0+b1HMFR41tHLWZs+CAJLWHmphSgU=
github.com/tliron/kutil v0.2.8/go.mod h1:ciY8a3bQfVyzdd/mXvBLlQrUq4gIpvuc+mTj9qHrvzY=
github.com/tliron/kutil v0.2.9 h1:JchzoOHcEYf1nl+kfyT4Si55pgiVmPOBYSLSmE+hh44=
github.com/tliron/kutil v0.2.9/go.mod h1:AnGFQ4vobNiGnxJ2BZ6Q3fkFy5UHyvPgDVvIUKtBbaM=
github.com/tliron/yamlkeys v1.3.6 h1:PPV4q7flMqIvmSUSsEZuns7Qt3VIMxkhBj+6KTRvI9c=
github.com/tliron/yamlkeys v1.3.6/go.mod h1:K/uKQwMke5a9h6YW/Sj9pcp66vU3lRP97OrOjo/ELoU=
github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8=
Expand All @@ -192,8 +192,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
Expand Down Expand Up @@ -227,23 +227,23 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand Down
Binary file modified library/default.pgo
Binary file not shown.
41 changes: 24 additions & 17 deletions library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import (
"github.com/tliron/puccini/tosca/parsing"
"github.com/tliron/yamlkeys"
)
import "github.com/tliron/puccini/normal"

var parserContext = parser.NewContext()
var parser_ = parser.NewParser()

//export Compile
func Compile(url *C.char, inputs *C.char, quirks *C.char, resolve C.char, coerce C.char) *C.char {
context := contextpkg.TODO()

inputs_ := make(map[string]ard.Value)

if data, err := yamlkeys.DecodeAll(strings.NewReader(C.GoString(inputs))); err == nil {
Expand Down Expand Up @@ -58,30 +61,34 @@ func Compile(url *C.char, inputs *C.char, quirks *C.char, resolve C.char, coerce
return result(nil, nil, err)
}

var url_ exturl.URL
var result_ parser.Result
var clout *cloutpkg.Clout
var err error

urlContext := exturl.NewContext()
defer urlContext.Release()
context := contextpkg.TODO()

var url_ exturl.URL
var err error
if url_, err = urlContext.NewValidURL(context, C.GoString(url), nil); err != nil {
return result(nil, nil, err)
}

if result_, err = parserContext.Parse(context, parser.ParseContext{URL: url_, Quirks: quirks_, Inputs: inputs_}); err != nil {
return result(nil, result_.Problems, err)
parserContext := parser_.NewContext()
parserContext.URL = url_
parserContext.Quirks = quirks_
parserContext.Inputs = inputs_
var normalServiceTemplate *normal.ServiceTemplate
if normalServiceTemplate, err = parserContext.Parse(context); err != nil {
return result(nil, parserContext.GetProblems(), err)
}

if clout, err = result_.NormalServiceTemplate.Compile(); err != nil {
return result(clout, result_.Problems, err)
problems := parserContext.GetProblems()

var clout *cloutpkg.Clout
if clout, err = normalServiceTemplate.Compile(); err != nil {
return result(clout, problems, err)
}

execContext := js.ExecContext{
Clout: clout,
Problems: result_.Problems,
Problems: problems,
URLContext: urlContext,
History: true,
Format: "yaml",
Expand All @@ -91,19 +98,19 @@ func Compile(url *C.char, inputs *C.char, quirks *C.char, resolve C.char, coerce

if resolve != 0 {
execContext.Resolve()
if !result_.Problems.Empty() {
return result(clout, result_.Problems, nil)
if !problems.Empty() {
return result(clout, problems, nil)
}
}

if coerce != 0 {
execContext.Coerce()
if !result_.Problems.Empty() {
return result(clout, result_.Problems, nil)
if !problems.Empty() {
return result(clout, problems, nil)
}
}

return result(clout, result_.Problems, nil)
return result(clout, problems, nil)
}

func result(clout *cloutpkg.Clout, problems *problems.Problems, err error) *C.char {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified puccini-clout/default.pgo
Binary file not shown.
Binary file modified puccini-csar/default.pgo
Binary file not shown.
6 changes: 3 additions & 3 deletions puccini-tosca/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ If you need more diagnostics for TOSCA parsing use the `parse` command. It works
`compile` but does not emit Clout. Instead, it provides you various flages for examining the
internal workings of Puccini's TOSCA parser.

By default Puccini will attempt all [5 parser phases](../tosca/parser/). This is in order to give
By default Puccini will attempt all [6 parser phases](../tosca/parser/). This is in order to give
users as complete a problem report as possible. However, if you're getting too many problems it
may be useful to specify `--stop/-s` with a phase number (1-5) at which you wish the to stop. Note
that `-s 0` will skip the TOSCA parser entirely and just check that the YAML input is readable.
may be useful to specify `--stop/-s` with a phase number (1-6) at which you wish the to stop.

`--dump/-d` is used to dump the internal data of phases. You may specify multiple phases to dump
using ",", e.g. `-d 2,3,4`. Per phase you will see:
Expand All @@ -68,6 +67,7 @@ using ",", e.g. `-d 2,3,4`. Per phase you will see:
* Phase 4: Inheritance. A tree of all inheritance tasks and their dependencies by path.
* Phase 5: Rendering. Dumps the rendered entities.
More useful, perhaps, would be the `--filter/-r` flag (see below).
* Phase 6: Normalization. Dumps the normalized structures.

The `--filter/-r` flag can be used to filter for specific parsed entities. Each entity is given a
path that more-or-less follows JSON. For example, a path can be:
Expand Down
1 change: 1 addition & 0 deletions puccini-tosca/commands/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var compileCommand = &cobra.Command{
url = args[0]
}

dumpPhases = nil
Compile(contextpkg.TODO(), url)
},
}
Expand Down
Loading

0 comments on commit 8b17f08

Please sign in to comment.