xi2

a plain text language that compiles to MIDI
git clone https://git.ce9e.org/xi2.git

commit
4960e95bb293eacd6aceec37e4812500d45d2cb5
parent
12c937667220a3d351f9279e99ffbc4dc0fc5486
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-09-19 08:17
swap meaning of {} and ()

in python, {} indicates (unordered) sets. This fits better with chords.

Diffstat

M iparser.py 8 ++++----
M xi2.py 12 ++++++------

2 files changed, 10 insertions, 10 deletions


diff --git a/iparser.py b/iparser.py

@@ -42,12 +42,12 @@ class IParser:
   42    42                     self.stop()
   43    43                 self.stack.append(e)
   44    44                 self.parse_el(e)
   45    -1             elif isinstance(e, list):
   -1    45             elif isinstance(e, set):
   46    46                 if '-' not in e:
   47    47                     self.stop()
   48    48                 self.stack.append(e)
   49    49                 self.parse_set(e)
   50    -1             elif isinstance(e, tuple):
   -1    50             elif isinstance(e, list):
   51    51                 self.parse_seq(e)
   52    52             else:
   53    53                 raise ValueError("unknown element: " + e)
@@ -78,7 +78,7 @@ class IParser:
   78    78                 self.dt = 0
   79    79             else:
   80    80                 pass
   81    -1         elif isinstance(e, list):
   -1    81         elif isinstance(e, set):
   82    82             if '-' in e:
   83    83                 self.stop()
   84    84             for ee in e:
@@ -92,7 +92,7 @@ class IParser:
   92    92 
   93    93 
   94    94 if __name__ == '__main__':
   95    -1     a = [(('0', '1'), '2'), '4', '5', '-', '', ['0', '4', '7'], '', '', '0', ['3', '-']]
   -1    95     a = [[['0', '1'], '2'], '4', '5', '-', '', {'0', '4', '7'}, '', '', '0', {'3', '-'}]
   96    96     t = midi.Midi()
   97    97     ip = IParser(t, a, 0, 60)
   98    98 

diff --git a/xi2.py b/xi2.py

@@ -11,16 +11,16 @@ def parse(t):
   11    11     string = ''
   12    12     stack = [[]]
   13    13     for c in t:
   14    -1         if c == '{':
   15    -1             stack.append([])
   16    -1         elif c == '}':
   17    -1             stack[-1].append(string)
   18    -1             string = tuple(stack.pop())
   19    -1         elif c == '(':
   -1    14         if c == '(':
   20    15             stack.append([])
   21    16         elif c == ')':
   22    17             stack[-1].append(string)
   23    18             string = stack.pop()
   -1    19         elif c == '{':
   -1    20             stack.append([])
   -1    21         elif c == '}':
   -1    22             stack[-1].append(string)
   -1    23             string = set(stack.pop())
   24    24         elif c == ',':
   25    25             stack[-1].append(string)
   26    26             string = ''