It is much easier to parse the entire Alloy model from string instead of creating AST manually. See this post for an example. That example uses
CompUtil.parseEverything_fromFile(..., <file_name>)
but you can replace that with
CompUtil.parseOneModule_fromString("sig A{ B: Int}")
to parse directly from string (note that the return type in the latter case is List<Command>
, and not CompModule
like in the linked example, but that shouldn't be a problem for you).