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