[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: Functional blocks and PCB format changes
Nice,
but I prefer
#! /usr/bin/python
import yaml
from pprint import pprint
pcb = yaml.load('''
---
pin:
pinNumber: 2
pinName: "rst"
x1: 1234
y1: 4321
x2: 2345
y2: 4321
layer: component
...
''')
# or from file
#pcb = yaml.load(open(sys.argv[1], 'rb'))
pprint(pcb)
EOF
./foo.py
{'pin': {'layer': 'component',
'pinName': 'rst',
'pinNumber': 2,
'x1': 1234,
'x2': 2345,
'y1': 4321,
'y2': 4321}}
When I add a new flag to the parser round....
#! /usr/bin/python
import yaml
from pprint import pprint
pcb = yaml.load('''
---
pin:
pinNumber: 2
pinName: "rst"
x1: 1234
y1: 4321
x2: 2345
y2: 4321
layer: component
round: true
...
''')
pprint(pcb)
./foo_with_round.py
{'pin': {'layer': 'component',
'pinName': 'rst',
'pinNumber': 2,
'round': True,
'x1': 1234,
'x2': 2345,
'y1': 4321,
'y2': 4321}}
The parser dosen't need a new line
> my($layer) = $pin->findnodes('./round/text()')->to_boolean ;
Or something like that.
My point about XML vs any data serialization language is that we have a data structure in out code that can be just dumped.
With XML we write a parser, with yaml we use a parser that is already written.
Now we may want to write a parser, and emitter, but that is a good amount of work, to serialize a data structure in the code that could be output be a data serializer that just works.
On Sep 13, 2010, at 6:57 PM, Ouabache Designworks wrote:
> pin:
> pinNumber: 2
> pinName: "rst"
> x1: 1234
> y1: 4321
> x2: 2345
> y2: 4321
> layer: component
> or
> <pin><pinNumber>2</pinNumber><pinName>"rst"<\pinName><x1>1234<\x1><y
> 1>4321<\y1><x2>2345<\x2><y2>5432<\y2><layer>component<\layer><\pin>
> I call the second large, bloat, and ugly.
>
> ---------------------------------------------
> Here you go:
> ===============================
> #!/usr/bin/perl -w
> use strict;
> use warnings;
> my $filename = shift @ARGV;
> use XML::LibXML;
> my $parser = XML::LibXML->new();
> my $doc = $parser->parse_file($filename);
> foreach
> my $pin ($doc->findnodes('/pin')) {
> my($pinNumber) = $pin->findnodes('./pinNumber/text()')->to_literal
> ;
> my($pinName) = $pin->findnodes('./pinName/text()')->to_literal ;
> my($x1) = $pin->findnodes('./x1/text()')->to_literal ;
> my($y1) = $pin->findnodes('./y1/text()')->to_literal ;
> my($x2) = $pin->findnodes('./x2/text()')->to_literal ;
> my($y2) = $pin->findnodes('./y2/text()')->to_literal ;
> my($layer) = $pin->findnodes('./layer/text()')->to_literal ;
> print "pin\n";
> print " pinNumber: $pinNumber\n";
> print " pinName: $pinName\n";
> print " x1: $x1\n";
> print " y1: $y1\n";
> print " x2: $x2\n";
> print " y2: $y2\n";
> print " layer: $layer\n";
> }
> =================================
> Simple perl script will make things pretty again. (after you fix the
> your backslashes). Only takes
oops :-0 see how one can make mistakes :-P
> one extra module (libXML) that you can apt-get on ubuntu. Going back
> the other way is just as easy once
> you write a parser for your format.
written already
in perl it is use yaml; available on cpan
> If size is an issue you can always store everything compressed.
I never really cared about size, gzip of bzip the bugger and you get faster load and store times..... for what ever format your using.
> Then
> we can have another argument about
> whether we should create our own compression scheme or use an existing
> one.
I vote for quantum 1 bit compression! this way all designs and files take up 4KB ( the block size in most computers to store the file). :-)
and all PCBs ever created are the same file! Included the first time you save the default layout!!!!
> John Eaton
>
>
> _______________________________________________
> geda-user mailing list
> geda-user@xxxxxxxxxxxxxx
> http://www.seul.org/cgi-bin/mailman/listinfo/geda-user
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user