I'm still not fully sold on DSLs, but I think everyone else is, so I'm considering what I might do with them.
So I want to revisit string indentation, though I barely dare to do so. Would it be possible to change the multiline string rules to ignore an immediate newline after an opening, and then base indentation on the start of the next line? I know we went through all this, but with DSLs, I was thinking of matrix syntax like so:
m := Mat <|
4 5 6
7 8 9
10 11 12
|>
I, being an evil "open-punctuation at the end of the line" person, would to format things like shown above. But since I haven't indented to the opening point, that would be illegal. And I'd really rather not have to indent like crazy. It would kill some of the value of pretty formatting like this.
Maybe just if the first line of actual content is illegally backdented, then count that as the correct starting point?
Side question, I presume there's absolutely no way to provide the content |> to a DSL? Or have I missed how that might be done?
KevinKelleyThu 28 May 2009
Not that I'd want to type it, but making it look something like
m := Mat
<| 4 5 6
| 7 8 9
|10 11 12
|>
would kind of connect the DSL text together, and make clear the indentation rule.
Maybe a good way for a Fan editor to present the DSL string.
--Actually I almost would be willing to type it, sometimes anyway. The more I look at it the more I like it. It holds the string together, and makes it blindingly obvious what's in the string and what's not, as far as indentation goes.
brianThu 28 May 2009
DSLs have no restrictions on whitespace. The text between the <| and the |> is passed exactly as typed including all whitespace directly to your plugin fix DslExpr.src. Although Fan will normalize all newlines to \n.
Additional information about leading tabs and spaces is stored in the DSL if you choose to do some normalization. There is a convenience method DslPlugin.normalizeSrc if you wish to use it which normalizes/error checks using the same rules a string literals.
For example the Str plugin is:
@compilerDsl="sys::Str"
class StrDslPlugin : DslPlugin
{
new make(Compiler c) : super(c) {}
override Expr compile(DslExpr dsl)
{
LiteralExpr.makeFor(dsl.location, ns, normalizeSrc(dsl))
}
}
tompalmerThu 28 May 2009
DSLs have no restrictions on whitespace.
Nice. Thanks for the info. That will do for now (but I may bring it up again for strings generally in the future).
By the way, is there any way to provide the content |> to a DSL? Or have I missed how that might be done? This is a general question, not urgent at the moment. Still, I think it needs to be supported.
brianThu 28 May 2009
By the way, is there any way to provide the content |> to a DSL?
I think that has to be a DSL specific problem. The sequence |> can never be in a DSL directly, because it would require some standardized escape sequence which would defeat the purpose of DSLs. But that doesn't mean those chars can't be interpreted by a DSL using some DSL specific escape sequence.
jessevdamFri 19 Feb 2010
A solution to this problem would be use of option to use the start tag <<| For example <<| dsl code |> still dsl code |>> //no more dsl code When it is not needed you can do the normal way of <| dsl code |>. When you need event |>> you can do for example <<<| dsl code |>> still dsl code |>>>
katoxFri 19 Feb 2010
Another possibility is to allow shell-like inlining where you can specify a delimiter in place. No escaping is done, DSL parsing ends when the delimiter is found.
tompalmer Thu 28 May 2009
I'm still not fully sold on DSLs, but I think everyone else is, so I'm considering what I might do with them.
So I want to revisit string indentation, though I barely dare to do so. Would it be possible to change the multiline string rules to ignore an immediate newline after an opening, and then base indentation on the start of the next line? I know we went through all this, but with DSLs, I was thinking of matrix syntax like so:
I, being an evil "open-punctuation at the end of the line" person, would to format things like shown above. But since I haven't indented to the opening point, that would be illegal. And I'd really rather not have to indent like crazy. It would kill some of the value of pretty formatting like this.
Maybe just if the first line of actual content is illegally backdented, then count that as the correct starting point?
Side question, I presume there's absolutely no way to provide the content
|>
to a DSL? Or have I missed how that might be done?KevinKelley Thu 28 May 2009
Not that I'd want to type it, but making it look something like
would kind of connect the DSL text together, and make clear the indentation rule.
Maybe a good way for a Fan editor to present the DSL string.
--Actually I almost would be willing to type it, sometimes anyway. The more I look at it the more I like it. It holds the string together, and makes it blindingly obvious what's in the string and what's not, as far as indentation goes.
brian Thu 28 May 2009
DSLs have no restrictions on whitespace. The text between the
<|
and the|>
is passed exactly as typed including all whitespace directly to your plugin fixDslExpr.src
. Although Fan will normalize all newlines to\n
.Additional information about leading tabs and spaces is stored in the DSL if you choose to do some normalization. There is a convenience method
DslPlugin.normalizeSrc
if you wish to use it which normalizes/error checks using the same rules a string literals.For example the Str plugin is:
tompalmer Thu 28 May 2009
Nice. Thanks for the info. That will do for now (but I may bring it up again for strings generally in the future).
By the way, is there any way to provide the content
|>
to a DSL? Or have I missed how that might be done? This is a general question, not urgent at the moment. Still, I think it needs to be supported.brian Thu 28 May 2009
I think that has to be a DSL specific problem. The sequence
|>
can never be in a DSL directly, because it would require some standardized escape sequence which would defeat the purpose of DSLs. But that doesn't mean those chars can't be interpreted by a DSL using some DSL specific escape sequence.jessevdam Fri 19 Feb 2010
A solution to this problem would be use of option to use the start tag <<| For example <<| dsl code |> still dsl code |>> //no more dsl code When it is not needed you can do the normal way of <| dsl code |>. When you need event |>> you can do for example <<<| dsl code |>> still dsl code |>>>
katox Fri 19 Feb 2010
Another possibility is to allow shell-like inlining where you can specify a delimiter in place. No escaping is done, DSL parsing ends when the delimiter is found.