Giter Site home page Giter Site logo

palm's People

Contributors

dowski avatar m4dc4p avatar schmichael avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

palm's Issues

Parser breaks on service definitions

I'm not worried about palmc generating service code for me, but it'd be nice if the parser didn't break when it encountered service definitions like:

service RemoteService {
    rpc Execute (Request) returns (Response);
}

__contains__ method generated once per field

Given t.proto:

message A {
  optional string foo = 0;
}

grep -c __contains__ t_palm.py => 1

Which is what you expect.

However, add a couple more fields:

message A {
  optional string foo = 0;
  optional string bar = 1;
  optional string baz = 2;
}

And you get __contains__ defined 3 times: grep -c __contains__ t_palm.py => 3

The definition is the same, so this is a harmless bug other than a few extra instructions processed when Python compiles the proto's class.

Allow setting repeated fields via __init__

The proto file t.proto:

message M {
  repeated string a = 0;
}

It'd be nice to be able to set the a field from a list during initialization like: pb = M(a=["one", "two"])

Google's protobuf library allows this, but palm does not:

>>> import t_palm
>>> pb = t_palm.M(a=['a', 'b'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "t_palm.py", line 14, in __init__
    ProtoBase.__init__(self, _pbf_buf, **kw)
  File "palm.pyx", line 154, in palm.palm.ProtoBase.__init__ (palm/palm.c:1583)
  File "t_palm.py", line 70, in _set_a
    raise ProtoValueError(list_assign_error)
palm.palm.ProtoValueError: Can't assign list to repeated field a

Unable to compile protos with nested messages of the same name

Google's protoc can compile the following just fine as the duplicate message Xs are in different enclosing messages:

message A {
    optional B b = 1;
    optional C c = 2;

    message B {
        optional X x = 1;
        message X {
            optional bool wat = 1;
        }
    }
    message C {
        optional X x = 1;
        message X {
            optional bool wat = 1;
        }
    }
}

palm 0.1.2 produces the following:

p.proto...                                                            [FAIL]
Traceback (most recent call last):
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/main.py", line 24, in run
    r = parser.parse(source)
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/baseparser.py", line 32, in parse
    return processor( value, data )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 32, in __call__
    result = dispatchList( self, tags, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
    return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
    return function( tag, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 63, in message
    dispatchList(self, subtags, buffer)
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
    return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
    return function( tag, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 88, in message_body
    return dispatchList(self, subtags, buffer)
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
    return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
    return function( tag, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 63, in message
    dispatchList(self, subtags, buffer)
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
    return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
    return function( tag, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 88, in message_body
    return dispatchList(self, subtags, buffer)
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
    return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
    return function( tag, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 63, in message
    dispatchList(self, subtags, buffer)
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
    return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
    return function( tag, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 83, in message_label
    raise ProtoParseError(start, stop, buffer, "message %s already defined" % self.current_message)
ProtoParseError: [line 1] message 2-X already defined

palm 0.1.5 produces the following:

p.proto...                                                            [FAIL]
Traceback (most recent call last):
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/main.py", line 36, in run
    r = parser.parse(source)
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/baseparser.py", line 32, in parse
    return processor( value, data )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 32, in __call__
    result = dispatchList( self, tags, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
    return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
    return function( tag, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 81, in message
    dispatchList(self, subtags, buffer)
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
    return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
    return function( tag, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 106, in message_body
    return dispatchList(self, subtags, buffer)
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
    return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
    return function( tag, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 81, in message
    dispatchList(self, subtags, buffer)
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
    return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
    return function( tag, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 106, in message_body
    return dispatchList(self, subtags, buffer)
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
    return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
    return function( tag, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 81, in message
    dispatchList(self, subtags, buffer)
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
    return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
    return function( tag, buffer )
  File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 101, in message_label
    raise ProtoParseError(start, stop, buffer, "message %s already defined" % self.current_message)
ProtoParseError: [line 1] message 2-X already defined

protoc compatible plugin

It would be handy to integrate into Google's protoc tool to simplify usage and integrate with cross-platform projects more easily.

Plugins are as "simple" as a binary named protoc-gen-$NAME:

// A plugin executable needs only to be placed somewhere in the path.  The
// plugin should be named "protoc-gen-$NAME", and will then be used when the
// flag "--${NAME}_out" is passed to protoc.

via: https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.compiler.plugin.pb

See also: https://developers.google.com/protocol-buffers/docs/reference/other

(I know this is probably a lot of work for only a slight bump in usability, but a guy can dream right?)

Default values that use nested enums fail with NameError

t.proto

message M {
    optional Options opt = 1 [default = NONE];

    enum Options {
        NONE = 0;
        NOT_NONE = 1;
    }
}
palmc . .
python
>>> import t_palm
>>> t_palm.M(t_palm.M().dumps()).opt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "t_palm.py", line 51, in _get_opt
    r = NONE
NameError: global name 'NONE' is not defined

Setting default = M.NONE or default = Options.NONE are both invalid.

package "support"

Ignoring package directives seems sensible since Python doesn't use it.

I'll see if I can't figure it out, but I've never used SimpleParse.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.