1
1
(* ::Package:: *)
2
2
3
3
(* ::Input:: *)
4
- (*StringMatchQ[", ",RegularExpression["\\, "]]*)
4
+ (*StringMatchQ["& ",RegularExpression["[^\\{\\}]* "]]*)
5
5
6
6
7
7
BeginPackage ["SMML`Tokenizer`" ];
@@ -11,13 +11,12 @@ rep[pat_]:=rep[pat,","~~" "...];
11
11
rep [pat_ ,sep_ ]:= pat ~~ (sep ~~ pat )... ;
12
12
repRegex [pat_ ]:= repRegex [pat ,", *" ];
13
13
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 },"|" ]<> ")" ];
15
16
unsigned = RE ["\\ d+" ];
16
17
signed = RE ["[\\ +\\ -]\\ d+" ];
17
18
integer = RE ["[\\ +\\ -]?\\ d+" ];
18
19
19
- chordCodePos = RE ["([\\ +\\ -]?\\ d+)?" ];
20
- chordCodeSft = RE ["([\\ +\\ -]\\ d+)?" ];
21
20
chordCodeTok [str_ ]:= StringCases [str ,
22
21
StringExpression [
23
22
ntt :LetterCharacter ~~ "\t " .. ,
@@ -66,7 +65,7 @@ postOperator="``"|"`"|"";
66
65
volOperator = (">" |":" )... ;
67
66
pitOperator = ("#" |"b" |"'" |"," )... ;
68
67
durOperator = ("." |"-" |"_" |"=" )... ;
69
- scaleDegree = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "%" | "x" ;
68
+ scaleDegree = RE [ "[0-7%x]" ] ;
70
69
71
70
number = integer ~~ "" |("." ~~ unsigned );
72
71
expression = (integer ~~ "" |("/" |"." ~~ unsigned ))|("Log2(" ~~ unsigned ~~ ")" );
@@ -81,7 +80,7 @@ orderTok=Union@@StringCases[#,{
81
80
n :integer ~~ "~" ~~ m :integer :> Range [ToExpression @ n ,ToExpression @ m ],
82
81
n :integer :> {ToExpression @ n }
83
82
}]& ;
84
- notationPadded = Whitespace | "|" | "/" | "^" | "&" | "*" ;
83
+ notationPadded = RE [ "[& \\ | \\ s \\ ^ \\ *]*" ] ;
85
84
notationPatt = Alternatives [
86
85
"+" |"ToCoda" |"Coda" |"s" |"Segno" |"DC" |"DaCapo" |"DS" |"DaSegno" ,
87
86
"||:" |":||" |("[" ~~ orderListP ~~ ".]" ),
@@ -166,7 +165,7 @@ Tokenizer[filepath_]:=Block[
166
165
][line ];
167
166
If [contextData != {},
168
167
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 |> ];
170
169
contextData = {};
171
170
];
172
171
Switch [command ,
@@ -187,7 +186,6 @@ Tokenizer[filepath_]:=Block[
187
186
{item ,{"Chord" ,"Function" }}];
188
187
AppendTo [library ,< |
189
188
"Type" -> "Package" ,
190
- "Storage" -> "External" ,
191
189
"Path" -> StringTake [value ,{2 ,- 2 }],
192
190
"Content" -> source [["Tokenizer" ,"Library" ]]
193
191
|> ],
@@ -292,8 +290,8 @@ Tokenizer[filepath_]:=Block[
292
290
}][[1 ]]& };
293
291
294
292
(* 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 ] |> ;
297
295
typeTok [type_ ,str_ ]:= Switch [type ,
298
296
"String" ,< |"Type" -> "String" ,"Content" -> str |> ,
299
297
"Expression" ,< |"Type" -> "Expression" ,"Content" -> str |> ,
@@ -411,14 +409,6 @@ Tokenizer[filepath_]:=Block[
411
409
EndPackage [];
412
410
413
411
414
- (* ::Input:: *)
415
- (*Contexts["SMML`*"]*)
416
-
417
-
418
- (* ::Input:: *)
419
- (*Export[NotebookDirectory[]<>"test.json",%];*)
420
-
421
-
422
412
(* ::Input:: *)
423
413
(*Tokenizer[NotebookDirectory[]<>"test.sml"][["Tokenizer","Sections",1,"Tracks",1,"Content"(*,All,"Type"*) ]]*)
424
414
0 commit comments