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
Maybe take a look at the xml module? https://docs.racket-lang.org/search/index.html?q=xml
xml convert into xexpr whrn read file. but i think what exists simple way for convert xexpr into strucutre
Thanks.
@wwall I don’t think that’s possible. Your XML data is known at runtime, but structure definition must be known at compile-time.
@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
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?
See my answer to your previous question ;)
are you using a lexer library like this language does? https://github.com/tov/dssl2/blob/master/private/lexer.rkt
Is there a way I can put interactive (or at least animated) diagrams in a Scribble document?
I’m using pretty basic stuff, more or less from the beautifulracket tutorial: #lang br/quicklang (require brag/support) (require parser-tools/lex-sre)
@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.
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)
I’ll check it out, thanks!
put a gif in?
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
The alternative is an svg animation. https://css-tricks.com/guide-svg-animations-smil/
it’s basically regular expressions, but written using the syntax concatenation
, union
, complement
, etc
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?
Do you mean, so you can have quotes-in-quotes? like string = “He said "hi"” or something like that?
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
@sydney.lambda exactly!
currently, I’m using (from/to """ """) which just gives me "He said "
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.
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.
I’ll look at it, thanks!
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 :)
Svg sounds like a decent plan
@elyandarin I’m very rusty with lexers, but this hopefully gives an idea of what I meant: https://gist.github.com/dys-bigwig/76d0e87805bfc34ad8fce1a4cae85330
@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 "\""))]
This says: consume "
, and repeatedly consume either (1) any \x
for any x
; or (2) anything that is neither "
nor \
. At the end, consume "
.
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 has joined the channel