Franck Pommereau

s/SNAKES/ZINC/gi

Showing 38 changed files with 202 additions and 202 deletions
package snk
package zn
import "os"
import "fmt"
......
package snk
package zn
import "fmt"
import "bytes"
......@@ -58,21 +58,21 @@ func (self Marking) Has (p string) bool {
return self.d.Has(place{p})
}
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 3, 4)
//... b := a.Copy()
//... b.Set("p2", 2, 3, 4, 5)
//... a.Hash() != b.Hash()
//=== true
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 3, 4)
//... b := a.Copy()
//... b.Set("p2")
//... a.Hash() == b.Hash()
//=== true
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 3, 4)
//... b := a.Copy()
//... b.Set("p2", 2, 3, 4, 5)
......@@ -80,11 +80,11 @@ func (self Marking) Has (p string) bool {
//... a.Hash() == b.Hash()
//=== true
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 0)
//... a.Set("p2", 2, 1, 3)
//... a.Set("p3", 5, 6, 2)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p2", 1, 3, 2)
//... b.Set("p3", 2, 5, 6)
//... b.Set("p1", 2, 0, 1)
......@@ -105,7 +105,7 @@ func (self Marking) Eq (other Marking) bool {
return true
}
//+++ snk.MakeMarking().Eq(snk.MakeMarking())
//+++ zn.MakeMarking().Eq(zn.MakeMarking())
func (self Marking) Set (p string, tokens ...interface{}) {
if len(tokens) == 0 {
......@@ -116,7 +116,7 @@ func (self Marking) Set (p string, tokens ...interface{}) {
}
}
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... a
......@@ -125,7 +125,7 @@ func (self Marking) Set (p string, tokens ...interface{}) {
//>>> list(sorted(m["p1"])) == [1, 2, 2, 3]
//>>> list(sorted(m["p2"])) == [1, 1, 4]
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2)
//... a.Set("p1")
//... a.Get("p1").Empty()
......@@ -140,11 +140,11 @@ func (self Marking) Update (p string, tokens Mset) {
}
}
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Update("p1", snk.MakeMset(1, 2, 2, 3))
//... a.Update("p2", snk.MakeMset(1, 1, 4))
//... b := snk.MakeMarking()
//... a.Update("p1", zn.MakeMset(1, 2, 2, 3))
//... a.Update("p2", zn.MakeMset(1, 1, 4))
//... b := zn.MakeMarking()
//... b.Set("p1", 1, 2, 2, 3, 1, 2, 2, 3)
//... b.Set("p2", 1, 1, 4)
//... a.Eq(b)
......@@ -158,46 +158,46 @@ func (self Marking) Copy () Marking {
return copy
}
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p1", 1, 2, 2, 3)
//... b.Set("p2", 1, 1, 4)
//... a.Eq(b)
//=== true
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p1", 1, 2, 2, 3)
//... b.Set("p3", 1, 1, 4)
//... a.Eq(b)
//=== false
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p1", 1, 2, 2, 3)
//... a.Eq(b)
//=== false
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p1", 1, 2, 2, 3)
//... b.Set("p2", 1, 1, 4)
//... b.Set("p3", 1)
//... a.Eq(b)
//=== false
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p1", 1, 2, 2, 3)
//... b.Set("p2", 1, 4)
//... a.Eq(b)
......@@ -207,22 +207,22 @@ func (self Marking) Get (p string) Mset {
return (*(self.d.Fetch(place{p}, MakeMset()))).(Mset)
}
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... a.Get("p1").Eq(snk.MakeMset(1, 2, 2, 3))
//... a.Get("p1").Eq(zn.MakeMset(1, 2, 2, 3))
//=== true
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... a.Get("p2").Eq(snk.MakeMset(1, 1, 4))
//... a.Get("p2").Eq(zn.MakeMset(1, 1, 4))
//=== true
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... a.Get("p3").Eq(snk.MakeMset())
//... a.Get("p3").Eq(zn.MakeMset())
//=== true
func (self Marking) NotEmpty (places ...string) bool {
......@@ -234,25 +234,25 @@ func (self Marking) NotEmpty (places ...string) bool {
return true
}
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... a.NotEmpty("p1")
//=== true
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... a.NotEmpty("p1", "p2")
//=== true
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... a.NotEmpty("p1", "p2", "p3")
//=== false
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... a.NotEmpty("p3")
......@@ -265,14 +265,14 @@ func (self Marking) Add (other Marking) Marking {
return self
}
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p2", 2, 4)
//... b.Set("p3", 1)
//... a.Add(b)
//... c := snk.MakeMarking()
//... c := zn.MakeMarking()
//... c.Set("p1", 1, 2, 2, 3)
//... c.Set("p2", 1, 1, 2, 4, 4)
//... c.Set("p3", 1)
......@@ -291,14 +291,14 @@ func (self Marking) Sub (other Marking) Marking {
return self
}
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p1", 1, 2, 2, 3)
//... b.Set("p2", 2, 4)
//... b.Set("p3", 1)
//... c := snk.MakeMarking()
//... c := zn.MakeMarking()
//... c.Set("p2", 1, 1)
//... a.Sub(b)
//... a.Eq(c)
......@@ -313,45 +313,45 @@ func (self Marking) Geq (other Marking) bool {
return true
}
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p1", 1, 2, 2, 3)
//... b.Set("p2", 1, 1, 4)
//... a.Geq(b)
//=== true
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p1", 1, 2, 2, 3)
//... b.Set("p2", 1)
//... a.Geq(b)
//=== true
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p1", 1, 2, 2, 3)
//... a.Geq(b)
//=== true
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p1", 1, 2, 2, 3)
//... b.Set("p2", 1, 1, 1, 1)
//... a.Geq(b)
//=== false
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... b := snk.MakeMarking()
//... b := zn.MakeMarking()
//... b.Set("p1", 1, 2, 2, 3)
//... b.Set("p2", 1, 1, 4)
//... b.Set("p3", 1)
......@@ -385,7 +385,7 @@ func (self Marking) Iter () (MarkingIterator, *string, *Mset) {
}
}
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... fmt.Print("{")
......@@ -394,7 +394,7 @@ func (self Marking) Iter () (MarkingIterator, *string, *Mset) {
//... nil
//>>> eval(out) == {1, 2, 3}
//### a := snk.MakeMarking()
//### a := zn.MakeMarking()
//... a.Set("p1", 1, 2, 2, 3)
//... a.Set("p2", 1, 1, 4)
//... fmt.Print("{")
......
package snk
package zn
import "fmt"
import "bytes"
......@@ -49,8 +49,8 @@ func h2i (v *dicts.Hashable) *interface{} {
return (*v).(AsString).val
}
//+++ snk.MakeMset(1, 2, 2, 3, 3, 3).Hash() == snk.MakeMset(3, 3, 3, 2, 2, 1).Hash()
//+++ snk.MakeMset(1, 2, 2, 3, 3, 3).Hash() == snk.MakeMset(3, 2, 1, 3, 2, 3).Hash()
//+++ zn.MakeMset(1, 2, 2, 3, 3, 3).Hash() == zn.MakeMset(3, 3, 3, 2, 2, 1).Hash()
//+++ zn.MakeMset(1, 2, 2, 3, 3, 3).Hash() == zn.MakeMset(3, 2, 1, 3, 2, 3).Hash()
func MakeMset (values ...interface{}) Mset {
dict := dicts.MakeDict()
......@@ -77,12 +77,12 @@ func (self Mset) Eq (other Mset) bool {
return true
}
//+++ snk.MakeMset().Eq(snk.MakeMset())
//--- snk.MakeMset().Eq(snk.MakeMset(1, 2, 3))
//--- snk.MakeMset().Eq(snk.MakeMset(1, 1, 1))
//+++ snk.MakeMset(1, 1, 1).Eq(snk.MakeMset(1, 1, 1))
//--- snk.MakeMset(1, 1, 3).Eq(snk.MakeMset(1, 1, 1))
//--- snk.MakeMset(1, 1, 1).Eq(snk.MakeMset(2, 2, 2))
//+++ zn.MakeMset().Eq(zn.MakeMset())
//--- zn.MakeMset().Eq(zn.MakeMset(1, 2, 3))
//--- zn.MakeMset().Eq(zn.MakeMset(1, 1, 1))
//+++ zn.MakeMset(1, 1, 1).Eq(zn.MakeMset(1, 1, 1))
//--- zn.MakeMset(1, 1, 3).Eq(zn.MakeMset(1, 1, 1))
//--- zn.MakeMset(1, 1, 1).Eq(zn.MakeMset(2, 2, 2))
func (self Mset) Copy () Mset {
copy := MakeMset()
......@@ -92,7 +92,7 @@ func (self Mset) Copy () Mset {
return copy
}
//+++ snk.MakeMset(1, 2, 2, 3, 3, 3).Copy().Eq(snk.MakeMset(1, 2, 2, 3, 3, 3))
//+++ zn.MakeMset(1, 2, 2, 3, 3, 3).Copy().Eq(zn.MakeMset(1, 2, 2, 3, 3, 3))
func (self Mset) Len () uint64 {
count := uint64(0)
......@@ -102,8 +102,8 @@ func (self Mset) Len () uint64 {
return count
}
//+++ snk.MakeMset(1, 2, 2, 3, 3, 3).Len() == 6
//+++ snk.MakeMset().Len() == 0
//+++ zn.MakeMset(1, 2, 2, 3, 3, 3).Len() == 6
//+++ zn.MakeMset().Len() == 0
func (self Mset) Add (other Mset) Mset {
for iter, item := other.d.Iter(); item != nil; item = iter.Next() {
......@@ -113,10 +113,10 @@ func (self Mset) Add (other Mset) Mset {
return self
}
//### a := snk.MakeMset(1, 2, 3)
//... b := snk.MakeMset(2, 3, 4)
//### a := zn.MakeMset(1, 2, 3)
//... b := zn.MakeMset(2, 3, 4)
//... a.Add(b)
//... a.Eq(snk.MakeMset(1, 2, 2, 3, 3, 4))
//... a.Eq(zn.MakeMset(1, 2, 2, 3, 3, 4))
//=== true
func (self Mset) Sub (other Mset) Mset {
......@@ -132,16 +132,16 @@ func (self Mset) Sub (other Mset) Mset {
return self
}
//### a := snk.MakeMset(1, 2, 3)
//... b := snk.MakeMset(2, 3, 4)
//### a := zn.MakeMset(1, 2, 3)
//... b := zn.MakeMset(2, 3, 4)
//... a.Sub(b)
//... a.Eq(snk.MakeMset(1))
//... a.Eq(zn.MakeMset(1))
//=== true
//### a := snk.MakeMset(1, 2, 2, 3, 3, 3)
//... b := snk.MakeMset(1, 2, 3)
//### a := zn.MakeMset(1, 2, 2, 3, 3, 3)
//... b := zn.MakeMset(1, 2, 3)
//... a.Sub(b)
//... a.Eq(snk.MakeMset(2, 3, 3))
//... a.Eq(zn.MakeMset(2, 3, 3))
//=== true
func (self Mset) Geq (other Mset) bool {
......@@ -154,34 +154,34 @@ func (self Mset) Geq (other Mset) bool {
return true
}
//+++ snk.MakeMset(1, 2, 3).Geq(snk.MakeMset(1, 2, 3))
//+++ snk.MakeMset(1, 2, 3).Geq(snk.MakeMset(1, 2))
//+++ snk.MakeMset(1, 2, 2, 3).Geq(snk.MakeMset(1, 2, 3))
//+++ snk.MakeMset(1, 2, 2, 3).Geq(snk.MakeMset())
//+++ snk.MakeMset().Geq(snk.MakeMset())
//--- snk.MakeMset(1, 2, 2, 3).Geq(snk.MakeMset(1, 2, 3, 4))
//--- snk.MakeMset(1, 2, 3).Geq(snk.MakeMset(1, 2, 2, 3))
//--- snk.MakeMset().Geq(snk.MakeMset(1))
//+++ zn.MakeMset(1, 2, 3).Geq(zn.MakeMset(1, 2, 3))
//+++ zn.MakeMset(1, 2, 3).Geq(zn.MakeMset(1, 2))
//+++ zn.MakeMset(1, 2, 2, 3).Geq(zn.MakeMset(1, 2, 3))
//+++ zn.MakeMset(1, 2, 2, 3).Geq(zn.MakeMset())
//+++ zn.MakeMset().Geq(zn.MakeMset())
//--- zn.MakeMset(1, 2, 2, 3).Geq(zn.MakeMset(1, 2, 3, 4))
//--- zn.MakeMset(1, 2, 3).Geq(zn.MakeMset(1, 2, 2, 3))
//--- zn.MakeMset().Geq(zn.MakeMset(1))
func (self Mset) Empty () bool {
return self.d.Len() == 0
}
//+++ snk.MakeMset().Empty()
//+++ snk.MakeMset().Empty()
//--- snk.MakeMset(1, 2).Empty()
//+++ zn.MakeMset().Empty()
//+++ zn.MakeMset().Empty()
//--- zn.MakeMset(1, 2).Empty()
func (self Mset) Count (value interface{}) uint64 {
return (*(self.d.Fetch(i2h(value), uint64(0)))).(uint64)
}
//### snk.MakeMset(1, 2, 2, 3, 3, 3).Count(1)
//### zn.MakeMset(1, 2, 2, 3, 3, 3).Count(1)
//=== 1
//### snk.MakeMset(1, 2, 2, 3, 3, 3).Count(2)
//### zn.MakeMset(1, 2, 2, 3, 3, 3).Count(2)
//=== 2
//### snk.MakeMset(1, 2, 2, 3, 3, 3).Count(3)
//### zn.MakeMset(1, 2, 2, 3, 3, 3).Count(3)
//=== 3
type MsetIterator struct {
......@@ -223,13 +223,13 @@ func (self Mset) IterDup () (MsetIterator, *interface{}) {
return myiter, h2i(item.Key)
}
//### a := snk.MakeMset(1, 2, 2, 3, 3, 3)
//### a := zn.MakeMset(1, 2, 2, 3, 3, 3)
//... t := 0
//... for i, n := a.Iter(); n != nil; n = i.Next() { t += (*n).(int) }
//... t
//=== 6
//### a := snk.MakeMset(1, 2, 2, 3, 3, 3)
//### a := zn.MakeMset(1, 2, 2, 3, 3, 3)
//... t := 0
//... for i, n := a.IterDup(); n != nil; n = i.Next() { t += (*n).(int) }
//... t
......@@ -250,11 +250,11 @@ func (self Mset) String () string {
return buf.String()
}
//### a := snk.MakeMset(1, 2, 3)
//### a := zn.MakeMset(1, 2, 3)
//... a
//>>> list(sorted((eval(out)))) == [1, 2, 3]
//### a := snk.MakeMset(1, 2, 2, 3, 3, 3)
//### a := zn.MakeMset(1, 2, 2, 3, 3, 3)
//... a
//>>> list(sorted(eval(out))) == [1, 2, 2, 3, 3, 3]
......@@ -271,9 +271,9 @@ func (self Mset) Map (f mapfunc) Mset {
return copy
}
//### a := snk.MakeMset(1, 2, 2)
//### a := zn.MakeMset(1, 2, 2)
//... b := a.Map(func (v interface{}, n uint64) (interface{}, uint64) {return v.(int)+1, n})
//... b.Eq(snk.MakeMset(2, 3, 3))
//... b.Eq(zn.MakeMset(2, 3, 3))
//=== true
func (self Mset) ShowStructure () {
......
package snk
package zn
type Queue struct {
head uint64
......
package snk
package zn
type Set struct {
data map[uint64]*Marking
}
//*** a := snk.MakeMarking()
//*** a := zn.MakeMarking()
//*** a.Set("p1", 1)
//*** b := a.Copy()
//*** b.Set("p2", 2)
......@@ -27,18 +27,18 @@ func (self Set) NotEmpty () bool {
return len(self.data) > 0
}
//+++ snk.MakeSet().Empty()
//--- snk.MakeSet(&a).Empty()
//--- snk.MakeSet().NotEmpty()
//+++ snk.MakeSet(&a).NotEmpty()
//+++ zn.MakeSet().Empty()
//--- zn.MakeSet(&a).Empty()
//--- zn.MakeSet().NotEmpty()
//+++ zn.MakeSet(&a).NotEmpty()
func (self Set) Len () int {
return len(self.data)
}
//+++ snk.MakeSet().Len() == 0
//+++ snk.MakeSet(&a).Len() == 1
//+++ snk.MakeSet(&a, &a).Len() == 1
//+++ zn.MakeSet().Len() == 0
//+++ zn.MakeSet(&a).Len() == 1
//+++ zn.MakeSet(&a, &a).Len() == 1
func (self Set) lookup (m *Marking) (uint64, bool) {
slot := m.Hash()
......@@ -66,11 +66,11 @@ func (self *Set) AddPtr (m *Marking) {
}
}
//### s := snk.MakeSet(&a, &b)
//### s := zn.MakeSet(&a, &b)
//... s.Len()
//=== 2
//### s := snk.MakeSet(&a, &b)
//### s := zn.MakeSet(&a, &b)
//... s.Add(c)
//... s.Add(c)
//... s.Len()
......@@ -89,6 +89,6 @@ func (self Set) Has (m *Marking) bool {
return found
}
//+++ snk.MakeSet(&a, &b).Has(&a)
//+++ snk.MakeSet(&a, &b).Has(&b)
//--- snk.MakeSet(&a, &b).Has(&c)
//+++ zn.MakeSet(&a, &b).Has(&a)
//+++ zn.MakeSet(&a, &b).Has(&b)
//--- zn.MakeSet(&a, &b).Has(&c)
......
package snk
package zn
import "time"
import "fmt"
......@@ -90,7 +90,7 @@ func TestSuccIterator () {
time.Sleep(20 * time.Millisecond)
}
//### snk.TestSuccIterator()
//### zn.TestSuccIterator()
//... nil
//=== 0 1 2 3 4 finished
//=== 0 1 2 stopped
......
find snakes -name "*.ebnf" | while read EBNF
find zinc -name "*.ebnf" | while read EBNF
do
TARGET=$(dirname $EBNF)/$(basename $EBNF .ebnf)parse.py
if test "$EBNF" -nt "$TARGET"
......
import collections
from snakes.nets import Marking, mset, dot, hdict
from zinc.nets import Marking, mset, dot, hdict
event = collections.namedtuple("event", ["trans", "mode", "state"])
......
import os, os.path, subprocess
def walk(root='libs/go/src/snk') :
def walk(root='libs/go/src/zn') :
for dirpath, dirnames, filenames in os.walk(root) :
for name in filenames :
if name.endswith('.go') :
......
class SNAKESError (Exception) :
class ZINCError (Exception) :
pass
class ConstraintError (SNAKESError) :
class ConstraintError (ZINCError) :
pass
class LanguageError (SNAKESError) :
class LanguageError (ZINCError) :
pass
class TypingError (SNAKESError) :
class TypingError (ZINCError) :
pass
class ParseError (SNAKESError) :
class ParseError (ZINCError) :
def __init__ (self, msg, lno=None, cno=None, path=None) :
loc = ":".join(str(p) for p in (path, lno, cno) if p is not None)
if loc :
msg = "%s: %s" % (loc, msg)
SNAKESError.__init__(self, msg)
ZINCError.__init__(self, msg)
......
from functools import reduce
from operator import and_, or_
from itertools import chain
from snakes import ConstraintError
from snakes.data import record
from zinc import ConstraintError
from zinc.data import record
class Arc (object) :
def _nest (self, *arcs, **more) :
......
import importlib, string, collections, io, tempfile, os, os.path
from snakes import LanguageError
from zinc import LanguageError
def getlang (name) :
name = name.lower()
try :
module = importlib.import_module("snakes.compil." + name)
module = importlib.import_module("zinc.compil." + name)
except ImportError :
raise LanguageError("unsupported language %r" % name)
module.name = name
......@@ -98,7 +98,7 @@ class CompilationError (Exception) :
class Context (object) :
def __init__ (self, **attrs) :
self._ast = importlib.import_module("snakes.compil.ast")
self._ast = importlib.import_module("zinc.compil.ast")
self._fields = list(attrs)
for name, value in attrs.items() :
setattr(self, name, value)
......
import snakes.io.snk, sys
import zinc.io.zn, sys
from . import build, CompilationError
net = snakes.io.snk.load(open(sys.argv[-1]))
net = zinc.io.zn.load(open(sys.argv[-1]))
ast = net.__ast__()
try :
build(net.lang, ast, None)
......
import time, io, inspect
from snakes.data import mset, iterate, record
from snakes.arcs import Tuple
from snakes.nodes import Place
from zinc.data import mset, iterate, record
from zinc.arcs import Tuple
from zinc.nodes import Place
try:
import autopep8
......@@ -448,6 +448,6 @@ class CodeGenerator (object) :
self.write(name)
if __name__ == "__main__" :
from snakes.io.snk import load
net = load(open("test/simple-python.snk"))
from zinc.io.zn import load
net = load(open("test/simple-python.zn"))
print(net.__ast__().dump())
......
import subprocess
from snakes.compil import CompilationError, BaseDeclare
from zinc.compil import CompilationError, BaseDeclare
from . import codegen as codegen
from .rename import rename
......
from snakes.compil import ast, CompilationError
from zinc.compil import ast, CompilationError
class CodeGenerator (ast.CodeGenerator) :
def visit_Module (self, node) :
......@@ -304,7 +304,7 @@ class CodeGenerator (ast.CodeGenerator) :
if __name__ == "__main__" :
import io, sys
from snakes.io.snk import load
from zinc.io.zn import load
net = load(open(sys.argv[-1]))
gen = CodeGenerator(io.StringIO(), libpath="./libs/js", main=True)
gen.visit(net.__ast__())
......
import subprocess, os.path, os, inspect
import snakes
from snakes.compil import BaseDeclare, CompilationError
from snakes.compil.go.rename import rename
import zinc
from zinc.compil import BaseDeclare, CompilationError
from zinc.compil.go.rename import rename
from . import codegen
NONETYPE = False
......@@ -15,7 +15,7 @@ class Declare (BaseDeclare) :
def update_gopath () :
# TODO: fix this wrt installation path
path = os.path.join(os.path.dirname(os.path.dirname(inspect.getfile(snakes))),
path = os.path.join(os.path.dirname(os.path.dirname(inspect.getfile(zinc))),
"libs", "go")
if "GOPATH" not in os.environ :
os.environ["GOPATH"] = path
......
import re
from operator import attrgetter
from snakes.compil import ast
from snakes import TypingError
from zinc.compil import ast
from zinc import TypingError
def S (text) :
return '"%s"' % text.replace('"', '\\"')
......@@ -13,7 +13,7 @@ package %(package)s
closing = """
func main () {
snk.Main(NET, Init, AddSucc, IterSucc)
zn.Main(NET, Init, AddSucc, IterSucc)
}
"""
......@@ -21,7 +21,7 @@ _letter = re.compile("\W+")
class CodeGenerator (ast.CodeGenerator) :
def visit_Context (self, node) :
node.decl('import "snk"', "import")
node.decl('import "zn"', "import")
node.decl("type Token struct {}")
node.decl("var DOT Token = Token{}")
node.decl("var NET string = %s\n" % S(node.NET.name))
......@@ -91,7 +91,7 @@ class CodeGenerator (ast.CodeGenerator) :
self.unused = set()
self.fill("func ")
self.visit(node.name)
self.write(" (%s snk.Marking, %s snk.Set) {" % (node.marking, node.succ))
self.write(" (%s zn.Marking, %s zn.Set) {" % (node.marking, node.succ))
with self.indent() :
if node.name.trans :
self.fill("// successors for transition %r" % node.name.trans)
......@@ -109,7 +109,7 @@ class CodeGenerator (ast.CodeGenerator) :
self.unused.update(node.variables)
for var, typ in node.variables.items() :
if isinstance(typ, tuple) and typ[0] == "mset" :
self.typedef[typ] = "snk.Mset"
self.typedef[typ] = "zn.Mset"
self.fill("var %s %s" % (var, self.typedef[typ]))
def visit_Assign (self, node) :
self.fill("%s = " % node.variable)
......@@ -236,7 +236,7 @@ class CodeGenerator (ast.CodeGenerator) :
", ".join(self._pattern(m, t) if isinstance(m, tuple)
else m for m, t in zip(matcher, placetype)))
def _newmarking (self, name, marking, assign) :
self.fill("%s := snk.MakeMarking()" % name)
self.fill("%s := zn.MakeMarking()" % name)
whole = []
for place, tokens in marking.items() :
found = False
......@@ -301,7 +301,7 @@ class CodeGenerator (ast.CodeGenerator) :
self.fill("%s.Add(%s.Copy())" % (node.succ, node.old))
def visit_YieldEvent (self, node) :
mvar = node.NAMES.fresh(base="mode")
self.fill("%s := snk.Binding{" % mvar)
self.fill("%s := zn.Binding{" % mvar)
tvars = node.CTX.trans.vars()
last = len(tvars) - 1
for i, v in enumerate(tvars) :
......@@ -310,20 +310,20 @@ class CodeGenerator (ast.CodeGenerator) :
self.write(", ")
self.write("}")
if node.sub and node.add :
self.fill("if ! %s.Put(&snk.Event{%s, %s, %s, %s}) { return }"
self.fill("if ! %s.Put(&zn.Event{%s, %s, %s, %s}) { return }"
% (node.CTX.iterator, S(node.CTX.trans.name), mvar,
node.CTX.subvar, node.CTX.addvar))
elif node.sub :
self.fill("if ! %s.Put(&snk.Event{%s, %s, %s, snk.MakeMarking()})"
self.fill("if ! %s.Put(&zn.Event{%s, %s, %s, zn.MakeMarking()})"
" { return }" % (node.CTX.iterator, S(node.CTX.trans.name),
mvar, node.CTX.subvar))
elif node.add :
self.fill("if ! %s.Put(&snk.Event{%s, %s, snk.MakeMarking(), %s})"
self.fill("if ! %s.Put(&zn.Event{%s, %s, zn.MakeMarking(), %s})"
" { return }" % (node.CTX.iterator, S(node.CTX.trans.name),
mvar, node.CTX.addvar))
else :
self.fill("if ! %s.Put(&snk.Event{%s, %s,"
" snk.MakeMarking(), snk.MakeMarking()}) { return }"
self.fill("if ! %s.Put(&zn.Event{%s, %s,"
" zn.MakeMarking(), zn.MakeMarking()}) { return }"
% (node.CTX.iterator, mvar, S(node.CTX.trans.name)))
def visit_DefSuccIter (self, node) :
self.unused = set()
......@@ -333,7 +333,7 @@ class CodeGenerator (ast.CodeGenerator) :
node.CTX.iterator = node.NAMES.fresh(base="it")
else :
node.CTX.iterator = "it"
self.write(" (%s snk.Marking, %s snk.SuccIterator) {"
self.write(" (%s zn.Marking, %s zn.SuccIterator) {"
% (node.marking, node.CTX.iterator))
with self.indent() :
if node.name.trans :
......@@ -342,7 +342,7 @@ class CodeGenerator (ast.CodeGenerator) :
else :
self.fill("// successors for all transitions")
for name in node.body :
self.fill("for i, p := snk.Iter(")
self.fill("for i, p := zn.Iter(")
self.visit(name)
self.write(", %s); p != nil; p = i.Next() {" % node.marking)
with self.indent() :
......@@ -359,7 +359,7 @@ class CodeGenerator (ast.CodeGenerator) :
def visit_DefSuccFunc (self, node) :
self.fill("func ")
self.visit(node.name)
self.write(" (%s snk.Marking) snk.Set {" % node.marking)
self.write(" (%s zn.Marking) zn.Set {" % node.marking)
with self.indent() :
if node.name.trans :
self.fill("// successors of %r" % node.name.trans)
......@@ -368,7 +368,7 @@ class CodeGenerator (ast.CodeGenerator) :
self.children_visit(node.body, False)
self.fill("}\n")
def visit_InitSucc (self, node) :
self.fill("%s := snk.MakeSet()" % node.name)
self.fill("%s := zn.MakeSet()" % node.name)
def visit_CallSuccProc (self, node) :
self.fill()
self.visit(node.name)
......@@ -378,10 +378,10 @@ class CodeGenerator (ast.CodeGenerator) :
def visit_DefInitFunc (self, node) :
self.fill("func ")
self.visit(node.name)
self.write(" () snk.Marking {")
self.write(" () zn.Marking {")
with self.indent() :
self.fill("// initial marking")
self.fill("init := snk.MakeMarking(0)")
self.fill("init := zn.MakeMarking(0)")
for place in sorted(node.marking, key=attrgetter("place")) :
self.fill("init.Set(")
self.visit(place)
......@@ -395,7 +395,7 @@ class CodeGenerator (ast.CodeGenerator) :
def visit_SuccProcTable (self, node) :
self.fill("// map transitions names to successor procs")
self.fill('// "" maps to all-transitions proc')
self.fill("type SuccProcType func(snk.Marking, snk.Set)")
self.fill("type SuccProcType func(zn.Marking, zn.Set)")
self.fill("var SuccProc map[string]SuccProcType = map[string]SuccProcType{")
with self.indent() :
for trans, name in sorted(self.succproc.items()) :
......@@ -404,7 +404,7 @@ class CodeGenerator (ast.CodeGenerator) :
def visit_SuccFuncTable (self, node) :
self.fill("// map transitions names to successor funcs")
self.fill('// "" maps to all-transitions func')
self.fill("type SuccFuncType func(snk.Marking)snk.Set")
self.fill("type SuccFuncType func(zn.Marking)zn.Set")
self.fill("var SuccFunc map[string]SuccFuncType = map[string]SuccFuncType{")
with self.indent() :
for trans, name in sorted(self.succfunc.items()) :
......@@ -413,8 +413,8 @@ class CodeGenerator (ast.CodeGenerator) :
def visit_SuccIterTable (self, node) :
self.fill("// map transitions names to successor iterators")
self.fill('// "" maps to all-transitions iterator')
self.fill("var SuccIter map[string]snk.SuccIterFunc"
" = map[string]snk.SuccIterFunc{")
self.fill("var SuccIter map[string]zn.SuccIterFunc"
" = map[string]zn.SuccIterFunc{")
with self.indent() :
for trans, name in sorted(self.succiter.items()) :
self.fill("%s: %s," % (S(trans or ""), name))
......@@ -422,7 +422,7 @@ class CodeGenerator (ast.CodeGenerator) :
if __name__ == "__main__" :
import io, sys
from snakes.io.snk import load
from zinc.io.zn import load
net = load(open(sys.argv[-1]))
gen = CodeGenerator(io.StringIO())
gen.visit(net.__ast__("main"))
......
import types, traceback, sys
from snakes.compil import CompilationError, BaseDeclare
from zinc.compil import CompilationError, BaseDeclare
from . import codegen as codegen
from .rename import rename
......
import inspect, collections
from snakes.compil import ast, CompilationError
from zinc.compil import ast, CompilationError
##
## to be included in the generated source code
......@@ -100,7 +100,7 @@ class CodeGenerator (ast.CodeGenerator) :
self.write("\nif __name__ == '__main__':"
"\n main()")
def visit_DefineMarking (self, node) :
self.fill("from snakes.nets import Marking, mset, dot, hdict")
self.fill("from zinc.nets import Marking, mset, dot, hdict")
self.fill("event = collections.namedtuple('event', "
"['trans', 'mode', 'sub', 'add'])\n")
def visit_DefSuccProc (self, node) :
......@@ -399,7 +399,7 @@ class CodeGenerator (ast.CodeGenerator) :
if __name__ == "__main__" :
import io, sys
from snakes.io.snk import load
from zinc.io.zn import load
net = load(open(sys.argv[-1]))
gen = CodeGenerator(io.StringIO())
gen.visit(net.__ast__())
......
@@grammar :: snk
@@grammar :: zn
@@eol_comments :: /#.*?$/
@@whitespace :: /[\t ]+/
......
import ast, collections, functools
from snakes import nets, ParseError, SNAKESError
from snakes.io import snkparse
from snakes.data import flatten
from zinc import nets, ParseError, ZINCError
from zinc.io import znparse
from zinc.data import flatten
class TupleParser (object) :
def __init__ (self) :
self.p = snkparse.snkParser()
self.p = znparse.znParser()
def parse (self, source) :
return self.p.parse(source, "tailtuple", semantics=self)
def tuple (self, st) :
......@@ -33,7 +33,7 @@ class TupleParser (object) :
class Parser (TupleParser) :
def __init__ (self, module=nets) :
self.n = module
self.p = snkparse.snkParser()
self.p = znparse.znParser()
self.t = TupleParser()
def parse (self, source, path) :
self._s = source.rstrip() + "\n"
......@@ -43,7 +43,7 @@ class Parser (TupleParser) :
def spec (self, st) :
try :
net = self.n.PetriNet(st.net, st.lang)
except SNAKESError as err :
except ZINCError as err :
raise ParseError(str(err), None, None, self._p)
for lvl, decl in st.declare :
net.declare(decl, lvl)
......@@ -51,13 +51,13 @@ class Parser (TupleParser) :
if isinstance(node, self.n.Place) :
try :
net.add_place(node)
except SNAKESError as err :
except ZINCError as err :
raise ParseError(err, rest[0], None, self._p)
else :
lineno, inputs, outputs = rest
try :
net.add_transition(node)
except SNAKESError as err :
except ZINCError as err :
raise ParseError(err, lineno, None, self._p)
for place, label in inputs.items() :
try :
......@@ -65,7 +65,7 @@ class Parser (TupleParser) :
net.add_input(place, node.name, label[0])
else :
net.add_input(place, node.name, self.n.MultiArc(*label))
except SNAKESError as err :
except ZINCError as err :
raise ParseError(err, self._l[place, node.name], None, self._p)
for place, label in outputs.items() :
try :
......@@ -73,7 +73,7 @@ class Parser (TupleParser) :
net.add_output(place, node.name, label[0])
else :
net.add_output(place, node.name, self.n.MultiArc(*label))
except SNAKESError as err :
except ZINCError as err :
raise ParseError(err, self._l[node.name, place], None, self._p)
return net
def decl (self, st) :
......@@ -146,7 +146,7 @@ class Parser (TupleParser) :
def arc (self, st) :
try :
return self._mkarc(st)
except SNAKESError as err :
except ZINCError as err :
raise ParseError(str(err), st.parseinfo.line+1, None, self._p)
def loads (source, module=nets) :
......
......@@ -22,7 +22,7 @@ from tatsu.util import re, generic_main # noqa
KEYWORDS = {} # type: ignore
class snkBuffer(Buffer):
class znBuffer(Buffer):
def __init__(
self,
text,
......@@ -34,7 +34,7 @@ class snkBuffer(Buffer):
namechars='',
**kwargs
):
super(snkBuffer, self).__init__(
super(znBuffer, self).__init__(
text,
whitespace=whitespace,
nameguard=nameguard,
......@@ -46,7 +46,7 @@ class snkBuffer(Buffer):
)
class snkParser(Parser):
class znParser(Parser):
def __init__(
self,
whitespace=re.compile('[\\t ]+'),
......@@ -58,12 +58,12 @@ class snkParser(Parser):
parseinfo=True,
keywords=None,
namechars='',
buffer_class=snkBuffer,
buffer_class=znBuffer,
**kwargs
):
if keywords is None:
keywords = KEYWORDS
super(snkParser, self).__init__(
super(znParser, self).__init__(
whitespace=whitespace,
nameguard=nameguard,
comments_re=comments_re,
......@@ -470,7 +470,7 @@ class snkParser(Parser):
self._error('no available options')
class snkSemantics(object):
class znSemantics(object):
def spec(self, ast): # noqa
return ast
......@@ -538,7 +538,7 @@ class snkSemantics(object):
def main(filename, startrule, **kwargs):
with open(filename) as f:
text = f.read()
parser = snkParser()
parser = znParser()
return parser.parse(text, startrule, filename=filename, **kwargs)
......@@ -546,7 +546,7 @@ if __name__ == '__main__':
import json
from tatsu.util import asjson
ast = generic_main(main, snkParser, name='snk')
ast = generic_main(main, znParser, name='zn')
print('AST:')
print(ast)
print()
......
from snakes import *
from snakes.arcs import *
from snakes.nodes import *
from snakes.data import *
from snakes.tokens import *
from zinc import *
from zinc.arcs import *
from zinc.nodes import *
from zinc.data import *
from zinc.tokens import *
import snakes.compil
import zinc.compil
class PetriNet (object) :
def __init__ (self, name, lang="python") :
self.name = name
self.lang = snakes.compil.getlang(lang)
self.lang = zinc.compil.getlang(lang)
self.declare = self.lang.Declare()
self._trans = {}
self._place = {}
......@@ -17,14 +17,14 @@ class PetriNet (object) :
def __repr__ (self) :
return "%s(%r, %r)" % (self.__class__.__name__, self.name, self.lang.name)
def build (self, name="net", saveto=None) :
return snakes.compil.build(self.lang, self.__ast__(name), saveto)
return zinc.compil.build(self.lang, self.__ast__(name), saveto)
def __ast__ (self, name="net") :
ctx = snakes.compil.Context(net=self)
ctx = zinc.compil.Context(net=self)
mod = ctx.Module(name,
[ctx.Context(self.declare.copy()),
ctx.DefineMarking(list(self._place.values()))])
for name, trans in sorted(self._trans.items()) :
mod.body.extend(trans.__ast__(snakes.compil.Context(net=self)))
mod.body.extend(trans.__ast__(zinc.compil.Context(net=self)))
mod.body.append(ctx.DefSuccProc(ctx.SuccProcName(), "marking", "succ", [
ctx.CallSuccProc(ctx.SuccProcName(t.name), "marking", "succ")
for n, t in sorted(self._trans.items())]))
......@@ -34,7 +34,7 @@ class PetriNet (object) :
ctx.ReturnSucc("succ")]))
mod.body.append(ctx.DefSuccIter(ctx.SuccIterName(), "marking", [
ctx.SuccIterName(t.name) for n, t in sorted(self._trans.items())]))
marking = self.get_marking().__ast__(snakes.compil.Context(net=self))
marking = self.get_marking().__ast__(zinc.compil.Context(net=self))
mod.body.extend([ctx.DefInitFunc(ctx.InitName(), marking),
ctx.SuccProcTable(),
ctx.SuccFuncTable(),
......
import operator, logging, collections
from functools import reduce
from snakes import TypingError
from snakes.data import mset, WordSet
from snakes.tokens import Token
from snakes.arcs import MultiArc
from zinc import TypingError
from zinc.data import mset, WordSet
from zinc.tokens import Token
from zinc.arcs import MultiArc
class Node (object) :
pass
......
from snakes.data import hashable, mset
from zinc.data import hashable, mset
class Token (object) :
def __init__ (self, code) :
......