def code():
        def field_code(f):
            def field_str(field):
                return f"{'repeated ' if field.repeated else ''}{field.fieldType} {field.name} = {field.label};"

            if isinstance(f, Field):
                field = f
                yield from lines(f"""\
    {field_str(field)}""")
            elif isinstance(f, Oneof):
                oneof = f
                yield from lines(f"""\
    oneof {oneof.name} {{""")
                for field in oneof.fields:
                    yield from lines(f"""\
        {field_str(field)}""")
                yield from lines(f"""\
    }}""")
            else:
                assert False

        def params_str(params):
            mandatory = (param.name for param in params if isinstance(param, MandatoryParam))
            repeated = (f"*{param.name}" for param in params if isinstance(param, RepeatedParam))
            optional = ("/".join(param.options) for param in params if isinstance(param, OptionalParam))

            optional = f"[{', '.join(optional)}]"
            optional = (optional,) if optional != "[]" else ()

            return f"({', '.join(itertools.chain(mandatory, repeated, optional))})"

        yield from lines(f"""\
syntax = "proto3";

package hedgehog.protocol.proto;

option java_package = "at.pria.hedgehog.protocol.proto";
option java_outer_classname = "{case(snake=proto.name, to='pascal')}P";

// <default GSL customizable: module-extras />
""")
        for message in proto.messages:
            yield from lines(f"""\

""")
            for docstring in lines(message.docstring or ""):
                yield from lines(f"""\
// {docstring}""")
            if message.docstring and message.messageClasses:
                yield from lines(f"""\
//""")
            for messageClass in message.messageClasses:
                yield from lines(f"""\
// {f"{messageClass.direction} {params_str(messageClass.params)}:".ljust(24)}  {messageClass.docstring or ""}""")
            yield from lines(f"""\
message {message.name} {{""")
            for field in message.fields:
                yield from field_code(field)
            yield from lines(f"""\
}}""")
示例#2
0
def class_declaration(model):
    yield from lines(f"""\
public class {model.name} {{""")
    for member in model.members:
        if isinstance(member, Field):
            yield from lines(f"""\

    private int {member.name};""")
        elif isinstance(member, Method):
            yield from lines(f"""\

    public void {member.name}() {{
        // TODO
    }}""")
    yield from lines(f"""\
}}""")
示例#3
0
def class_declaration(model):
    yield from lines(f"""\
public class {model.IDENTIFIER()} {{""")
    for member in model.getChildren():
        if isinstance(member, SimpleClassParser.FieldDefContext):
            yield from lines(f"""\

    private int {member.IDENTIFIER()};""")
        elif isinstance(member, SimpleClassParser.MethodDefContext):
            yield from lines(f"""\

    public void {member.IDENTIFIER()}() {{
        // TODO
    }}""")
    yield from lines(f"""\
}}""")
示例#4
0
def class_declaration(model):
    yield from lines(f"""\
public class {model.name} {{""")
    for member in model.members:
        if isinstance(member, Field):
            yield from lines(f"""\

    private int {member.name};""")
        elif isinstance(member, Method):
            yield from lines(f"""\

    public void {member.name}() {{
        // <default GSL customizable: method-{member.name}>
        // TODO
        // </GSL customizable: method-{member.name}>
    }}""")
    yield from lines(f"""\
}}""")
示例#5
0
文件: test.py 项目: SillyFreak/gsl
        def code():
            yield from lines("""\
newest generated header
# !! <default GSL customizable: section2>
# ! </GSL customizable: section2>
newest generated divider
# ! <default GSL customizable: section1 />
newest generated footer
""")
示例#6
0
文件: test.py 项目: SillyFreak/gsl
        def code():
            yield from lines("""\
generated header
# <default GSL customizable: section1>
CUSTOMIZED section1
# </GSL customizable: section1>
# <default GSL customizable: section2 />
generated footer
""")
示例#7
0
文件: test.py 项目: SillyFreak/gsl
        def code():
            yield from lines("""\
generated header
# <default GSL customizable: section1 />
generated divider
# <default GSL customizable: section2>
# </GSL customizable: section2>
generated footer
""")
示例#8
0
文件: test.py 项目: SillyFreak/gsl
        def code():
            yield from lines("""\
new generated header
# <GSL customizable: section1>
CUSTOMIZED section1
# </GSL customizable: section1>
new generated divider
# ! <GSL customizable: section2 />
new generated footer
""")
        def field_code(f):
            def field_str(field):
                return f"{'repeated ' if field.repeated else ''}{field.fieldType} {field.name} = {field.label};"

            if isinstance(f, Field):
                field = f
                yield from lines(f"""\
    {field_str(field)}""")
            elif isinstance(f, Oneof):
                oneof = f
                yield from lines(f"""\
    oneof {oneof.name} {{""")
                for field in oneof.fields:
                    yield from lines(f"""\
        {field_str(field)}""")
                yield from lines(f"""\
    }}""")
            else:
                assert False
    def code():
        yield from lines(f"""\
syntax = "proto3";

package hedgehog.protocol.proto;

option java_package = "at.pria.hedgehog.protocol.proto";
option java_outer_classname = "HedgehogP";

""")
        for proto in model.protos:
            yield from lines(f"""\
import "hedgehog/protocol/proto/{'/'.join(proto.path + (proto.name,))}.proto";""")
        yield from lines(f"""\

// <default GSL customizable: module-extras />

message HedgehogMessage {{
    oneof payload {{""")
        for proto in model.protos:
            yield from lines(f"""\
        // {proto.name}.proto""")
            for message in proto.messages:
                yield from lines(f"""\
        {message.name} {message.discriminator} = {message.label};""")
        yield from lines(f"""\
    }}
}}""")
示例#11
0
    def code():
        yield from lines(f"""\
import * as noflo from 'noflo';

// <default GSL customizable: module-extras />

export function getComponent() {{
    let c = new noflo.Component();
    c.description = {component.description!r};
    c.icon = {component.icon!r};

""")

        for port in component.inPorts:
            yield from lines(f"""\
    c.inPorts.add({get_js_value('name', in_port=port)}, {{
""")
            for prop in ['datatype', 'control', 'default', 'description']:
                try:
                    prop_value = get_js_value(prop, in_port=port)
                except KeyError:
                    pass
                else:
                    yield from lines(f"""\
        {prop}: {prop_value},
""")
            yield from lines(f"""\
    }});
""")
        yield from lines(f"""\

""")
        for port in component.outPorts:
            yield from lines(f"""\
    c.outPorts.add({get_js_value('name', out_port=port)}, {{
""")
            for prop in ['datatype', 'description']:
                try:
                    prop_value = get_js_value(prop, out_port=port)
                except KeyError:
                    pass
                else:
                    yield from lines(f"""\
        {prop}: {prop_value},
""")
            yield from lines(f"""\
    }});
""")
        yield from lines(f"""\

    // <default GSL customizable: component-extras />

    return c.process((input, output, context) => {{
""")
        if any(port.get('template', None) == 'endpoint' for port in component.inPorts):
            yield from lines(f"""\
        if (!input.hasData('endpoint')) return;

        let endpoint: string = input.getData('endpoint');
""")
        if any(port.get('template', None) == 'endpoint' for port in component.outPorts):
            yield from lines(f"""\
        output.send({{
            endpoint,
        }});
""")
        preconditions = component.preconditions
        preconditions = re.sub(r"(\w+)", r"'\1'", preconditions)
        preconditions = re.sub(r"('\w+'(?:\s*,\s*'\w+')*)", r"input.hasData(\1)", preconditions)
        yield from lines(f"""\

        if (!({preconditions})) {{
            output.done();
            return;
        }}
""")
        yield from lines(f"""\

        // <default GSL customizable: component>
        output.done();
        // </GSL customizable: component>
    }});
}}
""")