pegged: non at safe semantic actions

Dmitry Ponyatov dponyatov at gmail.com
Fri Dec 8 17:13:21 UTC 2023


What's wrong with using non at safe actions which creates and 
modifies some external objects?

```D
class Layer {
     int index;
     string name;
     this(int index, string name) {

class SignalLayer : Layer {
class UserLayer : Layer {

class PCB {
     Layer[] layer;

PT _deflayer(PT)(PT p) {
     auto index = to!int(p.matches[0]);
     switch (p.matches[2]) {
     case "signal":
         pcb.layer ~= new SignalLayer(index, p.matches[1]); break;
     case "user":
         pcb.layer ~= new UserLayer(index, p.matches[1]); break;
     default:
         break;
     }
     return p;
}

mixin(grammar(`
     parser:
         kicad_pcb <  :l :'kicad_pcb' verzion host general page 
layers
         layers    <  :l :'layers' (deflayer {_deflayer})+ :r
         deflayer  <  :l unum layer ('signal'|'user') :r

```
```
../.dub/packages/pegged/0.4.9/pegged/pegged/peg.d(3049,19): 
Error: `@safe` function `pegged.peg.action!(wrapAround, 
_deflayer).action` cannot call `@system` function 
`kicad._deflayer!(ParseTree)._deflayer`
src/kicad.d(27,5):        which calls `kicad.SignalLayer.this`
src/kicad.d(68,4):        `kicad._deflayer!(ParseTree)._deflayer` 
is declared here
src/kicad.d-mixin-83(219,289): Error: template instance 
`pegged.peg.action!(wrapAround, _deflayer)` error instantiating
src/kicad.d-mixin-83(932,7):        instantiated from here: 
`Genericparser!(ParseTree)`
../.dub/packages/pegged/0.4.9/pegged/pegged/peg.d(544,20): Error: 
none of the overloads of `layers` are callable using argument 
types `(GetName)`
src/kicad.d-mixin-83(215,23):        Candidates are: 
`kicad.Genericparser!(ParseTree).Genericparser.parser.layers(ParseTree p)`
src/kicad.d-mixin-83(234,23):                        
`kicad.Genericparser!(ParseTree).Genericparser.parser.layers(string s)`
../.dub/packages/pegged/0.4.9/pegged/pegged/peg.d(1598,24): 
Error: template instance `pegged.peg.getName!(layers)` error 
instantiating
src/kicad.d-mixin-83(183,436):        instantiated from here: 
`wrapAround!(named, layers, named)`
src/kicad.d-mixin-83(932,7):        instantiated from here: 
`Genericparser!(ParseTree)`
```



More information about the Digitalmars-d-learn mailing list