Q: Do we have a Custom Parser?

Parsers do a lot of the heavy-lifting in TW.

Is there a plugin yet that eases the creation of Custom Parsers?

Use Case: I would love a TW Custom Parser.
Written, I guess, in JS (JavaScript / ECMA-###)
To provide any number of pairs of these regex string replacers …


// Regex ...

     match: /baz/ig
   replace: /foo/

     match: /@fred/im
   replace: /Fred Smith/

etc.

Repeated - i.e. as many string replacement pairs as needed.
Without having to code in JS?

Has this been done already?
A query, TT.


P.S. -- @TiddlyTweeter --> @Springer
// Regex ...
       match: /@TiddlyTweeter/ig
     replace: /@Springer/

cc: @Springer @TW_Tones

It’s already in the TWCore. See https://tiddlywiki.com/#search-replace%20Operator
Examples:

{{{ [[some input text]] +[search-replace:ig:regexp[baz],[foo]] }}}
{{{ [[some input text]] +[search-replace:im:regexp[@fred],[Fred Smith]] }}}

enjoy,
-e

1 Like

Possibly related: Pretty fractions. It discussed two ways of adding parsing to wikitext. It sounds like Eric’s solution is what you need, but if you’re looking to do this at tiddler render time, those techniques may help.

2 Likes

I have also written parsers for data tiddlers by using list widget and filters to splitregexp[\n] then act on each line.

  • I suppose the issue is Parsers in one form or another is a common code pattern.

Deeper view;

As you may be aware a key parser function is used for wikitext. If you search shadows for parser you get to see the many already in use for example $:/core/modules/parsers/wikiparser/rules/dash.js
depending on your skills cloning one of these and modifying the code you can make a new parser, however keep in mind it would take a lot of effort to make something you could share.

But I do like your idea of an easy parametrized parser, but it could be somewhat risky, to use.

Common Fundamental


01001111 01110100 01101000 01100101 
01110010 01110111 01101001 01110011 
01100101 00100000 01110100 01101000 
01101001 01110011 00100000 01101001 
01110011 00100000 01110111 01101000 
01100001 01110100 00100000 01111001 
01101111 01110101 00100000 01100111 
01100101 01110100

Binary to Text Translator

And for the full list, just Advanced Search > Fitler > [all[tiddlers+shadows]module-type[wikirule]]

1 Like

That is v. useful to decko ...

(word: decko)

Definitely my final aim is: RENDER it already!

My handicap is I really don’t wanna understand JS.
'Cause I’m slow and “I only need to do this once.

BUT I do know enough that it should be possible to write a parser in JS that at the start has a JSON structure kinda like this … (in foobar-ese)

[
/groggins/ig → /neddy/
/Fred Flintstone/mg → /Elon Musk/
/Supreme Leader/ig → /Jeremy Ruston/
/\b\w(confusing|confus[ea]d)\b\s/ → /***Neggie/
]

Each replacement read in turn and applied.

How it works to actually do it I doubt I could grasp, or want to,

Just equip me with a loop to do a “render / replace” I’d be as happy as a sandboy.

I could edit the JSON data bit well okay.

You get the idea?
Ever hopeful.
TT. x

1 Like

This seems to still work:

http://tiddlystuff.tiddlyspot.com/#ReplacePragma

2 Likes

@TiddlyTweeter

I know “took a Deco”, “Have a Deco” but “useful to Deco” does not sound right for the lingo. The other references are “alien to me”, interesting in exposing me to other “cultures” close to my own. Although I did not watch “ello.ello” when it was on the Air, and had a French Partner since, and learned some of the Language so now it just not very funny for me, don’t get me wrong, I have had plenty of laughs with the language, for example “In France do people secretly piss in the piscine, or urinate in the urinoir”?

No Seriousely;

As illustrated by @buggyj what aspect of parser are you after?

  • Something that converts one thing to another at render time
  • Something to search and replace something with another
  • Something else I cant remember at this moment?

@TiddlyTweeter I stumbled on this that may be of interest to someone with regular expression skills

1 Like

Both. I am after several things. All related to regex.

As far as the parser bit goes I’m most interested in seeing if I can get a parser that I can easily edit with multiple sets of transient “render” replacers. For short term use (to help me better, quicker, understand imported documents.)

@buggyj’s Flexity parser, which I used before, is extremely helpful to study.

Tx for your interest
TT

I understand that you have a desired result. But this thought came to me;

So this would mean you have some text including wiki text and possibly TiddlyWiki Script, that as a rule is rendered a particular way. However you wish to provide a set of rules that transforms the text prior to rendering to generate a result with that set rules applied but don’t modify the underlying text.

  • These are on demand transformations “transient” and thus writing actual code parsers would be too demanding.

Would this not be equivalent to?;

  • copy the tiddler to a temp tiddler, apply multiple changes and render?
  • If necessary display the rendered tiddler as if it were in the source tiddler.

Just Curious