wwall
2019-11-26 08:48:40

hello. question - exists simple way for read xml into structures? f.e if i have xml file

<data> <f>1</f> <s> <d>1</d> <d>2</d> </s> </data> i want to get structure with field f and s may be somebody write code which cjnvert xml into structure


laurent.orseau
2019-11-26 08:56:56

Maybe take a look at the xml module? https://docs.racket-lang.org/search/index.html?q=xml


wwall
2019-11-26 08:58:19

xml convert into xexpr whrn read file. but i think what exists simple way for convert xexpr into strucutre


soegaard2
2019-11-26 11:01:23

Thanks.


sorawee
2019-11-26 15:20:14

@wwall I don’t think that’s possible. Your XML data is known at runtime, but structure definition must be known at compile-time.


capfredf
2019-11-26 18:16:54

@wwall actually, you can produce a struct definition at run-time using make-struct-type. But I think mapping a xml data to a struct and providing user-friendly accessors need extra work


elyandarin
2019-11-26 19:50:51

Hi! I’m currently defining what a string is in my tokenizer, and I’m not certain how I should tell the lexer to ignore escaped quotes when defining string boundaries. I got the impression that using regexps for this stuff is considered to be suboptimal, so is there a proper way I should do it?


laurent.orseau
2019-11-26 20:26:30

See my answer to your previous question ;)


shu--hung
2019-11-26 20:31:33

are you using a lexer library like this language does? https://github.com/tov/dssl2/blob/master/private/lexer.rkt


notjack
2019-11-26 20:39:55

Is there a way I can put interactive (or at least animated) diagrams in a Scribble document?


elyandarin
2019-11-26 20:50:17

I’m using pretty basic stuff, more or less from the beautifulracket tutorial: #lang br/quicklang (require brag/support) (require parser-tools/lex-sre)


elyandarin
2019-11-26 20:54:18

@laurent.orseau with-input-from-string definitely seems closely related to what I want, but unfortunately as a lisp/bracket newbie, I’m not sure how to implement it.


shu--hung
2019-11-26 21:03:09

I think the last example at the end of 2.2 is a way to go https://docs.racket-lang.org/brag/index.html?#(part._.Parsing_the_concrete_syntax)


elyandarin
2019-11-26 21:05:51

I’ll check it out, thanks!


samth
2019-11-26 21:05:53

put a gif in?


shu--hung
2019-11-26 21:06:21

also, the grammar for the RE language at each clause in lexer-src-pos is here: https://docs.racket-lang.org/br-parser-tools/Lexers.html


soegaard2
2019-11-26 21:07:31

The alternative is an svg animation. https://css-tricks.com/guide-svg-animations-smil/


shu--hung
2019-11-26 21:07:48

it’s basically regular expressions, but written using the syntax concatenation , union, complement, etc


deactivateduser60718
2019-11-26 21:08:08

How much flexibility do you get if you override render-other for an HTML-specific renderer? https://docs.racket-lang.org/scribble/renderer.html#%28meth._%28%28%28lib._scribble%2Fbase-render..rkt%29._render~25%29._render-other%29%29

Could you do <video> elements plus all the other approaches that way?


sydney.lambda
2019-11-26 21:15:00

Do you mean, so you can have quotes-in-quotes? like string = “He said "hi"” or something like that?


shu--hung
2019-11-26 21:15:04

the difference between writing lexers using REs in lexer-src-pos versus repeatedly calling regexp-match is that lexer-src-pos (iiuc) combines the REs together and build a DFA so there’s no overhead


elyandarin
2019-11-26 21:15:24

@sydney.lambda exactly!


elyandarin
2019-11-26 21:17:39

currently, I’m using (from/to """ """) which just gives me "He said "


sydney.lambda
2019-11-26 21:19:24

I’m no expert by any means, and I’m not sure if this is a good solution for you, but if you were writing a recursive-descent-parser, you could enter a “quoted string” munching function/state upon encountering the first double-quote. From within this state, whenever you encounter a backslash, you would throw it away, consume whatever token is next, add it to the string token being created, and then carry on munching away. Think of it like a state machine.


sydney.lambda
2019-11-26 21:20:13

Here’s a great example of one soegaard put together to help me a while ago: http://pasterack.org/pastes/12032 hopefully that might help a bit.


elyandarin
2019-11-26 21:20:33

I’ll look at it, thanks!


sydney.lambda
2019-11-26 21:21:34

No worries. There’s also parsack/megaparsack to try. I couldn’t get away with lex/yacc, but maybe you’ll have more joy with them. Good luck either way :)


notjack
2019-11-26 21:37:23

Svg sounds like a decent plan


sydney.lambda
2019-11-26 21:58:11

@elyandarin I’m very rusty with lexers, but this hopefully gives an idea of what I meant: https://gist.github.com/dys-bigwig/76d0e87805bfc34ad8fce1a4cae85330


sorawee
2019-11-27 01:09:39

@elyandarin I implemented exactly what you are looking for as a part of my language using lexer-src-pos:

[(:: "\"" (:* (:or (:~ "\"" "\\") (:: "\\" any-char))) "\"") (token 'STRING (trim-ends "\"" lexeme "\""))]


sorawee
2019-11-27 01:11:38

This says: consume " , and repeatedly consume either (1) any \x for any x ; or (2) anything that is neither " nor \ . At the end, consume " .


sorawee
2019-11-27 01:15:52

There’s nothing wrong with using regex. In fact, the regex that we are using here is the real mathematical regex which is possible to handle efficiently, unlike Perl-like regex which has weird features.


alik
2019-11-27 01:48:37

@alik has joined the channel