soil-schema / soil

REST api schema and code generator
MIT License
1 stars 0 forks source link

New Parser #53

Closed niaeashes closed 2 years ago

niaeashes commented 2 years ago

Problem

Update

Remove ( ) from command code.

before: @set-var(<variable>, <value>)

after: @set-var <variable>, <value>

But I want to support before case.

Directive rules

directive declaration = [<annotation>] <directive> <definition> [<block-open>]

Each block has allowed annotation and directive list, a directive end at <block-open> token or another allowed annotation or directive.

e.g.

annotation directive "Directive Name"
entity directive
  = entity <name> <block>

field directive
  = [mutable|writer] field <name>: <type> [<block>]

entity.inner directive
  = [enum] inner <name> <block>

endpoint directive
  = endpoint <method> <path> [<block>]

endpoint.request directive
  = request <block>

endpoint.success directive
  = success <block>

endpoint.query directive
  = [required] query <name>: <type> [<block>]

endpoint.parameter directive
  = parameter <name>: <type> [<block>]

scenario directive
  = [shared] scenario <name> <command-block>

scenario.@request.before directive
  = before <command-block>

scenario.@request.after directive
  = after <command-block>

Property keys

Directive has any property key. e.g. default sets default value of field or query, name is used custom reference, example defines mocking values.

Property key block is not allowed. name property key is always allowed.

directive property key
field default, example, enum
endpoint.query default (with required annotation only), example, enum
endpoint.parameter enum

Property key has end at line-break or end of the string.

Comment and Description

Comment starts with a # and continues until end of line. It's ignore from soil Parser.

Similarly description starts with a : and continues until end of line. It's exporting on soil generated codes. Description writes before the directive.

- This is a comment.

# The user entity for Sample Service API
#
# more description
entity User {
  field name: String
}

Command

command block only contains commands and comments.

command
  = @<command> ( [...args] ) [<block>]
  = @<command> [...args] [<block>]

Split each argument by ,.

In scenario directive, can use special @request command shorthand:

request shorhand
  = <endpoint-reference> <block>
  = <http-method> <http-path> <block>