parse create-namespace

This commit is contained in:
jackfoxy 2022-08-12 11:08:20 -07:00
parent ba95f8d0f3
commit 645c8a3cb5
2 changed files with 126 additions and 74 deletions

View File

@ -1,87 +1,139 @@
/- ast
|% |%
+$ states ?(%unknown %create) +$ states ?(%unknown %create)
+$ token ?(@t %create tape) +$ command-ast
++ resolve-face $%
|= [buffer=tape pos=[@ud @ud]] [%create-database create-database:ast]
^- @t [%create-index create-index:ast]
~| "Cannot parse {<pos>} to face" [%create-namespace create-namespace:ast]
`@t`(scan (flop buffer) sym) [%create-table create-table:ast]
++ resolve-unknown [%create-view create-view:ast]
|= [buffer=tape pos=[@ud @ud]] ==
::^- [states token] +$ command
~| "Cannot parse {<pos>}" $%
?: =('etaerc' (crip (cass buffer))) %create-database
::[%create %create] %create-index
%create %create-namespace
!! %create-table
%create-view
==
::++ resolve-face
:: |= [buffer=tape pos=[@ud @ud]]
:: ^- @t
:: ~| "Cannot parse {<pos>} to face"
:: `@t`(scan (flop buffer) sym)
::++ resolve-unknown
:: |= [buffer=tape pos=[@ud @ud]]
:: ::^- [states command]
:: ~| "Cannot parse {<pos>}"
:: ?: =('etaerc' (crip (cass buffer)))
:: ::[%create %create]
:: %create
:: !!
++ parse ++ parse
|= script=tape |= [current-database=@t script=tape]
~| 'Input script is empty.' ~| 'Input script is empty.'
?> !=((lent script) 0) ?> !=((lent script) 0)
^- (list token) :: ^- (list command)
=/ tokens `(list token)`~ :: =/ commands `(list command)`~
=/ buffer `tape`~ ::
:: parser rules
::
=/ whitespace (star ;~(pose gah (just '\09') (just '\0d')))
=/ 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
(cold %create-database ;~(plug whitespace (jest 'create') whitespace (jest 'database')))
(cold %create-index ;~(plug whitespace (jest 'create') whitespace (jest 'index')))
(cold %create-namespace ;~(plug whitespace (jest 'create') whitespace (jest 'namespace')))
(cold %create-table ;~(plug whitespace (jest 'create') whitespace (jest 'table')))
(cold %create-view ;~(plug whitespace (jest 'create') whitespace (jest 'view')))
:: (cold ;~(plug whitespace (jest '') whitespace (jest '')))
==
::
=/ buffer `(list *)`~
=/ state `states`%unknown =/ state `states`%unknown
=/ script-position [1 1] =/ script-position [1 1]
=/ buffer-position [1 1] =/ buffer-position [1 1]
|- |-
:: https://github.com/urbit/arvo/issues/1024 ?: =(~ script) :: https://github.com/urbit/arvo/issues/1024
:: :: ?: &(=((lent commands) 0) =((lent buffer) 0))
?: =(~ script) ?: =((lent buffer) 0)
?: &(=((lent tokens) 0) =((lent buffer) 0))
~| "no input" ~| "no input"
!! !!
?- state ?- state
%unknown %unknown
~& "state is: {<state>}" ~& "state is: {<state>}"
~& "tokens is: {<tokens>}" :: ~& "commands is: {<commands>}"
~& "buffer is: {<buffer>}" ~& "buffer is: {<buffer>}"
~| "incomplete statement {<buffer-position>}" ~| "incomplete statement {<buffer-position>}"
!! !!
%create %create
tokens !!
:: (flop `(list token)`[(resolve-face [buffer buffer-position]) tokens]) ::commands
:: (flop `(list command)`[(resolve-face [buffer buffer-position]) commands])
== ==
?- state =/ command-nail u.+3:q.+3:(parse-command [[1 1] script])
%unknown ?- `command`p.command-nail
?: =(' ' -:script) %create-database
?. (gth (lent buffer) 0)
%= $
script +:script
script-position [-:script-position +(+:script-position)]
buffer-position [-:buffer-position +(+:buffer-position)]
==
=/ the-token (resolve-unknown [buffer buffer-position])
%= $
script +:script
state the-token
tokens `(list token)`[the-token tokens]
buffer `tape`~
script-position [-:script-position +(+:script-position)]
buffer-position [-:script-position +(+:script-position)]
==
?: =('\0a' -:script)
?. (gth (lent buffer) 0)
%= $
script +:script
script-position [+(-:script-position) 1]
buffer-position [+(-:buffer-position) 1]
==
=/ the-token (resolve-unknown [buffer buffer-position])
%= $
script +:script
state the-token
tokens `(list token)`[the-token tokens]
buffer `tape`~
script-position [+(-:script-position) 1]
buffer-position [+(-:buffer-position) 1]
==
%= $
script +:script
buffer `tape`[-:script buffer]
script-position [-:script-position +(+:script-position)]
==
%create
!! !!
== %create-index
!!
%create-namespace
=/ position p.q.command-nail
~| "Cannot parse name {<position>} to face in create-namespace"
=/ qualified-name-nail u.+3:q.+3:(parse-db-qualified-name [[1 1] q.q.command-nail])
?@ p.qualified-name-nail
(create-namespace:ast %create-namespace current-database p.qualified-name-nail)
(create-namespace:ast %create-namespace -:p.qualified-name-nail +:p.qualified-name-nail)
%create-table
!!
%create-view
!!
==
:: !!
:: ?- state
:: %unknown
:: ?: =(' ' -:script)
:: ?. (gth (lent buffer) 0)
:: %= $
:: script +:script
:: script-position [-:script-position +(+:script-position)]
:: buffer-position [-:buffer-position +(+:buffer-position)]
:: ==
:: =/ the-command (resolve-unknown [buffer buffer-position])
:: %= $
:: script +:script
:: state the-command
:: commands `(list command)`[the-command commands]
:: buffer `tape`~
:: script-position [-:script-position +(+:script-position)]
:: buffer-position [-:script-position +(+:script-position)]
:: ==
:: ?: =('\0a' -:script)
:: ?. (gth (lent buffer) 0)
:: %= $
:: script +:script
:: script-position [+(-:script-position) 1]
:: buffer-position [+(-:buffer-position) 1]
:: ==
:: =/ the-command (resolve-unknown [buffer buffer-position])
:: %= $
:: script +:script
:: state the-command
:: commands `(list command)`[the-command commands]
:: buffer `tape`~
:: script-position [+(-:script-position) 1]
:: buffer-position [+(-:buffer-position) 1]
:: ==
:: %= $
:: script +:script
:: buffer `tape`[-:script buffer]
:: script-position [-:script-position +(+:script-position)]
:: ==
:: %create
:: !!
:: ==
-- --

View File

@ -93,13 +93,13 @@
$% $%
[%unary-predicate unary-predicate] [%unary-predicate unary-predicate]
[%binary-predicate binary-predicate] [%binary-predicate binary-predicate]
predicate-between [%predicate-between]
predicate-null [%predicate-null]
predicate-distinct [%predicate-distinct]
predicate-in-query [%predicate-in-query]
predicate-in-list [%predicate-in-list]
predicate-any [%predicate-any]
predicate-exists [%predicate-exists]
== ==
+$ conjoined-predicate +$ conjoined-predicate
$: $:
@ -224,7 +224,7 @@
is-clustered=? is-clustered=?
columns=(list column-order) columns=(list column-order)
== ==
+$ create-namespace $:([%create-namespace name=@t database-name=@t]) +$ create-namespace $:([%create-namespace database-name=@t name=@t])
+$ foreign-key +$ foreign-key
$: $:
%create-foreign-key %create-foreign-key