Skip to content

Instantly share code, notes, and snippets.

@Varriount
Last active July 22, 2020 21:31
Show Gist options
  • Save Varriount/c74b32d19aaa484cacb2578d0d512658 to your computer and use it in GitHub Desktop.
Save Varriount/c74b32d19aaa484cacb2578d0d512658 to your computer and use it in GitHub Desktop.
_dsl = regexes.to_regex(r"""
(?(DEFINE)
# Divider for syntactical elements
(?P<syntax_edge> \s+ )
# Divider for statements
(?P<statement_edge> (?:
# A syntax edge
(
**syntax_edge
) |
# A comment
(
(?<!
( $ | [^\\] ) # A non-backslash
( (\\){2} ) # An even number of backslashes
)
[#] .*
) |
(*FAIL)
)+)
# Non-greedy all
(?P<ng_all>
(?:.|\n)+?
)
# A word
(?P<word> \w+ )
)
# NOTE \*\*(?P<name>\w+) gets replaced with (?& $NAME )
**statement_edge?
(
(
(?P<kind> REGEX )
**syntax_edge
(?P<name> **word)
**syntax_edge
(?P<pattern> **ng_all)
**syntax_edge
END
) |
(
(?P<kind> EXCLUDE_PATH )
**syntax_edge
(?P<pattern> **ng_all)
**syntax_edge
END
) |
(
(?P<kind> (((PRE|POST)_)?REPLACE))
**syntax_edge
(?P<pattern> **ng_all )
**syntax_edge
WITH
**syntax_edge
(?P<replacement> **ng_all )
**syntax_edge
END
) |
(
(?P<kind> (DEFINE))
**syntax_edge
(?P<macro> .+)
) |
(
(?P<kind> (UNDEFINE))
**syntax_edge
(?P<macro> .+)
) |
(
(?P<kind> (MAP TYPE))
**syntax_edge
(?P<macro> .+)
) |
(
(?P<kind> (MAP IDENTIFIER))
**syntax_edge
(?P<macro> .+)
) |
(
(?P<kind> (SUFFIX))
**syntax_edge
(?P<macro> .+)
) |
(
(?P<kind> (PREFIX))
**syntax_edge
(?P<macro> .+)
) |
(*FAIL)
)
**statement_edge?
""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment