Did you know ... Search Documentation:
Pack plumdrum -- prolog/humdrum/humutils.pl
PublicShow source

This module provides some utility predicates for parsing. They all operate as part of a DCG where the threaded state is a list of character codes.

Parsers in this module use the following data types:

recip ---> X:natural  % duration is 1/X except for X=0, then duration=2
         ; dots(X:natural,N:natural)   % add N dots, means (1/X)*(3/2)^N

pitch_class ---> a ; b ; c ; d ; e ; f ; g
               ; sharp(pitch_class)
               ; flat(pitch_class).

barline_attribute ---> double
                ; ortho(list(barline_ortho))
                ; number(natural)
                ; number(natural,natural)
                ; pause.

barline_ortho ---> normal ; heavy ; partial1 ; partial2 ; invisible ; repeat.
 peek(+X:list(A))// is semidet
peek(-X:list(A))// is nondet
Works in a list(A) DCG and unifies X with the first one or two elements of the list being parsed. Can be used in a DCG to peek the first one or two elements of the unparsed % list without removing them.
 charsex(+Type:char_type, +ExFirst:list(code), +Exclude:list(code), -Chars:list(code))// is nondet
Parses characters of char_type Type excluding characters in Exclude. In addition, the first character is not allowed to be in ExFirst. NB: ordering of clauses means charsex will read as much as possible and only get to shorter parses on backtracking. Character types as defined by char_type/2 but adding type text defined as the union of types graph and space.
 nat(-Number:natural)// is nondet
Parse or generate a natural number, ie a non-negative integer.
 float(-X:float)// is semidet
Can parse or generate a float as part of a list-of-codes DCG.
 pitch(P:pitch_class, O:integer)// is semidet
Parses a pitch in Humdrum Kern syntax. The grammar is
pitch --> pitch_octave, modifiers.
pitch_octave --> {member(N,"abcdefg")}, +[N]  % each extra N goes up 1 octave
               ; {member(N,"ABCDEFG")}, +[N]. % each extra N goes down 1 octave
modifiers --> +"#"    % one or more sharps
            ; +"-"    % one or more flats
            ; "n"     % explicity natural
            ; "".     % implicit natural

+X --> X ; X, +X.     % one or more copies of X.
 pitchclass(P:pitch_class)// is semidet
 pitchclass(C:oneof([lower,upper]), P:pitch_class)// is semidet
Parses a pitch class in upper or lower case forms.
 rep_shared(N:natural, P:phrase)// is nondet
Equivalent to P repeated N times. Any variables in P are shared between iterations.
 recip_to_rational(+R:recip, -D:rational) is det
Converts duration from recip format to rational number.
 recip(-R:recip)// is semidet
Parses a duration as a recip term.
 bar(-Attrs:list(bar_attributes))// is semidet
Parses Humdrum bar signifiers. See module header for data type.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 pitchclass(Arg1, Arg2, Arg3, Arg4)