Is there any suitable way to generate a [jpg, png etc.] syntax diagram(and/or AST) directly from Scala Parser Combinators?
Asked Answered
E

1

16

The only ways I am aware of, aren't "direct":

  • converting to ANTLR format and using its own visualizer
  • VISUALLANGLAB, which it seems to require an entire mouse-clicks "rewrite"
  • implementing a converter by myself (which would be funny, but time-consuming)
  • second link below

Related:

The second link suggests to debug adding an implicitly method to the parsers:

implicit def toLogged(name:String) = new { 
  def !!![T](p:Parser[T]) = log(p)(name)
}

May be an AST would be more feasible/usefull; but the question remains similar.

Evannia answered 30/1, 2013 at 18:41 Comment(0)
R
1

I might have misunderstood your question.

Scala parser combinators are used to parse strings to instances of types that you can use (either custom or built-in). The result is a structure of Scala instances that you decide, this could be anything.

You could create a parser that parses your arbitrary string into instances of a well known java structure for example ECore.

Without a usecase it's hard to suggest the best road for your problem. Maybe Xtext can help you: http://www.eclipse.org/Xtext/. Xtext has quite a few built-in features, however it's an Eclipse plugin and you might need something else.

Roxannroxanna answered 14/2, 2013 at 7:50 Comment(2)
I am not good at terminology (Combinators etc.). My intent is to evolve my language interpreter already written in Scala (combinators + case classes + pattern matching). The syntax diagram would be mainly for debugging purposes.Evannia
Ahh, now I understand. I wonder, are looking for something that creates images of your case class instances or images of the structure that is represented by your combinators. The last one is very difficult because it's actually one big function (you would need quite a complex compiler plugin). The first one is doable, but not standardized. You could convert your case classes to a standard model like this: eclipse.org/Xtext/documentation.html#model_metamodelRoxannroxanna

© 2022 - 2024 — McMap. All rights reserved.