Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/ in annotations #123

Open
codalogic opened this issue Mar 29, 2018 · 3 comments
Open

/ in annotations #123

codalogic opened this issue Mar 29, 2018 · 3 comments

Comments

@codalogic
Copy link
Contributor

We currently define what's allowed in tbd directives and annotations as:

multi-line-parameters = *(comment / q-string / regex /
                   not-multi-line-special)

The presence of regex means that any / characters in the parameters will be treated as forming a regular expression. This allows assertion annotations like:

"link" : @{assert ($other == "ok" && $ =~ /p\d{1,2}/i) ||
          ($other == "bad" && $ =~ /x\d{1,3}/i) } string

But is problematic if we want to have assertion annotations such as:

"size" : @{assert $ / 4 == 2} integer

We could fix that by having something like:

"size" : @{assert $ idiv 4 == 2} integer

where idiv means integer divide.

But that doesn't allow for something like:

"geo" : @{abnf 1*DIGIT "." 1*DIGIT ("N" / "S") "," 1*DIGIT "." 1*DIGIT ("E" / "W") } string

We could remove the special meaning for /, and say if you want a regex in an annotation, then you have to define some sort of function, such as:

"link" : @{assert ($other == "ok" && re( $, "/p\d{1,2}/i" )) ||
          ($other == "bad" && re( $, "/x\d{1,3}/i" )) } string

That would basically means changing the above rule to:

multi-line-parameters = *(comment / q-string /
                   not-multi-line-special)
not-multi-line-special = spaces / %x21 / %x23-3A /
                   %x3C-7C / %x7E-10FFFF ; not ", ; or }
@anewton1998
Copy link
Contributor

This seems reasonable to me. Make it so!

@codalogic
Copy link
Contributor Author

:-)

@codalogic
Copy link
Contributor Author

codalogic commented Mar 29, 2018

One slight issue with putting regexes in q-string is that, where we want, say \d we have to do \\d, e.g.:

"link" : @{assert re( $, "/p\\d{1,2}\\n/i" ) } string

We could consider supporting the Ruby style single quoted string that only allows escaping `. Then we could allow:

"link" : @{assert re( $, '/p\d{1,2}\n/i' ) } string

If you think that's important let me know. At the moment we probably have bigger fish to fry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants