Skip to content

Case Insensitive Literals #40

Answered by drhagen
dennis-barrett asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah, you need to use reg for this:

from parsita import *

class CaseInsensitiveParsers(TextParsers):
  for_parser_reg = reg('(?i)for')

CaseInsensitiveParsers.for_parser_reg.parse('FOR').or_die() # also works

This seems pretty ergonomic to me, but if you have a lot of these you could make a helper function:

from parsita import *

def cilit(token: str) -> Parser[str, str]:
    return reg("(?i)" + token)

class CaseInsensitiveParsers(TextParsers):
  for_parser_cilit = cilit('for')

CaseInsensitiveParsers.for_parser_cilit.parse('FOR').or_die() # also works

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dennis-barrett
Comment options

Answer selected by dennis-barrett
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants