|
I've been working on a complicated set of templates used to render state machines for matching text in various ways.
The templates are complicated because they allow for targeting multiple languages by plugging in new templates.
Prior, I was just making one template per target per option, so like SQL matching code vs C# matching code would be two templates.
Well now, it's many templates but, they're structured such that you're forced to basically produce the same code regardless of target (like C#, or SQL). For example, the following is the basic structure of a matching state machine in an language independent way.
a.Comment("Matches text based on a DFA table and block end DFA table");
a.MethodPrologue("None",true,"TableMatcherMatchReturn","TableMatch","TableMatcherMatchImplParams");
a.MatcherCreateResultList();
a.TableMatcherMatchDeclarations();
a.ReadCodePoint();
a.InputLoopPrologue();
a.MatcherResetMatch();
a.TableMachineLoopPrologue();
a.TableMove("dfa");
a.TableMachineLoopEpilogue();
a.TableAcceptPrologue();
a.TableIfBlockEndPrologue();
a.TableStateReset();
a.InputLoopPrologue();
a.TableMachineLoopPrologue();
a.TableMove("blockEnd");
a.TableMachineLoopEpilogue();
a.TableAcceptPrologue();
a.TableMatchYieldResult();
a.BreakInputLoop();
a.TableAcceptEpilogue();
a.TableRejectPrologue();
a.UpdateLineAny();
a.AppendCapture();
a.ReadCodepoint();
a.AdvanceCursor();
a.TableRejectEpilogue();
a.TableStateReset();
a.InputLoopEpilogue();
a.TableStateReset();
a.ContinueInputLoop();
a.TableIfBlockEndEpilogue();
a.TableIfNotBlockEndPrologue();
a.TableMatchYieldNonEmptyResult();
a.TableIfNotBlockEndEpilogue();
a.TableAcceptEpilogue();
a.UpdateLineAny();
a.ReadCodepoint();
a.AdvanceCursor();
a.TableStateReset();
a.InputLoopEpilogue();
a.MatcherReturnResultList();
a.MethodEpilogue();
where a in this case is a especial expando object (dynamic ) I built that resolves to template generation calls that are selected based on your target (like SQL or C#)
Sorry for all the code, it's just hard to explain without it.
I've basically imposed a structure over the flow the code so that it renders the same regardless of target because I was failing tests doing one target per template.
Unfortunately, this method yields dozens of templates per target, but at least my code is consistent.
I had to hack the crap out of my csppg tool to even make this work, but now it's pretty powerful.
I can do this:
<%@param name="docTemplate" type="string"%>
<%@param name="@private" type="bool"%>
<%@param name="returnTemplate" type="string"%>
<%@param name="methodName" type="string"%>
<%@param name="parametersTemplate" type="string"%>
To add parameters to my generator routines. I use this in MethodPrologue and TableMove above.
It's crazy code, folks. Just a zoo. But it works. I wish I had a better way to do this. It's a chore.
Real programmers use butterflies
modified 4-Nov-21 19:20pm.
|
|
|
|
|
If you are a developer then I'm a scammer. We can't be in the same profession, I'm guilty.
Do people start to do the kind of stuff you write about out of experience or there is some kind of oil that one has to smear on their fore head every morning.😑
|
|
|
|
|
I keep chickens, so that I have a supply of them to wave over my code while chanting. It helps.
Real programmers use butterflies
|
|
|
|
|
The proper incantations are important.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
Chickens only help fix mysterious bugs. There's gotta be a better explanation. I think you've got a familiar who channels exotic code to you from the Other Side.
If you think 'goto' is evil, try writing an Assembly program without JMP.
|
|
|
|
|
TNCaver wrote: Chickens only help fix mysterious bugs Sorry there dude/dudette, but that's rubber ducks[^], not chickens.
Software Zen: delete this;
|
|
|
|
|
loathsome criminal spied transmission (10)
|
|
|
|
|
loathsome
criminal CABLE (no idea why)
spied SPIED
transmission (anag)
DESPICABLE
I'm kinda hoping I'm way wrong ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
But the wrong derivation.
Criminal is the anagram indicator, and transmission clues for cable.
|
|
|
|
|
... to all those who celebrate it
Happiness will never come to those who fail to appreciate what they already have. -Anon
|
|
|
|
|
To you too. Hope I am not too late.
ed
|
|
|
|
|
Thanks!
Happiness will never come to those who fail to appreciate what they already have. -Anon
|
|
|
|
|
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
|
Sorry - I was busy fixing the kitchen after the small fire yesterday ... bloody new storage heaters ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Fire ! not serious I hope ?
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
No, I turned it on Tuesday for the first time and when I got back from dropping Herself off at work Wednesday morning the kitchen was lightly full of smoke. No sign of flames or a source, so I turned it off, opened all the windows and moved the sofa bed away from the radiator.
When the air had cleared I turned it back on and no sign of smoke for a couple of hours, or today. So it could be it was just full of dust and just heated it then blew it into the room, or the foam in the sofa got too hot.
I spent this morning reorganising so nothing flammable was near the radiator - and it's all heavy stuff to shift on your own!
No mains gas on the Ynys, so we're all electric heating. New, more efficient rads were installed this summer, but this was the first "in anger" usage, so I'm not too worried about fire risk, just taking sensible precautions.
I'd dump the sofabed - we never use it - but ... Herself.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Are you near Harlech ?
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
No, we're just south of the Brecon Beacons.
It's called the Ynys because it was between the river and the canal, before the latter was replaced with a (very necessary) town bypass.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Has anyone read the book "Modern Front-end Architecture" by Ryan Lanciaux?
I would like to hear your opinions about it.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Pardon me if I'm sounding ignorant but when I think about front-end that complex that it needs architecture I'm starting to become horrified thinking about the amount of javasrcipt transferred over the wire. Let alone the cases when some language like typescript or fable is compiled into js and introduces it's own additional code.
|
|
|
|
|
Good point.
Thank you
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
What I find amusing is when I create all these interfaces in TypeScript and it literally compiles down to a "no implementation" file in Javascript.
|
|
|
|
|
I'm hoping they mean "framework" rather than architecture.
Architecture is meant to be seen, it's the visible façade upon a framework.
|
|
|
|
|
You are right...
Thanks
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|