This package offers both a portable {py3} module and a command-line
tool.
-WARNING: This version of Normand is 0.9, meaning both the Normand
+WARNING: This version of Normand is 0.10, meaning both the Normand
language and the module/CLI interface aren't stable.
ifdef::env-github[]
* Between the last item and the ``pass:[*]`` character of a post-item
repetition, and between that ``pass:[*]`` character and the following
number or expression.
-* Between the ``!repeat``/``!r`` prefix and the following constant
- integer, name, or expression of a repetition block.
-* Between the ``!if`` prefix and the following name or expression of a
- conditional block.
+* Between the ``!repeat``/``!r`` block opening and the following
+ constant integer, name, or expression of a repetition block.
+* Between the ``!if`` block opening and the following name or expression
+ of a conditional block.
A comment is anything between two ``pass:[#]`` characters on the same
line, or from ``pass:[#]`` until the end of the line. Whitespaces and
A group is:
-. The `(` prefix.
+. The `(`, `!group`, or `!g` opening.
. Zero or more items.
-. The `)` suffix.
+. Depending on the group opening:
++
+--
+`(`::
+ The `)` closing.
+
+`!group`::
+`!g`::
+ The `!end` closing.
+--
====
Input:
Input:
----
-((aa bb cc) * 3 dd ee) * 5
+!group
+ (aa bb cc) * 3 dd ee
+!end * 5
----
Output:
A conditional block is:
-. The `!if` prefix.
+. The `!if` opening.
. One of:
. Zero or more items.
-. The `!end` suffix.
+. The `!end` closing.
====
Input:
A repetition block is:
-. The `!repeat` or `!r` prefix.
+. The `!repeat` or `!r` opening.
. One of:
. Zero or more items.
-. The `!end` suffix.
+. The `!end` closing.
You may also use a <<post-item-repetition,post-item repetition>> after
some items. The form ``!repeat{nbsp}__X__{nbsp}__ITEMS__{nbsp}!end``
# Upstream repository: <https://github.com/efficios/normand>.
__author__ = "Philippe Proulx"
-__version__ = "0.9.0"
+__version__ = "0.10.0"
__all__ = [
"ByteOrder",
"parse",
return _Str(data, begin_text_loc)
# Patterns for _try_parse_group()
- _group_prefix_pat = re.compile(r"\(")
- _group_suffix_pat = re.compile(r"\)")
+ _group_prefix_pat = re.compile(r"\(|!g(roup)?\b")
+ _group_suffix_paren_pat = re.compile(r"\)")
# Tries to parse a group, returning a group item on success.
def _try_parse_group(self):
begin_text_loc = self._text_loc
# Match prefix
- if self._try_parse_pat(self._group_prefix_pat) is None:
+ m_open = self._try_parse_pat(self._group_prefix_pat)
+
+ if m_open is None:
# No match
return
# Expect end of group
self._skip_ws_and_comments()
- self._expect_pat(
- self._group_suffix_pat, "Expecting an item or `)` (end of group)"
- )
+
+ if m_open.group(0) == "(":
+ pat = self._group_suffix_paren_pat
+ exp = ")"
+ else:
+ pat = self._block_end_pat
+ exp = "!end"
+
+ self._expect_pat(pat, "Expecting an item or `{}` (end of group)".format(exp))
# Return item
return _Group(items, begin_text_loc)
[tool.poetry]
name = 'normand'
-version = '0.9.0'
+version = '0.10.0'
description = 'Text-to-binary processor with its own language'
license = 'MIT'
authors = ['Philippe Proulx <eeppeliteloop@gmail.com>']
--- /dev/null
+!group aa bb cc "yeah"
+---
+2:1 - Expecting an item or `!end` (end of group)
--- /dev/null
+!group aa bb cc )
+---
+1:17 - Expecting an item or `!end` (end of group)
+++ /dev/null
-( aa bb cc "yeah"
----
-2:1 - Expecting an item or `)` (end of group)
--- /dev/null
+( aa bb cc "yeah"
+---
+2:1 - Expecting an item or `)` (end of group)
--- /dev/null
+( aa bb cc !end
+---
+1:12 - Expecting an item or `)` (end of group)
--- /dev/null
+!g $1 $2 $3 !end * 2
+---
+01 02 03
+01 02 03
--- /dev/null
+00 !group 11 <meow> 22 {mix-meow:8} 33 <mix> 44 !end * 2 55
+---
+00
+11 22 03 33 44
+11 22 03 33 44
+55
--- /dev/null
+00
+!group
+ 11 {mix:8} 22 <mix>
+ !group
+ <meow> {meow + mix : 8}
+ !end * 3
+ 33
+!end * 2
+44
+---
+00
+
+11 04 22
+ 08
+ 09
+ 0a
+33
+
+11 0b 22
+ 16
+ 17
+ 18
+33
+
+44
--- /dev/null
+00 <outer>
+!group
+ 11 <inner> 22 {outer:8} {inner:8} {end:8}
+!end * 3
+<end> ff
+---
+00
+ 11 22 01 02 10
+ 11 22 01 07 10
+ 11 22 01 0c 10
+ff
--- /dev/null
+00
+!group
+ 11 22 33
+ !group
+ aa bb cc
+ !end
+!end
+dd
+---
+00 11 22 33 aa bb cc dd
+++ /dev/null
-00 (11 <meow> 22 {mix-meow:8} 33 <mix> 44) * 2 55
----
-00
-11 22 03 33 44
-11 22 03 33 44
-55
+++ /dev/null
-00 (11 {mix:8} 22 <mix> (<meow> {meow + mix : 8}) * 3 33) * 2 44
----
-00
-
-11 04 22
- 08
- 09
- 0a
-33
-
-11 0b 22
- 16
- 17
- 18
-33
-
-44
+++ /dev/null
-00 <outer> (11 <inner> 22 {outer:8} {inner:8} {end:8}) * 3 <end> ff
----
-00
- 11 22 01 02 10
- 11 22 01 07 10
- 11 22 01 0c 10
-ff
+++ /dev/null
-00 (11 22 33 (aa bb cc)) dd
----
-00 11 22 33 aa bb cc dd
--- /dev/null
+00 (11 <meow> 22 {mix-meow:8} 33 <mix> 44) * 2 55
+---
+00
+11 22 03 33 44
+11 22 03 33 44
+55
--- /dev/null
+00 (11 {mix:8} 22 <mix> (<meow> {meow + mix : 8}) * 3 33) * 2 44
+---
+00
+
+11 04 22
+ 08
+ 09
+ 0a
+33
+
+11 0b 22
+ 16
+ 17
+ 18
+33
+
+44
--- /dev/null
+00 <outer> (11 <inner> 22 {outer:8} {inner:8} {end:8}) * 3 <end> ff
+---
+00
+ 11 22 01 02 10
+ 11 22 01 07 10
+ 11 22 01 0c 10
+ff
--- /dev/null
+00 (11 22 33 (aa bb cc)) dd
+---
+00 11 22 33 aa bb cc dd
-((aa bb cc) * 3 dd ee) * 5
+!group
+ (aa bb cc) * 3 dd ee
+!end * 5
---
aa bb cc aa bb cc aa bb cc dd ee aa bb cc aa bb
cc aa bb cc dd ee aa bb cc aa bb cc aa bb cc dd