Created
January 22, 2020 21:09
-
-
Save aurynn/dd9b2d652911c97874d6d27a61e86e4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyparsing import Word, Literal, alphas, alphanums, stringStart, ParserElement, ZeroOrMore,OneOrMore, Forward, Dict, Group, pythonStyleComment, lineStart, lineEnd, FollowedBy, dictOf, oneOf, NotAny, Regex | |
import re | |
DEBUG=True | |
ce = """custom_tooltip = { | |
fail_text = INVALID_RIVAL_DESC | |
is_country_type = default | |
} | |
""" | |
annotation_label = ParserElement.suppress(lineStart) + \ | |
ParserElement.suppress(Literal("#")) +\ | |
Word(alphas) | |
annotation_value = oneOf("= :").suppress() +\ | |
Word(alphas) +\ | |
ParserElement.suppress(lineEnd) | |
annotation = dictOf(annotation_label, annotation_value) | |
comment = lineStart.suppress() + pythonStyleComment | |
label = Word ( alphas + "_" ) | |
# + Literal("{").suppress() | |
# Defining a name | |
define = label + Literal ( "=" ).suppress() | |
block_open = Literal("{").suppress() | |
block_close = Literal("}").suppress() | |
# +"<"+"="+">" | |
# Nested literal? | |
lit = Word( alphanums + "_" ) | |
lit.setDefaultWhitespaceChars(" \t\n") | |
# literal = OneOrMore( lit ).setDebug(flag=DEBUG) + lineEnd.setDebug(flag=DEBUG) | |
# assign_literal = literal.setDebug(flag=DEBUG) | |
assign_literal = Regex(r"[a-zA-Z_ ]+^") | |
block = Forward() | |
exprs = dictOf(define.setDebug(flag=DEBUG), block ^ assign_literal) | |
block << block_open + OneOrMore(exprs) + block_close | |
exprs.parseString(ce) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment