on d64cdeb help sign in
project-m36/src/bin/TutorialD/Interpreter/InformationOperator.hs
63 lines 3.4 kB history raw
1{-# LANGUAGE CPP #-}
2module TutorialD.Interpreter.InformationOperator where
3import Data.Text
4import Text.Megaparsec
5import Text.Megaparsec.Text
6import TutorialD.Interpreter.Base
7-- older versions of stack fail to
8#if !defined(VERSION_project_m36)
9# warning Failed to discover proper version from cabal_macros.h
10# define VERSION_project_m36 "<unknown>"
11#endif
13-- this module provides information about the current interpreter
15data InformationOperator = HelpOperator |
16 GetVersionOperator
17 deriving (Show)
19infoOpP :: Parser InformationOperator
20infoOpP = helpOpP <|> getVersionP
22helpOpP :: Parser InformationOperator
23helpOpP = reserved ":help" >> pure HelpOperator
25getVersionP :: Parser InformationOperator
26getVersionP = reserved ":version" >> pure GetVersionOperator
28evalInformationOperator :: InformationOperator -> Either Text Text
29evalInformationOperator GetVersionOperator = Right ("tutd " `append` VERSION_project_m36)
30-- display generic help
31evalInformationOperator HelpOperator = Right $ intercalate "\n" help
32 where
33 help = ["tutd Help",
34 "Quick Examples:",
35 ":showexpr true",
36 ":showexpr relation{name Text, address Text}{tuple{name \"Steve\", address \"Main St.\"}}",
37 "address := relation{tuple{name \"Steve\", address \"Main St.\"}}",
38 ":showexpr true join false = false",
39 "Relational Operators:",
40 ":showexpr relation{a Int, b Text}{} -- relation creation",
41 ":showexpr relation{tuple{c t}} -- relation creation",
42 ":showexpr relation{tuple{a 4, b 4}}{a} -- projection",
43 ":showexpr relation{tuple{a 5}} rename {a as num} -- rename",
44 ":showexpr relation{tuple{d 10}} where d=10 or d=5 -- restriction",
45 ":showexpr relation{tuple{d 10}} : {e:=add(@d,5)} -- extension",
46 "Database Context Operators:",
47 "animal := relation{tuple{name \"octopus\", legs_count 8}} -- assignment",
48 "insert animal relation{tuple{name \"cat\", legs_count 4}} -- insertion",
49 "car :: {model Text, make Text, year Int} -- definition",
50 "undefine car -- undefine",
51 "delete animal where legs_count=4 -- deletion",
52 "update animal where name=\"octopus\" (name:=\"Mr. Octopus\") -- updating",
53 "employee:=relation{id Int, name Text, age Int}{}; key emp_unique_id {id} employee --uniqueness constraint",
54 "constraint age_gt_zero (employee{age} where ^lt(@age,0)){} equals false -- constraint",
55 "notify teenager_added employee where ^lt(@age,20) and ^gte(@age,13) employee{age} where ^lt(@age,20) and ^gte(@age,13) -- change notification",
56 "Graph Operators: ",
57 ":jumphead <head_name> - change the current database context to point to a current head",
58 ":jump <transaction_id> - change the current database context to that of a past transaction",
59 ":commit - push the current context into the current head and make it immutable",
60 ":rollback - discard any changes made in the current context",
61 ":showgraph - display the transaction graph",
62 "View more documentation at: https://github.com/agentm/project-m36/blob/master/docs/tutd_tutorial.markdown"
63 ]