Skip to content

About

OMG IDL parser. This parses OMG IDL file and output intermediate Python object.

Resources

Stars

16 stars

Watchers

6 watching

Forks

Repository files navigation

idl_parser

Test Documentation Status codecov

Description

OMG IDL file parser. This library just parse IDL files, and output intermidiate type objects.

Documentation

API reference and usage: https://idl-parser.readthedocs.io/

Example

"""
    
"""
    
from idl_parser import parser
parser_ = parser.IDLParser()
idl_str = """
module my_module {
  struct Time {
    long sec;
    long usec;
  };

  typedef sequence<double> DoubleSeq;
  
  struct TimedDoubleSeq {
    Time tm;
    DoubleSeq data;
  };

  enum RETURN_VALUE {
    RETURN_OK,
    RETURN_FAILED,
  };

  interface DataGetter {
    RETURN_VALUE getData(out TimedDoubleSeq data);
  };

};
"""
    
global_module = parser_.load(idl_str)
my_module = global_module.module_by_name('my_module')
dataGetter = my_module.interface_by_name('DataGetter')
print('DataGetter interface')
for m in dataGetter.methods:
  print('- method:')
  print('  name:', m.name)
  print('  returns:', m.returns.name)
  print('  arguments:')
  for a in m.arguments:
    print('    name:', a.name)
    print('    type:', a.type)
    print('    direction:', a.direction)
    
doubleSeq = my_module.typedef_by_name('DoubleSeq')
print('typedef %s %s' % (doubleSeq.type.name, doubleSeq.name))

timedDoubleSeq = my_module.struct_by_name('TimedDoubleSeq')
print('TimedDoubleSeq')
for m in timedDoubleSeq.members:
  print('- member:')
  print('  name:', m.name)
  print('  type:', m.type.name)

More examples are in the examples folder:

File Shows
example.py the smallest example: a module and an interface
argument_direction_example.py directions of method arguments: in, out and inout
struct_example.py structs and their member types
struct_inheritance_map_example.py struct inheritance (struct B : A) and map<K, V> types
any_fixed_example.py any, Object, ValueBase and fixed-point (fixed<d, s>) types
preprocessor_example.py #define macros, #if / #elif / #else, and macros given from outside with IDLParser(defines=...)
enum_example.py enums and their values
enum_value_example.py enumerator values set with @value(n) (literals or const names)
const_expr_example.py constant expressions (N * 2, (1 << 3)) in const values, array sizes and bounds
typedef_template_module_example.py types declared inside a typedef (typedef enum E { ... } EE;), and template modules, which are skipped with a warning
union_example.py unions: discriminator kinds, case and default labels, member types
annotation_example.py IDL 4 annotations (@key, @range, ...) and struct keys
valuetype_example.py value types and event types: state members, factory, inheritance, supports, boxed value types
include_dirs_example.py IDL files that #include each other across several include directories
conditional_include_example.py #include in #if / #elif / #else branches: only the files of the kept branch are read
repository_id_example.py repository IDs (IDL:omg.org/CosNaming/NamingContext:1.0) from #pragma prefix / ID / version, typeid and typeprefix
scoped_name_example.py same-named types in several modules: relative (X, C::X) and absolute (::B::X) names

Run them with e.g. python examples/union_example.py (in a source checkout no install is needed).

How to install

sudo pip install idl_parser

Copyright

  • author: Yuki Suga
  • copyright: Yuki Suga
  • contact: please open an issue on GitHub Issues
  • license: GPLv3 or later (GPL-3.0-or-later, see LICENSE)

About

OMG IDL parser. This parses OMG IDL file and output intermediate Python object.

Resources

Stars

16 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages