Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [Xbase] Problems with types and scoping in Xbase-based DSL
[Xbase] Problems with types and scoping in Xbase-based DSL [message #1798050] Sun, 11 November 2018 16:16 Go to next message
Eclipse UserFriend
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
Re: [Xbase] Problems with types and scoping in Xbase-based DSL [message #1798053 is a reply to message #1798050] Sun, 11 November 2018 18:03 Go to previous messageGo to next message
Eclipse UserFriend
I found the problem! Since it seemed to have something to do with type computation, I looked at how Xbase' type computer worked for XBlockExpression and noticed it recursed on the child expressions. Doing this for TableLiteral solved the problem.
Re: [Xbase] Problems with types and scoping in Xbase-based DSL [message #1798064 is a reply to message #1798053] Mon, 12 November 2018 02:30 Go to previous message
Eclipse UserFriend
yes you have to actually tell xbase to see the children typesystem wise. otherwise the logical container magic does not work
Previous Topic:Strange trace files after code generation! Are they generated by XText?
Next Topic:Error: The code for the static initializer is exceeding the 65535 bytes limit
Goto Forum:
  


Current Time: Thu Jun 19 12:55:59 EDT 2025

Powered by FUDForum. Page generated in 0.04174 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top