Skip to content

Commit 2bbb1c1

Browse files
committed
Add some adjustments
1. 删除了Storage标签 2. 将和弦符号与和弦操作符整合成Chord 3. 修复了倚音不能正常tok的bug
1 parent d178645 commit 2bbb1c1

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

Lib/Tokenizer.wl

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(* ::Package:: *)
22

33
(* ::Input:: *)
4-
(*StringMatchQ[",",RegularExpression["\\,"]]*)
4+
(*StringMatchQ["&",RegularExpression["[^\\{\\}]*"]]*)
55

66

77
BeginPackage["SMML`Tokenizer`"];
@@ -11,13 +11,12 @@ rep[pat_]:=rep[pat,","~~" "...];
1111
rep[pat_,sep_]:=pat~~(sep~~pat)...;
1212
repRegex[pat_]:=repRegex[pat,", *"];
1313
repRegex[pat_,sep_]:=RE[pat<>"("<>sep<>pat<>")*"];
14-
sel[pat_RegularExpression]:=RE["("<>pat[[1]]<>")?"];
14+
sel[pat_]:=RE["("<>pat[[1]]<>")?"];
15+
or[pat__]:=RE["("<>StringRiffle[#[[1]]&/@{pat},"|"]<>")"];
1516
unsigned=RE["\\d+"];
1617
signed=RE["[\\+\\-]\\d+"];
1718
integer=RE["[\\+\\-]?\\d+"];
1819

19-
chordCodePos=RE["([\\+\\-]?\\d+)?"];
20-
chordCodeSft=RE["([\\+\\-]\\d+)?"];
2120
chordCodeTok[str_]:=StringCases[str,
2221
StringExpression[
2322
ntt:LetterCharacter~~"\t"..,
@@ -66,7 +65,7 @@ postOperator="``"|"`"|"";
6665
volOperator=(">"|":")...;
6766
pitOperator=("#"|"b"|"'"|",")...;
6867
durOperator=("."|"-"|"_"|"=")...;
69-
scaleDegree="0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"%"|"x";
68+
scaleDegree=RE["[0-7%x]"];
7069

7170
number=integer~~""|("."~~unsigned);
7271
expression=(integer~~""|("/"|"."~~unsigned))|("Log2("~~unsigned~~")");
@@ -81,7 +80,7 @@ orderTok=Union@@StringCases[#,{
8180
n:integer~~"~"~~m:integer:>Range[ToExpression@n,ToExpression@m],
8281
n:integer:>{ToExpression@n}
8382
}]&;
84-
notationPadded=Whitespace|"|"|"/"|"^"|"&"|"*";
83+
notationPadded=RE["[&\\|\\s\\^\\*]*"];
8584
notationPatt=Alternatives[
8685
"+"|"ToCoda"|"Coda"|"s"|"Segno"|"DC"|"DaCapo"|"DS"|"DaSegno",
8786
"||:"|":||"|("["~~orderListP~~".]"),
@@ -166,7 +165,7 @@ Tokenizer[filepath_]:=Block[
166165
][line];
167166
If[contextData!={},
168167
syntax[[context]]=Union[syntax[[context]],contextData[[All,syntaxTags[[context]]]]];
169-
AppendTo[library,<|"Type"->context,"Storage"->"Internal","Data"->contextData|>];
168+
AppendTo[library,<|"Type"->context,"Data"->contextData|>];
170169
contextData={};
171170
];
172171
Switch[command,
@@ -187,7 +186,6 @@ Tokenizer[filepath_]:=Block[
187186
{item,{"Chord","Function"}}];
188187
AppendTo[library,<|
189188
"Type"->"Package",
190-
"Storage"->"External",
191189
"Path"->StringTake[value,{2,-2}],
192190
"Content"->source[["Tokenizer","Library"]]
193191
|>],
@@ -292,8 +290,8 @@ Tokenizer[filepath_]:=Block[
292290
}][[1]]&};
293291

294292
(* function simplified *)
295-
object=("{"~~subtrack~~"}")|(notationPadded...~~note~~notationPadded...);
296-
typePatt=<|"$"->string,"%"->expression,"&"->object,"!"->number,"@"->subtrack|>;
293+
object=("{"~~subtrack~~"}")|(notationPadded~~note~~notationPadded);
294+
typePatt=<|"$"->string,"%"->expression,"&"->object,"!"->number,"@"->Shortest[subtrack]|>;
297295
typeTok[type_,str_]:=Switch[type,
298296
"String",<|"Type"->"String","Content"->str|>,
299297
"Expression",<|"Type"->"Expression","Content"->str|>,
@@ -411,14 +409,6 @@ Tokenizer[filepath_]:=Block[
411409
EndPackage[];
412410

413411

414-
(* ::Input:: *)
415-
(*Contexts["SMML`*"]*)
416-
417-
418-
(* ::Input:: *)
419-
(*Export[NotebookDirectory[]<>"test.json",%];*)
420-
421-
422412
(* ::Input:: *)
423413
(*Tokenizer[NotebookDirectory[]<>"test.sml"][["Tokenizer","Sections",1,"Tracks",1,"Content"(*,All,"Type"*)]]*)
424414

0 commit comments

Comments
 (0)