j kongertil
mountains and websites

til

Posts tagged with til

    How to match til the end of an input string with a janet peg

    aka a parsing expression grammar, aka the only reason i wanna use janet:

    to match all the rest of the content in a string, use this:

    (any 1)

    unlike most else i seen in PEGs, this is hella unclear. it literally means, more or less, match any amount of single characters, but god does that not help. instead, i think of it like “match anyone”: get anyone left.

    Janet PEGs don't accept unicode??

    nope! not easily, at least. you can match unicode characters, but NOTHING is made easy for you, the way a regex /u flag will. that said, its still possible with use of (to)

    look, for example, at a truncated version of a PEG i’m writing to pull info from a french/english dictionary:

    (def dict-result-peg
      ~{
        # ... catch some stuff
        :pronunciation (* "/" (to "/") "/")
        # ... and so on
       })
     

    i wanna catch all the character in the words IPA prnounciation, which luckily enough are surrounded by /s. since janets PEGs don’t allow for a character class range of unicode prononciation strings, i instead use a (to "/") to grab all the text between delimiters. it’s imprecise, but in this instance perfect, as i know ill never get a / in the prnonciation guide