Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macros and backticks #101

Open
BeastyBlacksmith opened this issue Jul 21, 2022 · 5 comments
Open

Macros and backticks #101

BeastyBlacksmith opened this issue Jul 21, 2022 · 5 comments

Comments

@BeastyBlacksmith
Copy link

It seems that

  1. macros don't get expanded inside backticks (single or triple)
  2. you can't use backticks inside of macros, e.g.
<!--
@m: '```\n' + @0 + '\n```\n'
-->
# Test

@m(Test)
@andre-dietrich
Copy link
Member

Hi, macros in LiaScript are a simple text substitution not strings as in programming languages. What you want is something like

<!--

@mm
``` @0
@1
```
@end

-->

# Course Main Title

@mm(python,`print('Hallo Welt')`)

``` @mm(python)
# hallo Welt

print(12)
```

I think for some reason, a macro name must be longer than one character. And if you want to have new lines, it is better to use the definition type with @end...

I tried to explain the definition of macros here:

https://liascript.github.io/course/?https://raw.githubusercontent.com/liaScript/docs/master/README.md#163

I hope this helps ;-)

@BeastyBlacksmith
Copy link
Author

Would it be possible to construct the same output using javascript?

I tried

<!--

@mm
<script>
"LIASCRIPT:" + "```" + "@0\n" + "@1" + "\n```\n"
</script>
@end

-->

@andre-dietrich
Copy link
Member

andre-dietrich commented Jul 21, 2022

It should be ... what is problematic in this case, is that you have to add some styling. You have to display it as a block otherwise the code will not be visible ... For me, the following macro did the job ...

@mm2
<script style="width:100%; display:block">
`LIASCRIPT: 
\`\`\` @0
@1
\`\`\`
`
</script>
@end

Scripts are inline elements, that is why they are rendered within a span. This works fine, if scripts are small members within a text, etc. But when larger elements are created, this styling has to be applied 🙈

@BeastyBlacksmith
Copy link
Author

I'm not sure I understand how composition of macros works when backticks are involved.
If i have one macro returning a string, and the old @mm macro:

<!--
@mm
``` @0
@1
```
@end

@tt
<script style="width:100%; display:block">
'LIASCRIPT: # ' + @0
</script>
@end
-->

Then @mm(python, @tt(1)) creates a huge box until the next triple backticks including

 <script style="width:100%; display:block">
'LIASCRIPT: # ' + 
```)

And if I change @mm to

@mm
``` @0
@tt(@1)
```
@end

I get a box with @tt( 1).

@andre-dietrich
Copy link
Member

andre-dietrich commented Jul 23, 2022

Hi, this is a bit more complicated, the problem is that macros are not like in programming languages, it only deals with strings, it uses only the characters , to separate parameters and ) to find the end or the param-list. We tried to stick with the Markdown-syntax, if you want to pass a macro as input that also has some parameters you need to put it into backticks:

@example(_This is a longer param_,`@t1(some more stuff, with commas)`,``` some very long param

with some 

new lines
...
```)

in your case surrounding @tt with simple backtics will not work, since the result is an output with multiple lines, that is why triple backtics are required to surround this macro, otherwise it will search for a closing parenthesis within the same line ... and fail ...

@mm3
``` @0
@1
```
@end

@tt
<script style="width:100%; display:block">
'LIASCRIPT: # ' + @0
</script>
@end

-->

# Course Main Title

@mm3(python,```@tt(1)```)

The algorithm goes like this. When a macro is identified, its parameters are checked, if it contains some macros, then these are evaluated, in the same way (recursively), if the result-string is ready, it injected at the position it is called within your macro definition ... Sub macros are only evaluated immediately if they are parameters, you macro definition might contain further but these are ignored until the parser reaches them ... It is a pretty simple and "mighty" approach. We have created this originally to deal with replication in its simplest way and thought complex stuff should still be done with javascript ...

You can have a look at https://github.com/topics/liascript-template for some inspiration, in nearly all cases here are some more complex macros are defined ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants