Fork me on GitHub
#babashka
<
2020-02-13
>
jeroenvandijk11:02:23

Thank you for your talk last night @borkdude! Nice to hear the background story of all the things you have created 🙂 Great job!

borkdude11:02:56

Thanks and thanks for coming 🙂

sogaiu12:02:56

i don't suppose there are recordings or slides we can see?

borkdude12:02:34

I'll post the slides after ClojureD

👍 1
jeroenvandijk13:02:28

@borkdude when you wrote edamame did you consider using an instaparse parser? I'm considering this now, but I wonder if there might be problems with Graalvm

borkdude13:02:27

I never considered it for edamame considering how slow it is

borkdude13:02:52

it's fine for small snippets but not for parsing large files

borkdude13:02:21

what do you need it for if I may ask?

jeroenvandijk13:02:35

I'm trying to write a php parser 🙂

jeroenvandijk13:02:02

The prototype can be slow

jeroenvandijk13:02:08

Also edamame misses some cases

borkdude13:02:24

what cases does it miss

jeroenvandijk13:02:05

🙂 I am not worried

jeroenvandijk13:02:26

Actually it doesn't miss anything, but it doesn't give me enough information

borkdude13:02:12

what information do you need

jeroenvandijk13:02:16

e.g.`(edamame/parse-string "(((" {:all true})` doesn't tell me how many brackets are open

jeroenvandijk13:02:46

I'm worried that I spend too much time on a parser that I will never use, but good point anyway

borkdude13:02:07

what is an example of what you are trying to parse? are you parsing html, or clojure code or a mix?

borkdude13:02:14

do you just need templating?

jeroenvandijk13:02:12

fooo <?php (if (> 1 10000) ?> 1 is not bigger than 1000 <? ?> 1 is smaller than 10000  <?php ) ?>

jeroenvandijk13:02:24

the basics are simple. The tricky part is when you have to count open brackets etc

borkdude13:02:29

it's probably very close to reader conditionals

borkdude13:02:54

parsing-wise I mean

borkdude13:02:05

you could just try forking edamame and customize it

borkdude13:02:42

then you will know for sure it works with graalvm, I'm not sure about instaparse

jeroenvandijk13:02:43

Does edamame give a lazy sequence?

borkdude13:02:05

why do you need a lazy sequence?

jeroenvandijk13:02:08

Because given the "performance first", the biggest performance hit is reading strings 🙂

jeroenvandijk13:02:26

If you have a big template you just want to flush stuff

borkdude13:02:58

you don't need a lazy sequence per say, you can just use a read-next from the stream kind of construction

borkdude13:02:08

which is more idiomatic for parsing things

borkdude13:02:24

e.g. clojure.edn/read

jeroenvandijk13:02:26

yes sorry that's what I mean. Does edamame have that?

borkdude13:02:51

but not in the public API. you can just use it like it's used in sci / babashka though, they use it

borkdude13:02:03

e.g. for the REPL

borkdude13:02:18

all top level forms are parsed one by one actually, not the entire file at once

borkdude13:02:30

there is an issue to make this public, I just haven't done it yet

borkdude13:02:30

there is an issue to make this public, I just haven't done it yet

mauricio.szabo17:02:21

This could be useful for tooling. For example, at Chlorine I'm currently using rewrite-cljs to be able to parse Clojure code and detect "blocks and top-blocks" but it can be slow...

borkdude17:02:41

yes, it's definitely handy

borkdude17:02:59

feel free to try it out

jeroenvandijk13:02:24

ah cool good to know

borkdude13:02:46

note that edamame only parses clojure code, I don't know what stuff you are parsing outside the templating things

jeroenvandijk13:02:10

hmmm ok than it doesn't work

jeroenvandijk13:02:25

everything outside of <?php ?> tags can be anything

jeroenvandijk13:02:36

and between as well

borkdude13:02:46

> than it doesn't work yeah, that's why I suggested forking edamame so you can just skip until the first templating part, etc, make tweaks

jeroenvandijk13:02:46

ah awesome, that looks useful

borkdude14:02:01

alternatively you can use edamame within your own parser. when you first parse until after the first <?php in your own parsing logic and then invoke edamame on the same reader, etc, that should also maybe work

