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