diff --git a/benchmarks/go.mod b/benchmarks/go.mod index e1676313..195db583 100644 --- a/benchmarks/go.mod +++ b/benchmarks/go.mod @@ -6,6 +6,6 @@ replace github.com/goccy/go-yaml => ../ require ( github.com/goccy/go-yaml v0.0.0-00010101000000-000000000000 - gopkg.in/yaml.v2 v2.3.0 - gopkg.in/yaml.v3 v3.0.0-20200506231410-2ff61e1afc86 + gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.1 ) diff --git a/benchmarks/go.sum b/benchmarks/go.sum index f1e4145c..3c36f012 100644 --- a/benchmarks/go.sum +++ b/benchmarks/go.sum @@ -1,75 +1,116 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= -github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= -github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= -github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= -github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= -github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= -github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= -github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= +github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= +github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= 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/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= 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.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/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.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= 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= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200506231410-2ff61e1afc86 h1:OfFoIUYv/me30yv7XlMy4F9RJw8DEm8WQ6QG1Ph4bH0= -gopkg.in/yaml.v3 v3.0.0-20200506231410-2ff61e1afc86/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/parser/context.go b/parser/context.go index c4752f9f..39b23cbf 100644 --- a/parser/context.go +++ b/parser/context.go @@ -3,17 +3,11 @@ package parser import ( "fmt" "strings" - - "github.com/goccy/go-yaml/token" ) // context context at parsing type context struct { - parent *context - idx int - size int - tokens token.Tokens - path string + path string } var pathSpecialChars = []string{ @@ -37,149 +31,19 @@ func normalizePath(path string) string { } func (c *context) withChild(path string) *context { - ctx := c.copy() - path = normalizePath(path) - ctx.path += fmt.Sprintf(".%s", path) - return ctx + ctx := *c + ctx.path = c.path + "." + normalizePath(path) + return &ctx } func (c *context) withIndex(idx uint) *context { - ctx := c.copy() - ctx.path += fmt.Sprintf("[%d]", idx) - return ctx -} - -func (c *context) copy() *context { - return &context{ - parent: c, - idx: c.idx, - size: c.size, - tokens: append(token.Tokens{}, c.tokens...), - path: c.path, - } -} - -func (c *context) next() bool { - return c.idx < c.size -} - -func (c *context) previousToken() *token.Token { - if c.idx > 0 { - return c.tokens[c.idx-1] - } - return nil + ctx := *c + ctx.path = c.path + "[" + fmt.Sprint(idx) + "]" + return &ctx } -func (c *context) insertToken(idx int, tk *token.Token) { - if c.parent != nil { - c.parent.insertToken(idx, tk) - } - if c.size < idx { - return - } - if c.size == idx { - curToken := c.tokens[c.size-1] - tk.Next = curToken - curToken.Prev = tk - - c.tokens = append(c.tokens, tk) - c.size = len(c.tokens) - return - } - - curToken := c.tokens[idx] - tk.Next = curToken - curToken.Prev = tk - - c.tokens = append(c.tokens[:idx+1], c.tokens[idx:]...) - c.tokens[idx] = tk - c.size = len(c.tokens) -} - -func (c *context) currentToken() *token.Token { - if c.idx >= c.size { - return nil - } - return c.tokens[c.idx] -} - -func (c *context) nextToken() *token.Token { - if c.idx+1 >= c.size { - return nil - } - return c.tokens[c.idx+1] -} - -func (c *context) nextNotCommentToken() *token.Token { - for i := c.idx + 1; i < c.size; i++ { - tk := c.tokens[i] - if tk.Type == token.CommentType { - continue - } - return tk - } - return nil -} - -func (c *context) afterNextNotCommentToken() *token.Token { - notCommentTokenCount := 0 - for i := c.idx + 1; i < c.size; i++ { - tk := c.tokens[i] - if tk.Type == token.CommentType { - continue - } - notCommentTokenCount++ - if notCommentTokenCount == 2 { - return tk - } - } - return nil -} - -func (c *context) isCurrentCommentToken() bool { - tk := c.currentToken() - if tk == nil { - return false - } - return tk.Type == token.CommentType -} - -func (c *context) progressIgnoreComment(num int) { - if c.parent != nil { - c.parent.progressIgnoreComment(num) - } - if c.size <= c.idx+num { - c.idx = c.size - } else { - c.idx += num - } -} - -func (c *context) progress(num int) { - if c.isCurrentCommentToken() { - return - } - c.progressIgnoreComment(num) -} - -func newContext(tokens token.Tokens, mode Mode) *context { - filteredTokens := []*token.Token{} - if mode&ParseComments != 0 { - filteredTokens = tokens - } else { - for _, tk := range tokens { - if tk.Type == token.CommentType { - continue - } - // keep prev/next reference between tokens containing comments - // https://github.com/goccy/go-yaml/issues/254 - filteredTokens = append(filteredTokens, tk) - } - } +func newContext() *context { return &context{ - idx: 0, - size: len(filteredTokens), - tokens: token.Tokens(filteredTokens), - path: "$", + path: "$", } } diff --git a/parser/parser.go b/parser/parser.go index b59f2e1a..2179a9cd 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -11,20 +11,142 @@ import ( "github.com/goccy/go-yaml/token" ) -type parser struct{} +type parser struct { + idx int + size int + tokens token.Tokens +} + +func newParser(tokens token.Tokens, mode Mode) *parser { + filteredTokens := []*token.Token{} + if mode&ParseComments != 0 { + filteredTokens = tokens + } else { + for _, tk := range tokens { + if tk.Type == token.CommentType { + continue + } + // keep prev/next reference between tokens containing comments + // https://github.com/goccy/go-yaml/issues/254 + filteredTokens = append(filteredTokens, tk) + } + } + return &parser{ + idx: 0, + size: len(filteredTokens), + tokens: token.Tokens(filteredTokens), + } +} + +func (p *parser) next() bool { + return p.idx < p.size +} + +func (p *parser) previousToken() *token.Token { + if p.idx > 0 { + return p.tokens[p.idx-1] + } + return nil +} + +func (p *parser) insertToken(idx int, tk *token.Token) { + if p.size < idx { + return + } + if p.size == idx { + curToken := p.tokens[p.size-1] + tk.Next = curToken + curToken.Prev = tk + + p.tokens = append(p.tokens, tk) + p.size = len(p.tokens) + return + } + + curToken := p.tokens[idx] + tk.Next = curToken + curToken.Prev = tk + + p.tokens = append(p.tokens[:idx+1], p.tokens[idx:]...) + p.tokens[idx] = tk + p.size = len(p.tokens) +} + +func (p *parser) currentToken() *token.Token { + if p.idx >= p.size { + return nil + } + return p.tokens[p.idx] +} + +func (p *parser) nextToken() *token.Token { + if p.idx+1 >= p.size { + return nil + } + return p.tokens[p.idx+1] +} + +func (p *parser) nextNotCommentToken() *token.Token { + for i := p.idx + 1; i < p.size; i++ { + tk := p.tokens[i] + if tk.Type == token.CommentType { + continue + } + return tk + } + return nil +} + +func (p *parser) afterNextNotCommentToken() *token.Token { + notCommentTokenCount := 0 + for i := p.idx + 1; i < p.size; i++ { + tk := p.tokens[i] + if tk.Type == token.CommentType { + continue + } + notCommentTokenCount++ + if notCommentTokenCount == 2 { + return tk + } + } + return nil +} + +func (p *parser) isCurrentCommentToken() bool { + tk := p.currentToken() + if tk == nil { + return false + } + return tk.Type == token.CommentType +} + +func (p *parser) progressIgnoreComment(num int) { + if p.size <= p.idx+num { + p.idx = p.size + } else { + p.idx += num + } +} + +func (p *parser) progress(num int) { + if p.isCurrentCommentToken() { + return + } + p.progressIgnoreComment(num) +} func (p *parser) parseMapping(ctx *context) (*ast.MappingNode, error) { - mapTk := ctx.currentToken() + mapTk := p.currentToken() node := ast.Mapping(mapTk, true) node.SetPath(ctx.path) - ctx.progress(1) // skip MappingStart token - for ctx.next() { - tk := ctx.currentToken() + p.progress(1) // skip MappingStart token + for p.next() { + tk := p.currentToken() if tk.Type == token.MappingEndType { node.End = tk return node, nil } else if tk.Type == token.CollectEntryType { - ctx.progress(1) + p.progress(1) continue } @@ -37,41 +159,41 @@ func (p *parser) parseMapping(ctx *context) (*ast.MappingNode, error) { return nil, errors.ErrSyntax("failed to parse flow mapping node", value.GetToken()) } node.Values = append(node.Values, mvnode) - ctx.progress(1) + p.progress(1) } return nil, errors.ErrSyntax("unterminated flow mapping", node.GetToken()) } func (p *parser) parseSequence(ctx *context) (*ast.SequenceNode, error) { - node := ast.Sequence(ctx.currentToken(), true) + node := ast.Sequence(p.currentToken(), true) node.SetPath(ctx.path) - ctx.progress(1) // skip SequenceStart token + p.progress(1) // skip SequenceStart token isFirst := true - for ctx.next() { - tk := ctx.currentToken() + for p.next() { + tk := p.currentToken() if tk.Type == token.SequenceEndType { node.End = tk break } else if tk.Type == token.CollectEntryType { - ctx.progress(1) + p.progress(1) } else if !isFirst { return nil, errors.ErrSyntax("',' or ']' must be specified", tk) } - if tk := ctx.currentToken(); tk != nil && tk.Type == token.SequenceEndType { + if tk := p.currentToken(); tk != nil && tk.Type == token.SequenceEndType { // this case is here: "[ elem, ]". // In this case, ignore the last element and break sequence parsing. node.End = tk break } - value, err := p.parseToken(ctx.withIndex(uint(len(node.Values))), ctx.currentToken()) + value, err := p.parseToken(ctx.withIndex(uint(len(node.Values))), p.currentToken()) if err != nil { return nil, err } node.Values = append(node.Values, value) - ctx.progress(1) + p.progress(1) isFirst = false } if node.End == nil || node.End.Type != token.SequenceEndType { @@ -81,10 +203,10 @@ func (p *parser) parseSequence(ctx *context) (*ast.SequenceNode, error) { } func (p *parser) parseTag(ctx *context) (*ast.TagNode, error) { - tagToken := ctx.currentToken() + tagToken := p.currentToken() node := ast.Tag(tagToken) node.SetPath(ctx.path) - ctx.progress(1) // skip tag token + p.progress(1) // skip tag token var ( value ast.Node err error @@ -99,18 +221,18 @@ func (p *parser) parseTag(ctx *context) (*ast.TagNode, error) { token.BinaryTag, token.TimestampTag, token.NullTag: - typ := ctx.currentToken().Type + typ := p.currentToken().Type if typ == token.LiteralType || typ == token.FoldedType { value, err = p.parseLiteral(ctx) } else { - value = p.parseScalarValue(ctx.currentToken()) + value = p.parseScalarValue(p.currentToken()) } case token.SequenceTag, token.SetTag: err = errors.ErrSyntax(fmt.Sprintf("sorry, currently not supported %s tag", tagToken.Value), tagToken) default: // custom tag - value, err = p.parseToken(ctx, ctx.currentToken()) + value, err = p.parseToken(ctx, p.currentToken()) } if err != nil { return nil, err @@ -163,10 +285,10 @@ func (p *parser) parseMapValue(ctx *context, key ast.MapKeyNode, colonToken *tok } func (p *parser) createMapValueNode(ctx *context, key ast.MapKeyNode, colonToken *token.Token) (ast.Node, error) { - tk := ctx.currentToken() + tk := p.currentToken() if tk == nil { nullToken := p.createNullToken(colonToken) - ctx.insertToken(ctx.idx, nullToken) + p.insertToken(p.idx, nullToken) return ast.Null(nullToken), nil } else if tk.Type == token.CollectEntryType { // implicit null value. @@ -178,7 +300,7 @@ func (p *parser) createMapValueNode(ctx *context, key ast.MapKeyNode, colonToken if comment != nil { comment.SetPath(ctx.withChild(key.GetToken().Value).path) } - tk = ctx.currentToken() + tk = p.currentToken() } if tk.Position.Column == key.GetToken().Position.Column && tk.Type == token.StringType { // in this case, @@ -187,7 +309,7 @@ func (p *parser) createMapValueNode(ctx *context, key ast.MapKeyNode, colonToken // next nullToken := p.createNullToken(colonToken) - ctx.insertToken(ctx.idx, nullToken) + p.insertToken(p.idx, nullToken) nullNode := ast.Null(nullToken) if comment != nil { @@ -212,7 +334,7 @@ func (p *parser) createMapValueNode(ctx *context, key ast.MapKeyNode, colonToken // key: // next nullToken := p.createNullToken(colonToken) - ctx.insertToken(ctx.idx, nullToken) + p.insertToken(p.idx, nullToken) nullNode := ast.Null(nullToken) if comment != nil { _ = nullNode.SetComment(comment) @@ -220,7 +342,7 @@ func (p *parser) createMapValueNode(ctx *context, key ast.MapKeyNode, colonToken return nullNode, nil } - value, err := p.parseToken(ctx, ctx.currentToken()) + value, err := p.parseToken(ctx, p.currentToken()) if err != nil { return nil, err } @@ -243,7 +365,7 @@ func (p *parser) validateMapValue(ctx *context, key, value ast.Node) error { if value.Type() != ast.StringType { return nil } - ntk := ctx.nextToken() + ntk := p.nextToken() if ntk == nil || (ntk.Type != token.MappingValueType && ntk.Type != token.SequenceEntryType) { return errors.ErrSyntax("could not find expected ':' token", valueTk) } @@ -260,19 +382,19 @@ func (p *parser) parseMappingValue(ctx *context) (ast.Node, error) { if err := p.validateMapKey(key.GetToken()); err != nil { return nil, err } - ctx.progress(1) // progress to mapping value token - tk := ctx.currentToken() // get mapping value token + p.progress(1) // progress to mapping value token + tk := p.currentToken() // get mapping value token if tk == nil { return nil, errors.ErrSyntax("unexpected map", key.GetToken()) } - ctx.progress(1) // progress to value token + p.progress(1) // progress to value token if err := p.setSameLineCommentIfExists(ctx.withChild(keyText), key); err != nil { return nil, err } if key.GetComment() != nil { // if current token is comment, GetComment() is not nil. // then progress to value token - ctx.progressIgnoreComment(1) + p.progressIgnoreComment(1) } value, err := p.parseMapValue(ctx.withChild(keyText), key, tk) @@ -288,8 +410,8 @@ func (p *parser) parseMappingValue(ctx *context) (ast.Node, error) { node := ast.Mapping(tk, false, mvnode) node.SetPath(ctx.withChild(keyText).path) - ntk := ctx.nextNotCommentToken() - antk := ctx.afterNextNotCommentToken() + ntk := p.nextNotCommentToken() + antk := p.afterNextNotCommentToken() for ntk != nil && ntk.Position.Column == key.GetToken().Position.Column { if ntk.Type == token.DocumentHeaderType || ntk.Type == token.DocumentEndType { break @@ -300,8 +422,8 @@ func (p *parser) parseMappingValue(ctx *context) (ast.Node, error) { if antk.Type != token.MappingValueType { return nil, errors.ErrSyntax("required ':' and map value", antk) } - ctx.progressIgnoreComment(1) - value, err := p.parseToken(ctx, ctx.currentToken()) + p.progressIgnoreComment(1) + value, err := p.parseToken(ctx, p.currentToken()) if err != nil { return nil, err } @@ -322,12 +444,12 @@ func (p *parser) parseMappingValue(ctx *context) (ast.Node, error) { default: return nil, fmt.Errorf("failed to parse mapping value node node is %s", value.Type()) } - ntk = ctx.nextNotCommentToken() - antk = ctx.afterNextNotCommentToken() + ntk = p.nextNotCommentToken() + antk = p.afterNextNotCommentToken() } if len(node.Values) == 1 { mapKeyCol := mvnode.Key.GetToken().Position.Column - commentTk := ctx.nextToken() + commentTk := p.nextToken() if commentTk != nil && commentTk.Type == token.CommentType && mapKeyCol <= commentTk.Position.Column { // If the comment is in the same or deeper column as the last element column in map value, // treat it as a footer comment for the last element. @@ -337,7 +459,7 @@ func (p *parser) parseMappingValue(ctx *context) (ast.Node, error) { return mvnode, nil } mapCol := node.GetToken().Position.Column - commentTk := ctx.nextToken() + commentTk := p.nextToken() if commentTk != nil && commentTk.Type == token.CommentType && mapCol <= commentTk.Position.Column { // If the comment is in the same or deeper column as the last element column in map value, // treat it as a footer comment for the last element. @@ -348,25 +470,25 @@ func (p *parser) parseMappingValue(ctx *context) (ast.Node, error) { } func (p *parser) parseSequenceEntry(ctx *context) (*ast.SequenceNode, error) { - tk := ctx.currentToken() + tk := p.currentToken() sequenceNode := ast.Sequence(tk, false) sequenceNode.SetPath(ctx.path) curColumn := tk.Position.Column for tk.Type == token.SequenceEntryType { - ctx.progress(1) // skip sequence token - tk = ctx.currentToken() + p.progress(1) // skip sequence token + tk = p.currentToken() if tk == nil { - return nil, errors.ErrSyntax("empty sequence value", ctx.previousToken()) + return nil, errors.ErrSyntax("empty sequence value", p.previousToken()) } var comment *ast.CommentGroupNode if tk.Type == token.CommentType { comment = p.parseCommentOnly(ctx) - tk = ctx.currentToken() + tk = p.currentToken() if tk.Type == token.SequenceEntryType { - ctx.progress(1) // skip sequence token + p.progress(1) // skip sequence token } } - value, err := p.parseToken(ctx.withIndex(uint(len(sequenceNode.Values))), ctx.currentToken()) + value, err := p.parseToken(ctx.withIndex(uint(len(sequenceNode.Values))), p.currentToken()) if err != nil { return nil, err } @@ -377,7 +499,7 @@ func (p *parser) parseSequenceEntry(ctx *context) (*ast.SequenceNode, error) { sequenceNode.ValueHeadComments = append(sequenceNode.ValueHeadComments, nil) } sequenceNode.Values = append(sequenceNode.Values, value) - tk = ctx.nextNotCommentToken() + tk = p.nextNotCommentToken() if tk == nil { break } @@ -387,9 +509,9 @@ func (p *parser) parseSequenceEntry(ctx *context) (*ast.SequenceNode, error) { if tk.Position.Column != curColumn { break } - ctx.progressIgnoreComment(1) + p.progressIgnoreComment(1) } - commentTk := ctx.nextToken() + commentTk := p.nextToken() if commentTk != nil && commentTk.Type == token.CommentType && curColumn <= commentTk.Position.Column { // If the comment is in the same or deeper column as the last element column in sequence value, // treat it as a footer comment for the last element. @@ -400,25 +522,25 @@ func (p *parser) parseSequenceEntry(ctx *context) (*ast.SequenceNode, error) { } func (p *parser) parseAnchor(ctx *context) (*ast.AnchorNode, error) { - tk := ctx.currentToken() + tk := p.currentToken() anchor := ast.Anchor(tk) anchor.SetPath(ctx.path) - ntk := ctx.nextToken() + ntk := p.nextToken() if ntk == nil { return nil, errors.ErrSyntax("unexpected anchor. anchor name is undefined", tk) } - ctx.progress(1) // skip anchor token - name, err := p.parseToken(ctx, ctx.currentToken()) + p.progress(1) // skip anchor token + name, err := p.parseToken(ctx, p.currentToken()) if err != nil { return nil, err } anchor.Name = name - ntk = ctx.nextToken() + ntk = p.nextToken() if ntk == nil { - return nil, errors.ErrSyntax("unexpected anchor. anchor value is undefined", ctx.currentToken()) + return nil, errors.ErrSyntax("unexpected anchor. anchor value is undefined", p.currentToken()) } - ctx.progress(1) - value, err := p.parseToken(ctx, ctx.currentToken()) + p.progress(1) + value, err := p.parseToken(ctx, p.currentToken()) if err != nil { return nil, err } @@ -427,15 +549,15 @@ func (p *parser) parseAnchor(ctx *context) (*ast.AnchorNode, error) { } func (p *parser) parseAlias(ctx *context) (*ast.AliasNode, error) { - tk := ctx.currentToken() + tk := p.currentToken() alias := ast.Alias(tk) alias.SetPath(ctx.path) - ntk := ctx.nextToken() + ntk := p.nextToken() if ntk == nil { return nil, errors.ErrSyntax("unexpected alias. alias name is undefined", tk) } - ctx.progress(1) // skip alias token - name, err := p.parseToken(ctx, ctx.currentToken()) + p.progress(1) // skip alias token + name, err := p.parseToken(ctx, p.currentToken()) if err != nil { return nil, err } @@ -444,7 +566,7 @@ func (p *parser) parseAlias(ctx *context) (*ast.AliasNode, error) { } func (p *parser) parseMapKey(ctx *context) (ast.MapKeyNode, error) { - tk := ctx.currentToken() + tk := p.currentToken() if value := p.parseScalarValue(tk); value != nil { return value, nil } @@ -473,8 +595,8 @@ func (p *parser) parseScalarValueWithComment(ctx *context, tk *token.Token) (ast return nil, nil } node.SetPath(ctx.path) - if p.isSameLineComment(ctx.nextToken(), node) { - ctx.progress(1) + if p.isSameLineComment(p.nextToken(), node) { + p.progress(1) if err := p.setSameLineCommentIfExists(ctx, node); err != nil { return nil, err } @@ -507,31 +629,31 @@ func (p *parser) parseScalarValue(tk *token.Token) ast.ScalarNode { } func (p *parser) parseDirective(ctx *context) (*ast.DirectiveNode, error) { - node := ast.Directive(ctx.currentToken()) - ctx.progress(1) // skip directive token - value, err := p.parseToken(ctx, ctx.currentToken()) + node := ast.Directive(p.currentToken()) + p.progress(1) // skip directive token + value, err := p.parseToken(ctx, p.currentToken()) if err != nil { return nil, err } node.Value = value - ctx.progress(1) - tk := ctx.currentToken() + p.progress(1) + tk := p.currentToken() if tk == nil { // Since current token is nil, use the previous token to specify // the syntax error location. - return nil, errors.ErrSyntax("unexpected directive value. document not started", ctx.previousToken()) + return nil, errors.ErrSyntax("unexpected directive value. document not started", p.previousToken()) } if tk.Type != token.DocumentHeaderType { - return nil, errors.ErrSyntax("unexpected directive value. document not started", ctx.currentToken()) + return nil, errors.ErrSyntax("unexpected directive value. document not started", p.currentToken()) } return node, nil } func (p *parser) parseLiteral(ctx *context) (*ast.LiteralNode, error) { - node := ast.Literal(ctx.currentToken()) - ctx.progress(1) // skip literal/folded token + node := ast.Literal(p.currentToken()) + p.progress(1) // skip literal/folded token - tk := ctx.currentToken() + tk := p.currentToken() var comment *ast.CommentGroupNode if tk.Type == token.CommentType { comment = p.parseCommentOnly(ctx) @@ -539,7 +661,7 @@ func (p *parser) parseLiteral(ctx *context) (*ast.LiteralNode, error) { if err := node.SetComment(comment); err != nil { return nil, err } - tk = ctx.currentToken() + tk = p.currentToken() } value, err := p.parseToken(ctx, tk) if err != nil { @@ -564,7 +686,7 @@ func (p *parser) isSameLineComment(tk *token.Token, node ast.Node) bool { } func (p *parser) setSameLineCommentIfExists(ctx *context, node ast.Node) error { - tk := ctx.currentToken() + tk := p.currentToken() if !p.isSameLineComment(tk, node) { return nil } @@ -577,16 +699,16 @@ func (p *parser) setSameLineCommentIfExists(ctx *context, node ast.Node) error { } func (p *parser) parseDocument(ctx *context) (*ast.DocumentNode, error) { - startTk := ctx.currentToken() - ctx.progress(1) // skip document header token - body, err := p.parseToken(ctx, ctx.currentToken()) + startTk := p.currentToken() + p.progress(1) // skip document header token + body, err := p.parseToken(ctx, p.currentToken()) if err != nil { return nil, err } node := ast.Document(startTk, body) - if ntk := ctx.nextToken(); ntk != nil && ntk.Type == token.DocumentEndType { + if ntk := p.nextToken(); ntk != nil && ntk.Type == token.DocumentEndType { node.End = ntk - ctx.progress(1) + p.progress(1) } return node, nil } @@ -594,7 +716,7 @@ func (p *parser) parseDocument(ctx *context) (*ast.DocumentNode, error) { func (p *parser) parseCommentOnly(ctx *context) *ast.CommentGroupNode { commentTokens := []*token.Token{} for { - tk := ctx.currentToken() + tk := p.currentToken() if tk == nil { break } @@ -602,7 +724,7 @@ func (p *parser) parseCommentOnly(ctx *context) *ast.CommentGroupNode { break } commentTokens = append(commentTokens, tk) - ctx.progressIgnoreComment(1) // skip comment token + p.progressIgnoreComment(1) // skip comment token } return ast.CommentGroup(commentTokens) } @@ -610,10 +732,10 @@ func (p *parser) parseCommentOnly(ctx *context) *ast.CommentGroupNode { func (p *parser) parseFootComment(ctx *context, col int) *ast.CommentGroupNode { commentTokens := []*token.Token{} for { - ctx.progressIgnoreComment(1) - commentTokens = append(commentTokens, ctx.currentToken()) + p.progressIgnoreComment(1) + commentTokens = append(commentTokens, p.currentToken()) - nextTk := ctx.nextToken() + nextTk := p.nextToken() if nextTk == nil { break } @@ -629,7 +751,7 @@ func (p *parser) parseFootComment(ctx *context, col int) *ast.CommentGroupNode { func (p *parser) parseComment(ctx *context) (ast.Node, error) { group := p.parseCommentOnly(ctx) - node, err := p.parseToken(ctx, ctx.currentToken()) + node, err := p.parseToken(ctx, p.currentToken()) if err != nil { return nil, err } @@ -644,11 +766,11 @@ func (p *parser) parseComment(ctx *context) (ast.Node, error) { } func (p *parser) parseMappingKey(ctx *context) (*ast.MappingKeyNode, error) { - keyTk := ctx.currentToken() + keyTk := p.currentToken() node := ast.MappingKey(keyTk) node.SetPath(ctx.path) - ctx.progress(1) // skip mapping key token - value, err := p.parseToken(ctx.withChild(keyTk.Value), ctx.currentToken()) + p.progress(1) // skip mapping key token + value, err := p.parseToken(ctx.withChild(keyTk.Value), p.currentToken()) if err != nil { return nil, err } @@ -713,15 +835,14 @@ func (p *parser) createNodeFromToken(ctx *context, tk *token.Token) (ast.Node, e return nil, nil } -func (p *parser) parse(tokens token.Tokens, mode Mode) (*ast.File, error) { - ctx := newContext(tokens, mode) +func (p *parser) parse(ctx *context) (*ast.File, error) { file := &ast.File{Docs: []*ast.DocumentNode{}} - for ctx.next() { - node, err := p.parseToken(ctx, ctx.currentToken()) + for p.next() { + node, err := p.parseToken(ctx, p.currentToken()) if err != nil { return nil, err } - ctx.progressIgnoreComment(1) + p.progressIgnoreComment(1) if node == nil { continue } @@ -755,8 +876,7 @@ func Parse(tokens token.Tokens, mode Mode) (*ast.File, error) { if tk := tokens.InvalidToken(); tk != nil { return nil, errors.ErrSyntax("found invalid token", tk) } - var p parser - f, err := p.parse(tokens, mode) + f, err := newParser(tokens, mode).parse(newContext()) if err != nil { return nil, err }