jeroenvandijk14:02:17

That's my current implementation. It becomes difficult with nested sexpressions and tags

jeroenvandijk14:02:37

so simple cases work, but when you start doing things like <? (if foo ?> a <? (if bar ?> that <? )) ?> it becomes more difficult. You also need to count the brackets for proper error messages. My current approach is to collect the string and evaluate after the closing ?>. The parser for this is so big that my repl didn't like it. So I thought maybe i should try instaparse 🙂

jeroenvandijk14:02:33

Maybe I should use instaparse to collect the tags and the rest with edamame for the proof of concept

borkdude14:02:36

good luck 😉

borkdude14:02:15

maybe the hiccup approach isn't a bad idea after all?

jeroenvandijk14:02:33

Probably a better idea indeed

jeroenvandijk14:02:49

But that has other downsides

jeroenvandijk14:02:07

I'll not give up yet

borkdude14:02:18

fwiw bootleg does html templating as a CLI using sci: https://github.com/retrogradeorbit/bootleg

borkdude14:02:28

I wanted to mention that in my talk, but no time

jeroenvandijk14:02:06

I'll have a look. Thanks!

Crispin14:02:50

bootleg maker here. hi!

Crispin14:02:32

bootleg doesn't really do that php escapey thing itself. If you were using bootleg you would do that in a template, like a selmer template, which bootleg supports

Crispin14:02:47

or you can do conditionals within your hiccup

borkdude15:02:41

^ @jeroenvandijk

jeroenvandijk15:02:44

Ah thanks for confirming @retrogradeorbit

jeroenvandijk15:02:09

Did you build the bootleg templating to be super performant or is it more a convenience tool exploiting the quick boot time of Graalvm?

Crispin15:02:57

it is very performant but that was not an aim. Startup time was essential, though.

👍 1
Crispin15:02:51

I built it because I wanted to build static websites. I appraised all the existing (mostly JS) static site builders and was frustrated by their complexity.

Crispin15:02:02

They all wanted me to learn a whole bunch of things particular to their framework. I didn't want to learn anything new. So I thought, if only I had a command line tool that would just take hiccup and render it as html. That's most of what I need.

Crispin15:02:45

It was also a project for me to experiment with the technology stack. To combine graal native images with @borkdude s sci project and put it through its paces.

Crispin15:02:18

If you do end up using it and the source of your site is open source then I would love to expand the example section.

Crispin15:02:55

I know of a few people using it but for commercial sites and they are unwilling to opensource their code.

borkdude15:02:21

I might use it when I have some time and enough motivation to get off my jekyll thing

borkdude15:02:00

or octopress, I don't even remember what I'm using

Crispin15:02:33

There are so many! Yet another static site generator.

jeroenvandijk15:02:41

Thanks for explaining @retrogradeorbit

borkdude15:02:42

I might also do my personal website in it, since it's just a single html file which I edit manually (last update 3 years ago)

Crispin15:02:39

Oh the other motivation was to combine markup. So I had a site template already done by a designer. Html and CSS and some JS. And I had expanded his JS (jquery)

Crispin15:02:50

I didnt want to redo any of it

Crispin15:02:04

I just wanted to inject hiccup generated code into it

Crispin15:02:43

so its good at letting you mash together a bunch of different formats, styles, templates and glue it all together

jeroenvandijk15:02:14

Ok I have something working. I've written it in a true php spaghetti code style as well https://gist.github.com/jeroenvandijk/fb4cafb5022cead538cde1c7c6e39c4d 😎

👌 1
jeroenvandijk16:02:10

I've added a case that is currently not catched by Sci. https://github.com/borkdude/sci/pull/265/files Thinking about it a bit more validation the AST before running it might make more sense?

borkdude16:02:59

Sure, I'll take a look at it later

borkdude16:02:19

left some feedback

jeroenvandijk17:02:51

ok cool, fixed it i think

borkdude17:02:34

merged

👍 1
borkdude19:02:08

$ bb '(if 1 2 3 4)'
clojure.lang.ExceptionInfo: Too many arguments to if [at line 1, column 1]

2