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

Derive.Parse

Contents

Description

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

Synopsis

# Documentation

Parse a single Val.

Parse attributes in the form +a+b.

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

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.

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.

# parsers

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.

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.

Arguments

 :: 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

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

Constructors

 Definitions Fieldsdef_note :: !([Definition], [Definition]) def_control :: !([Definition], [Definition]) def_pitch :: !([Definition], [Definition]) def_val :: ![Definition] def_aliases :: ![(Score.Instrument, Score.Instrument)]
Instances
 # Instance detailsDefined in Derive.Parse MethodsshowList :: [Definitions] -> ShowS # # Instance detailsDefined in Derive.Parse Methodsstimes :: Integral b => b -> Definitions -> Definitions # # Instance detailsDefined in Derive.Parse Methodsmconcat :: [Definitions] -> Definitions #

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

(defining_file, (Symbol, Expr))

Arguments

 :: [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 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

alias:
>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.

## types

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.

Constructors

 Expr (NonEmpty Call)
Instances
 # Instance detailsDefined in Derive.Parse MethodsshowsPrec :: Int -> Expr -> ShowS #show :: Expr -> String #showList :: [Expr] -> ShowS # # Instance detailsDefined in Derive.Parse Methods

data Call Source #

Constructors

 Call !Expr.Symbol ![Term]
Instances
 # Instance detailsDefined in Derive.Parse MethodsshowsPrec :: Int -> Call -> ShowS #show :: Call -> String #showList :: [Call] -> ShowS # # Instance detailsDefined in Derive.Parse Methods

data Term Source #

Constructors

 VarTerm !Var ValCall !Call Literal !BaseTypes.Val
Instances
 # Instance detailsDefined in Derive.Parse MethodsshowsPrec :: Int -> Term -> ShowS #show :: Term -> String #showList :: [Term] -> ShowS # # Instance detailsDefined in Derive.Parse Methods

newtype Var Source #

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

Constructors

 Var Text
Instances
 # Instance detailsDefined in Derive.Parse MethodsshowsPrec :: Int -> Var -> ShowS #show :: Var -> String #showList :: [Var] -> ShowS # # Instance detailsDefined in Derive.Parse Methods