Skip to content

Parametrized types do not allow spaces after "(" #792

Closed
kaitai-io/kaitai_struct_compiler
#207
@Mingun

Description

@Mingun

Following KSY raises error until space between ( and true will be deleted:

meta:
  id: type_references
seq:
  - id: field
    type: 'type::sub( true , 2 )'
types:
  type:
    types:
      sub:
        params:
          - id: par
            type: bool
          - id: par2
            type: u1
        seq: []

I think that is unnecessary restriction and it can be eliminated. The root of the problem is that parametric type parsing is partially done in manually, and partially using expression language. It is much easier to always parse the entire string as an expression, at the same time you can:

  • allow spaces between ::
  • allow spaces in begin and at end of string
  • allow spaces before (

Now corresponding PEG rule for type references is:

parseTypeRef = name ("::" name)* ("(" args _ ")")? EOS;
args = expr (_ "," _ expr)*;
...

But it would be:

parseTypeRef = _ name (_ "::" _ name)* _ ("(" _ args _ ")" _)? EOS;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions