Karya, built on 2018-05-31T02:46:59 (patch 0a1a35479c514820d77330ae8a978975ba22a47a)

Safe HaskellNone




Tracklang parsers. Many of the parsers in here should be inverses of the ShowVal.ShowVal class.



parse_val :: Text -> Either Text BaseTypes.Val Source #

Parse a single Val.

parse_attrs :: String -> Either Text Attrs.Attributes Source #

Parse attributes in the form +a+b.

parse_num :: Text -> Either Text Signal.Y Source #

Parse a number or hex code, without a type suffix.

parse_call :: Text -> Maybe Text Source #

Extract only the call part of the text.

lex1 :: Text -> (Text, Text) Source #

Lex out a single expression. This isn't really a traditional lex, because it will extract a whole parenthesized expression instead of a token.

lex :: Text -> [Text] Source #

Like lex1, but get all of them.

split_pipeline :: Text -> [[Text]] Source #

Take an expression and lex it into words, where each sublist corresponds to one expression in the pipeline.

unparsed_call :: Expr.Symbol Source #

This is a magic call name that surpresses normal parsing. Instead, the rest of the event expression is passed as a string. The only characters that can't be used are ) and |, so an unparsed call can still be included in a sub expression.


p_pcontrol :: A.Parser Score.PControl Source #

Unlike p_control_ref, this doesn't parse a comma and a default value, because pitches don't have literals. Instead, use the pitch-control val call.

p_identifier :: Bool -> String -> A.Parser Text Source #

Identifiers are somewhat more strict than usual. They must be lowercase, and the only non-letter allowed is hyphen. This means words must be separated with hyphens, and leaves me free to give special meanings to underscores or caps if I want.

until gives additional chars that stop parsing, for idents that are embedded in another lexeme.

p_symbol Source #


:: Bool

A call at the top level can allow a ).

-> A.Parser Expr.Symbol 

Any word in call position is considered a Str. This means that you can have calls like 4 and >, which are useful names for notes or ornaments.

expand macros

expand_macros :: (Text -> Text) -> Text -> Either Text Text Source #

Map the identifiers after a "@" through the given function. Used to implement ID macros for the REPL.

A macro looks like either @valid-id-chars or @"any chars".

ky file

data Definitions Source #

This is a mirror of Library, but with expressions instead of calls. (generators, transformers)

type Definition = (FilePath, (Expr.Symbol, Expr)) Source #

(defining_file, (Symbol, Expr))

load_ky Source #


:: [FilePath] 
-> Text 
-> IO (Either Text (Definitions, [(FilePath, Text)]))

(all_definitions, [(import_filename, content)])

Parse ky text and load and parse all the files it imports. parse_ky describes the format of the ky file.

find_ky :: [FilePath] -> FilePath -> IO (Either Text (FilePath, Text)) Source #

Find the file in the given paths and return its filename and contents.

parse_ky :: FilePath -> Text -> Either Text ([FilePath], Definitions) Source #

Parse a ky file. This file gives a way to define new calls in the tracklang language, which is less powerful but more concise than haskell.

The syntax is a sequence of import 'path\/to\/file' lines followed by a sequence of sections. A section is a header: line followed by definitions. The header determines the type of the calls defined after it, e.g.:

import 'somelib.ky'

note generator:
x = y

>new-inst = >source-inst

Valid headers are val:, (note|control|pitch) (generator|transformer):, or alias:. A line is continued if it is indented, and -- comments until the end of the line.

This is similar to the Derive.Call.Equal call, but not quite the same:

  • It uses headers for the call type instead of equal's weird sigils.
  • The syntax is different because the arguments to equal are evaluated in place, while a file is all quoted by nature. E.g. a definition x = a b c is equivalent to an equal ^x = "(a b c). x = a (no arguments) is equivalent to ^x = a, in that x can take the same arguments as a.
  • Calls are defined as Derive.Call.Macros, which means they can include $variables, which become arguments to the call.


newtype Expr Source #

These are parallel to the Expr.Expr types, except they add VarTerm. The duplication is unfortunate, but as long as this remains a simple AST it seems better than the various heavyweight techniques for parameterizing an AST.


Expr (NonEmpty Call) 
Show Expr # 
Instance details

Defined in Derive.Parse


showsPrec :: Int -> Expr -> ShowS #

show :: Expr -> String #

showList :: [Expr] -> ShowS #

ShowVal.ShowVal Expr # 
Instance details

Defined in Derive.Parse


show_val :: Expr -> Text Source #

data Call Source #


Call !Expr.Symbol ![Term] 
Show Call # 
Instance details

Defined in Derive.Parse


showsPrec :: Int -> Call -> ShowS #

show :: Call -> String #

showList :: [Call] -> ShowS #

ShowVal.ShowVal Call # 
Instance details

Defined in Derive.Parse


show_val :: Call -> Text Source #

data Term Source #

Show Term # 
Instance details

Defined in Derive.Parse


showsPrec :: Int -> Term -> ShowS #

show :: Term -> String #

showList :: [Term] -> ShowS #

ShowVal.ShowVal Term # 
Instance details

Defined in Derive.Parse


show_val :: Term -> Text Source #

newtype Var Source #

A variable to be substituted via the Derive.Call.Macro mechanism.


Var Text 
Show Var # 
Instance details

Defined in Derive.Parse


showsPrec :: Int -> Var -> ShowS #

show :: Var -> String #

showList :: [Var] -> ShowS #

ShowVal.ShowVal Var # 
Instance details

Defined in Derive.Parse


show_val :: Var -> Text Source #