Add verbatim string literals '...' #5

Closed
opened 2021-01-31 04:10:57 +00:00 by glen · 6 comments
Owner

This opens a host of other questions:

  • How to allow the ' character to occur in such a literal? Answer: Don't, since we will end up adding ""-strings with escape sequences anyway, and those can have either ' or " (via \") in them.

  • Semantics of String + String? It seems this should perhaps be concatenation, but on the other hand, there's reason to use application for concatenation, namely that then string interpolation becomes fairly moot, in that it's not much easier to write
    "The sum of {a} and {b} is {a+b}." than 'The sum of 'a' and 'b' is '(a+b)'.'

  • Semantics if any of Int + String, etc. ?

  • Do we need to type things to be able to generate code for sums?

This opens a host of other questions: * How to allow the ' character to occur in such a literal? Answer: Don't, since we will end up adding ""-strings with escape sequences anyway, and those can have either ' or " (via `\"`) in them. * Semantics of String + String? It seems this should perhaps be concatenation, but on the other hand, there's reason to use application for concatenation, namely that then string interpolation becomes fairly moot, in that it's not much easier to write "The sum of {a} and {b} is {a+b}." than 'The sum of 'a' and 'b' is '(a+b)'.' * Semantics if any of Int + String, etc. ? * Do we need to type things to be able to generate code for sums?
glen added the
enhancement
label 2021-01-31 04:10:57 +00:00
Author
Owner

But if application is concatenation, how do we index a string to get characters and substrings and such? We were planning to use application for indexing of arrays and finite maps (makes perfect sense to think of them as kinds of functions).

I think it's ok to lose the indexing semantics for application, but we need a nice syntax for indexing/slicing. Perhaps @ operator, although then there's a question of what to do for namespacing, as I was also thinking of identifiers of the form fred@module. I'd be worried about overloading between these two.

But if application is concatenation, how do we index a string to get characters and substrings and such? We were planning to use application for indexing of arrays and finite maps (makes perfect sense to think of them as kinds of functions). I think it's ok to lose the indexing semantics for application, but we need a nice syntax for indexing/slicing. Perhaps @ operator, although then there's a question of what to do for namespacing, as I was also thinking of identifiers of the form fred@module. I'd be worried about overloading between these two.
Author
Owner

I think fostr should go with string @ 3:6, and maybe use ~ for namespaced identifiers, e.g. fred~module.

I think fostr should go with string @ 3:6, and maybe use ~ for namespaced identifiers, e.g. fred~module.
Author
Owner

And the plan now is to use ++ for string concatenation, rather than overloading +, and
for strings s, s 'fred' will be a shorthand for s ++ fred, whereas for other collections c, c 5 will be a shorthand for c @ 5.

And the plan now is to use ++ for string concatenation, rather than overloading +, and for strings s, s 'fred' will be a shorthand for s ++ fred, whereas for other collections c, c 5 will be a shorthand for c @ 5.
glen added a new dependency 2021-02-12 00:31:22 +00:00
Author
Owner

Todos on this issue:

  • See if I can make sense of Ivo Wilms' wrapper functions in Slack
  • Debug Haskell code generation: Gets() with typed item
  • Do a documentation PR on stratego for the help that was provided with syntax
  • Work out the case of typing a sequence
  • See what happens when a string literal wraps on multiple lines and how that interacts with layout

Answer: string literals must be contained in a single line because of the offside
rule; apparently the internal whitespace characters count as characters in the line, and so trigger the offside.

Todos on this issue: - ~~See if I can make sense of Ivo Wilms' wrapper functions in Slack~~ - ~~Debug Haskell code generation: Gets() with typed item~~ - ~~Do a documentation PR on stratego for the help that was provided with syntax~~ - ~~Work out the case of typing a sequence~~ - See what happens when a string literal wraps on multiple lines and how that interacts with layout Answer: string literals must be contained in a single line because of the offside rule; apparently the internal whitespace characters count as characters in the line, and so trigger the offside.
Author
Owner

Actually do the Haskell code generation in both ways:

A) Put a hashtable on every node and populate it with preamble and value and such,
then use the values from the hash at the top.

B) Make a dynamic rule Preamble: () -> string that is going to start out giving the empty string, and just accumulate in the value be resetting the rule. Basically just use the dynamic rule as a global variable.

Then ask on Slack which is "better".

Actually do the Haskell code generation in both ways: A) Put a hashtable on every node and populate it with preamble and value and such, then use the values from the hash at the top. B) Make a dynamic rule Preamble: () -> string that is going to start out giving the empty string, and just accumulate in the value be resetting the rule. Basically just use the dynamic rule as a global variable. Then ask on Slack which is "better".
Author
Owner

New approach:

A) Stick preamble lines onto a rule Preactions : () -> String, just constantly appending to the string.

B) Have the rule pass back just the value expression

C) Iterate with bottomup-para so the original expression is available as well as the value expression.

Hopefully that will allow everything to be expressed as easily as possible, with
just the minimal amount of propagation code.

New approach: A) Stick preamble lines onto a rule Preactions : () -> String, just constantly appending to the string. B) Have the rule pass back just the value expression C) Iterate with bottomup-para so the original expression is available as well as the value expression. Hopefully that will allow everything to be expressed as easily as possible, with just the minimal amount of propagation code.
glen added the
in progress
label 2021-02-16 17:52:56 +00:00
glen closed this issue 2021-02-18 04:17:05 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Reference: glen/fostr#5
No description provided.