% @doc % gsc_bst = ast second attempt but prefix so tab complete % % from docs/sophia/so_syntax.md: % % File ::= Block(TopDecl) % % TopDecl ::= ['payable'] ['main'] 'contract' Con [Implement] '=' Block(Decl) % | 'contract' 'interface' Con [Implement] '=' Block(Decl) % | 'namespace' Con '=' Block(Decl) % | '@compiler' PragmaOp Version % | 'include' String % | Using % % Implement ::= ':' Sep1(Con, ',') % % Decl ::= 'type' Id ['(' TVar* ')'] '=' TypeAlias % | 'record' Id ['(' TVar* ')'] '=' RecordType % | 'datatype' Id ['(' TVar* ')'] '=' DataType % | 'let' Id [':' Type] '=' Expr % | (EModifier* 'entrypoint' | FModifier* 'function') Block(FunDecl) % | Using % % FunDecl ::= Id ':' Type // Type signature % | Id Args [':' Type] '=' Block(Stmt) // Definition % | Id Args [':' Type] Block(GuardedDef) // Guarded definitions % % GuardedDef ::= '|' Sep1(Expr, ',') '=' Block(Stmt) % % Using ::= 'using' Con ['as' Con] [UsingParts] % UsingParts ::= 'for' '[' Sep1(Id, ',') ']' % | 'hiding' '[' Sep1(Id, ',') ']' % % PragmaOp ::= '<' | '=<' | '==' | '>=' | '>' % Version ::= Sep1(Int, '.') % % EModifier ::= 'payable' | 'stateful' % FModifier ::= 'stateful' | 'private' % % Args ::= '(' Sep(Pattern, ',') ')' -module(gsc_bst). -compile([export_all, nowarn_export_all]). -include("$gsc_include/gsc.hrl"). %-record(bst_nyi, {tokens :: [tk()]). % %% ['payable'] ['main'] 'contract' Con [Implement] '=' Block(Decl) %-record(bst_ct, % {payable = none :: none | boolean(), % main = none :: none | boolean(), % name = none :: none | string(), % impl = none :: none | [string()], % eq = none :: none | '=', % decls = none :: none | [decl()]}). % %% 'contract' 'interface' Con [Implement] '=' Block(Decl) %-record(bst_iface, % {payable = none :: none | boolean() % name = none :: none | string(), % impl = none :: none | [string()], % eq = none :: none | '=', % decls = none :: none | [decl()]}). % % % %% File ::= Block(TopDecl) %gulp(file, Tokens) -> % gulp({block, top_decl}, Tokens); %% TopDecl ::= ['payable'] ['main'] 'contract' Con [Implement] '=' Block(Decl) %% | 'contract' 'interface' Con [Implement] '=' Block(Decl) %% | 'namespace' Con '=' Block(Decl) %% | '@compiler' PragmaOp Version %% | 'include' String %% | Using %gulp(top_decl, [#tk{string = S} | Rest]) -> % case strings(3, Tokens) of % ["payable", "contract", "interface"] -> % gulp_ct(#bst_iface{payable = true, main = true}, drop(3, Tokens)); % ["payable", "contract", _] -> % gulp_ct(#bst_ct{payable = true, main = false}, drop(2, Tokens)); % ["contract" | _] -> % gulp({oneof, [bst_iface, bst_ct, bst_nyi]}, Tokens); %gulp(bst_ct, Tokens) -> %gulp(top_decl, Tokens) ->