2022-08-12 21:08:20 +03:00
|
|
|
/- ast
|
2022-08-06 17:06:18 +03:00
|
|
|
|%
|
2022-08-12 21:08:20 +03:00
|
|
|
+$ command-ast
|
|
|
|
$%
|
2022-08-13 05:00:44 +03:00
|
|
|
create-database:ast
|
|
|
|
create-index:ast
|
|
|
|
create-namespace:ast
|
|
|
|
create-table:ast
|
|
|
|
create-view:ast
|
2022-08-12 21:08:20 +03:00
|
|
|
==
|
|
|
|
+$ command
|
|
|
|
$%
|
|
|
|
%create-database
|
|
|
|
%create-index
|
|
|
|
%create-namespace
|
|
|
|
%create-table
|
|
|
|
%create-view
|
|
|
|
==
|
2022-08-13 05:00:44 +03:00
|
|
|
::
|
|
|
|
:: the main event
|
|
|
|
::
|
2022-08-06 17:06:18 +03:00
|
|
|
++ parse
|
2022-08-12 21:08:20 +03:00
|
|
|
|= [current-database=@t script=tape]
|
2022-08-06 17:06:18 +03:00
|
|
|
~| 'Input script is empty.'
|
|
|
|
?> !=((lent script) 0)
|
2022-08-13 05:13:25 +03:00
|
|
|
^- (list command-ast)
|
2022-08-13 05:00:44 +03:00
|
|
|
=/ commands `(list command-ast)`~
|
2022-08-13 05:13:25 +03:00
|
|
|
=/ script-position [1 1]
|
2022-08-12 21:08:20 +03:00
|
|
|
::
|
|
|
|
:: parser rules
|
|
|
|
::
|
|
|
|
=/ whitespace (star ;~(pose gah (just '\09') (just '\0d')))
|
2022-08-13 05:00:44 +03:00
|
|
|
=/ end-or-next-command ;~(pose ;~(plug whitespace mic) whitespace mic)
|
2022-08-12 21:08:20 +03:00
|
|
|
=/ parse-face ;~(pfix whitespace sym)
|
|
|
|
=/ parse-qualified ;~(pfix whitespace ;~((glue dot) parse-face parse-face))
|
|
|
|
=/ parse-db-qualified-name ;~(pose parse-qualified parse-face)
|
|
|
|
=/ parse-command ;~ pose
|
2022-08-13 05:13:25 +03:00
|
|
|
(cold %create-database ;~(plug whitespace (jester 'create') whitespace (jester 'database')))
|
|
|
|
(cold %create-index ;~(plug whitespace (jester 'create') whitespace (jester 'index')))
|
|
|
|
(cold %create-namespace ;~(plug whitespace (jester 'create') whitespace (jester 'namespace')))
|
|
|
|
(cold %create-table ;~(plug whitespace (jester 'create') whitespace (jester 'table')))
|
|
|
|
(cold %create-view ;~(plug whitespace (jester 'create') whitespace (jester 'view')))
|
|
|
|
:: (cold ;~(plug whitespace (jester '') whitespace (jester '')))
|
2022-08-12 21:08:20 +03:00
|
|
|
==
|
2022-08-13 22:08:34 +03:00
|
|
|
~| 'Current database name is not a proper face'
|
|
|
|
=/ dummy (scan (trip current-database) sym)
|
2022-08-13 05:13:25 +03:00
|
|
|
:: main loop
|
2022-08-12 21:08:20 +03:00
|
|
|
::
|
2022-08-06 17:06:18 +03:00
|
|
|
|-
|
2022-08-12 21:08:20 +03:00
|
|
|
?: =(~ script) :: https://github.com/urbit/arvo/issues/1024
|
2022-08-13 05:00:44 +03:00
|
|
|
(flop commands)
|
|
|
|
~| "Error parsing command keyword: {<script-position>}"
|
|
|
|
=/ command-nail u.+3:q.+3:(parse-command [script-position script])
|
2022-08-12 21:08:20 +03:00
|
|
|
?- `command`p.command-nail
|
|
|
|
%create-database
|
2022-08-14 00:20:30 +03:00
|
|
|
~| 'Create database must be only statement in script'
|
|
|
|
?> =((lent commands) 0)
|
|
|
|
=/ database-name p.u.+3:q.+3:(parse-db-qualified-name [[1 1] q.q.command-nail])
|
|
|
|
=/ database-ast (create-database:ast %create-database database-name)
|
|
|
|
%= $
|
|
|
|
script ""
|
|
|
|
commands [`command-ast`database-ast commands]
|
|
|
|
==
|
2022-08-12 21:08:20 +03:00
|
|
|
%create-index
|
|
|
|
!!
|
|
|
|
%create-namespace
|
2022-08-13 05:13:25 +03:00
|
|
|
~| "Cannot parse name to face in create-namespace {<p.q.command-nail>}"
|
2022-08-12 21:08:20 +03:00
|
|
|
=/ qualified-name-nail u.+3:q.+3:(parse-db-qualified-name [[1 1] q.q.command-nail])
|
2022-08-13 05:00:44 +03:00
|
|
|
=/ namespace-ast ?@ p.qualified-name-nail
|
2022-08-12 21:08:20 +03:00
|
|
|
(create-namespace:ast %create-namespace current-database p.qualified-name-nail)
|
|
|
|
(create-namespace:ast %create-namespace -:p.qualified-name-nail +:p.qualified-name-nail)
|
2022-08-13 05:13:25 +03:00
|
|
|
=/ last-nail (end-or-next-command q:qualified-name-nail)
|
|
|
|
?: (gth -.p:last-nail -.p.q.command-nail) :: if we advanced to next input line
|
2022-08-13 05:00:44 +03:00
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:last-nail :: then use the current position
|
|
|
|
script-position [p.p.q.+3.+3.q:last-nail q.p.q.+3.+3.q:last-nail]
|
|
|
|
commands [`command-ast`namespace-ast commands]
|
|
|
|
==
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:last-nail :: else add starting column to current column position
|
2022-08-13 05:13:25 +03:00
|
|
|
script-position [p.p.q.command-nail (add q.p.q.command-nail q.p.q.+3.+3.q.last-nail)]
|
2022-08-13 05:00:44 +03:00
|
|
|
commands [`command-ast`namespace-ast commands]
|
|
|
|
==
|
2022-08-12 21:08:20 +03:00
|
|
|
%create-table
|
|
|
|
!!
|
|
|
|
%create-view
|
|
|
|
!!
|
|
|
|
==
|
2022-08-13 05:00:44 +03:00
|
|
|
::
|
|
|
|
:: turn an atom into upper case cord
|
|
|
|
::
|
|
|
|
++ trip-cuss-crip
|
|
|
|
|= target=@
|
|
|
|
^- @t
|
|
|
|
(crip (cuss (trip `@t`target)))
|
|
|
|
::
|
|
|
|
:: match a cord, case agnostic
|
|
|
|
::
|
2022-08-13 05:13:25 +03:00
|
|
|
++ jester
|
2022-08-13 05:00:44 +03:00
|
|
|
|= daf=@t
|
|
|
|
|= tub=nail
|
|
|
|
=+ fad=daf
|
|
|
|
|- ^- (like @t)
|
|
|
|
?: =(`@`0 daf)
|
|
|
|
[p=p.tub q=[~ u=[p=fad q=tub]]]
|
|
|
|
?: |(?=(~ q.tub) !=((trip-cuss-crip (end 3 daf)) (trip-cuss-crip i.q.tub)))
|
|
|
|
(fail tub)
|
|
|
|
$(p.tub (lust i.q.tub p.tub), q.tub t.q.tub, daf (rsh 3 daf))
|
2022-08-13 05:13:25 +03:00
|
|
|
--
|