[Xbase] Problems with types and scoping in Xbase-based DSL [message #1798050] |
Sun, 11 November 2018 16:16  |
Eclipse User |
|
|
|
I'm working on a DSL for making Tablesaw (a data frame library for Java) scripts, and one of its features is a special syntax for table literals:
val tab1 =
# String name, short age #
| "Hallvard", 51 |
| "Aud", 80 |
val tab2 = #String name = tab1.getColumn("name"), short age #
Two variants are shown, the first defines a table with two columns (name and age) and provides values for two rows of name and age values, while the second variant declares the same columns, and initialises the first column to the corresponding column of the first table (assigned to tab1).
Note how the syntax for a table literal has "inner" expressions in both the column list part (the part between the # characters) and the row list part (between | characters). My problem is that neither type computations nor scoping work for the inner expressions, e.g. XBase doesn't find the type of "Hallvard" or 51 (during compilation), or link tab1 in the second table literal to the tab1 variable declaration. Code completion doesn't suggest anything other that the expression keywords within the column or row parts). I know that tab1 is properly declared, since it can be referenced in expressions outside the table literal expressions.
The Xtext syntax declares rules for TableLiteral, TableColumn and TableRow as follows (slightly simplified):
TableLiteral returns xbase::XBlockExpression :
{ TableLiteral }
'#' (expressions += TableColumn (',' expressions += TableColumn)*)? '#'
(expressions += TableRow)*
;
TableColumn returns xbase::XExpression:
{ TableColumn } (type = JvmTypeReference name = (ValidID | STRING) ('=' expression = XExpression)?)
;
TableRow returns xbase::XBlockExpression:
{ TableRow } '|' (expressions += XExpression (',' expressions += XExpression)*)? '|'
;
I return XBlockExpression for both TableLiteral and TableRow, since both contain many expressions. I was hoping that the scoping for the expressions reference would work out-of-the-box, since all the inner expressions are logically within a block. I have tried a variant where only TableLiteral returns XExpression, but the problems where the same. I bind my own compiler and override relevant methods so I can control how statements are generated, but without type info for even simple literals or correct linking of variables like tab1, the generated code have syntax errors. I've spent hours in the debugger and the control flow seems correct, if I compare with how existing expression constructs seems to work.
Any suggestions?
Regards,
Hallvard
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04174 seconds