Hi,
I have a question I'd like to discuss. We have a certain subproject in
[Kaitai Struct], which implements [expression language] — some simple
generic (poorly documented, though) language that aims to be
compilable into all supported target languages.
It was designed to be fairly distinct from the rest of Kaitai Struct
project, i.e. it does not know anything about structures, YAML
definitions, seq/instances, etc. If just operates in simple identifier
semantics.
It some respects, it's like Haxe, but much simpler, and requires zero
extra runtime libraries.
Would it be potenially interesting to anyone if we've released it as a
separate Scala (Java/JavaScript) library? The interface is pretty
simple. We just need to supply an implementation of TypeProvider that
basically tells which type is which identifier:
class FooBarProvider extends TypeProvider {
override def determineType(name: String): BaseType = ???
override def determineType(parentType: List[String], name: String):
BaseType = ???
}
and then you can translate any expression to any language:
val expr = Expressions.parse("foo[42] + 7")
val tr1 = new PythonTranslator(new FooBarProvider)
tr1.translate(expr) // => "(self.foo[42] + 7)"
val tr2 = new JavaTranslator(new FooBarProvider)
tr2.translate(expr) // => "(foo().get(42) + 7)"
val tr3 = new CSharpTranslator(new FooBarProvider)
tr3.translate(expr) // => "(Foo[42] + 7)"
val tr4 = new JavaScriptTranslator(new FooBarProvider)
tr4.translate(expr) // => "(this.foo[42] + 7)"
(in this example, FooBarProvider was queries for the type of "foo" and
reported it is an array of integers).
[Kaitai Struct]:
http://kaitai.io/
[expression language]:
https://github.com/kaitai-io/kaitai_struct/wiki/Expressions
--
WBR, Mikhail Yakshin