Discussion/help for any of my projects, such as gometalinter, kingpin, voluptuous, EntityX, etc.
alecthomas on v0.8.0
Add hermit (compare)
alecthomas on v0.8.0
Add hermit (compare)
alecthomas on v0.8.0
Add hermit (compare)
alecthomas on v0.8.0
I'm having a curious problem with pytest-voluptuous==1.1.0 (and voluptuous==0.11.5). Below timing.1.source has value "create," and the actual value is "create," but get assertion error and this doesn't really compute?
I should point out that timing.0 is fine. timing.1.duration_in_ms is also fine. Just timing.1.source that's failing.
v1_base_url = 'http://127.0.0.1:64387/v1'
def test_customers_create(v1_base_url):
url = v1_base_url + "/customers"
data = {
"first_name": "john",
"last_name": "doe",
"email": "johndoe@example.com",
"phone_number": "04555555555"
}
r = requests.post(url, json=data)
assert r.status_code == 200
> assert r.json() == S(
{
"success": True,
"timing": [
{"duration_in_ms": int, "source": "backend_api_call"},
{"duration_in_ms": int, "source": "create"}
],
"messages": ["Customer created", "OK"],
"response": {"unnecessary": "crap"}
)
E AssertionError: assert failed to validation error(s):
E - timing.1.source: not a valid value (actual: 'create')
{
"success": true,
"response": { "unnecessary": "crap" },
"timing": [
{
"duration_in_ms": 629,
"source": "backend_api_call"
},
{
"duration_in_ms": 655,
"source": "create"
}
],
"messages": [
"Customer created",
"OK"
],
"time": "2019-08-12T03:53:41.070455Z"
}
{...}
matched, but then failed on a sub-key
{...}
) it will not exit
myapp -a b -c
, b -c
are non-options
participle.Capture
interface on a custom type
type Time time.Time
func (t *Time) Capture(tokens []string) error {
s, err := time.Parse("...", tokens[0])
...
*t = s
return nil
}
$ go build -i -v -x
WORK=/tmp/go-build822795550
mkdir -p $WORK/b017/
mkdir -p /home/oceanfish81/go/pkg/gccgo_linux_amd64/github.com/alecthomas/
cp /home/oceanfish81/.cache/go-build/3f/3f17f09c67a788726b59d58fcca2958f8e89f05f49c82be2d1c6e75183bf139a-d /home/oceanfish81/go/pkg/gccgo_linux_amd64/github.com/alecthomas/libunits.a
mkdir -p $WORK/b020/
mkdir -p /home/oceanfish81/go/pkg/gccgo_linux_amd64/github.com/nicksnyder/go-i18n/i18n/
cp /home/oceanfish81/.cache/go-build/1d/1d82d5034089a023b328cb96570d592006677007d9489fa77d5a6a64c584b247-d /home/oceanfish81/go/pkg/gccgo_linux_amd64/github.com/nicksnyder/go-i18n/i18n/liblanguage.a
rm -r $WORK/b017/
rm -r $WORK/b020/
mkdir -p $WORK/b022/
cp /home/oceanfish81/.cache/go-build/00/007e3ade50871872acfa250f6dcd292a0f846c61c8739ab18f79bccfcea98082-d /home/oceanfish81/go/pkg/gccgo_linux_amd64/github.com/nicksnyder/go-i18n/i18n/libtranslation.a
rm -r $WORK/b022/
mkdir -p $WORK/b025/
mkdir -p /home/oceanfish81/go/pkg/gccgo_linux_amd64/github.com/pelletier/
cp /home/oceanfish81/.cache/go-build/1e/1e1e4b85589ef24d39f9fc768b9bc7f8719ca407fca7c59fe6f650ae7bc96d43-d /home/oceanfish81/go/pkg/gccgo_linux_amd64/github.com/pelletier/libgo-toml.a
mkdir -p $WORK/b035/
mkdir -p /home/oceanfish81/go/pkg/gccgo_linux_amd64/gopkg.in/
cp /home/oceanfish81/.cache/go-build/17/17b6e6437480a8d8489dcaf96914181618b1641928828f8227fa59e5c2b5fc0b-d /home/oceanfish81/go/pkg/gccgo_linux_amd64/gopkg.in/libyaml.v2.a
rm -r $WORK/b025/
rm -r $WORK/b035/
mkdir -p $WORK/b019/
cp /home/oceanfish81/.cache/go-build/cf/cf0ac62a87259aadf849489ca255fad6bf03bf9a1a31bb4df5dcf87ce8232e45-d /home/oceanfish81/go/pkg/gccgo_linux_amd64/github.com/nicksnyder/go-i18n/i18n/libbundle.a
rm -r $WORK/b019/
mkdir -p $WORK/b018/
mkdir -p /home/oceanfish81/go/pkg/gccgo_linux_amd64/github.com/nicksnyder/go-i18n/
cp /home/oceanfish81/.cache/go-build/26/267db29519d8a5d352c042db18c08aa7a0f3e408c4b8720cc52aa9195c0951ab-d /home/oceanfish81/go/pkg/gccgo_linuxamd64/github.com/nicksnyder/go-i18n/libi18n.a
rm -r $WORK/b018/
/home/oceanfish81/go_projects/gometalinter
mkdir -p $WORK/b001/
cd $WORK
/home/oceanfish81/gollvm_dist/bin/llvm-goc -fgo-importcfg=/dev/null -c -x c - -o /dev/null || true
mkdir -p $WORK/b001/importcfgroot/github.com/google
ln -s /home/oceanfish81/go/pkg/gccgo_linux_amd64/github.com/google/libshlex.a $WORK/b001/importcfgroot/github.com/google/libshlex.a
mkdir -p $WORK/b001/importcfgroot/gopkg.in/alecthomas
ln -s /home/oceanfish81/go/pkg/gccgo_linux_amd64/gopkg.in/alecthomas/libkingpin.v3-unstable.a $WORK/b001/importcfgroot/gopkg.in/alecthomas/libkingpin.v3-unstable.a
cd /home/oceanfish81/go_projects/gometalinter
/home/oceanfish81/gollvmdist/bin/llvm-goc -c -O2 -g -m64 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -fgo-relative-import-path=/home/oceanfish81/go_projects/gometalinter -o $WORK/b001/go.o -I $WORK/b001/importcfgroot ./aggregate.go ./checkstyle.go ./config.go ./directives.go ./execute.go ./issue.go ./linters.go ./main.go ./partition.go ./stringset.go
./main.go:36:95: error: argument 1 has incompatible type (different parameter types)
./main.go:38:101: error: argument 1 has incompatible type (different parameter types)
./main.go:39:100: error: argument 1 has incompatible type (different parameter types)
./main.go:40:84: error: argument 1 has incompatible type (different parameter types)
./main.go:43:57: error: argument 1 has incompatible type (different parameter types)
./main.go:44:55: error: argument 1 has incompatible type (different parameter types)
./main.go:200:13: error: argument 1 has incompatible type (different parameter types)
@ https://github.com/alecthomas/participle
Hi
I appreciate the work on github.com/alecthomas/participle
library :thumbsup: !
I'm writing a dynamic parser/lexer for EBNF grammar. Currently, I'm trying to use Go EBNF grammar that I derived from Go specification HTML (https://gist.github.com/vellotis/d59980f924309e0258222f26c02218fb). For parsing EBNF grammar I used Go's https://github.com/golang/exp/blob/master/ebnf/parser.go plus a bit of instrumentation of the grammar productions so it would fulfill my needs.
I have almost finished with my 1st working version of the lexer as well. But with a few complications with the Go's EBNF grammar. Probably the problem is how I handle which of the EBNF alternations should be resolved if multiple of them return a value.
Example:
Go's short variable declaration as inputsimple := "value"
type testableShortVarDecl struct {
ShortVarDecl `@@ term`
}
// Collect instrumented version of github.com/golang/exp/ebnf/parser.go returned grammar
grammar := GoGrammar()
// Putting together my lexer with a starting production of "StatementList"
lexerDefinition, err := NewLexer(grammar, ebnf.InitialProduction("StatementList"))
require.NoError(t, err)
// Build a participle parser
parser, err := participle.Build(&testableShortVarDecl{},
participle.Lexer(lexerDefinition),
participle.Elide("ignored"))
require.NoError(t, err)
shortVarDecl := &testableShortVarDecl{}
err = parser.ParseString("", `single := "value"`, shortVarDecl)
assert.NoError(t, err)
The problem is that for production "SimpleStmt" it finds a matching lexical token for ExpressionStmt -> Expression -> UnaryExpr -> PrimaryExpr -> Operand -> OperandName -> identifier
(= "simple") and resolves the whole alternation and doesn't reach to ShortVarDecl
at all.
Does any of you have any expertise in EBNF and picking a resolving alternate element when many of them resolve?
Or could you point me to another discussion board? I know my last option is StackOverflow, but I would like to have a discussion, not just a solution at first.
BR