Skip to content

Field annotations

Dmitrii Chechetkin edited this page Oct 6, 2019 · 4 revisions

@OptionalToken

This annotation should be used on fields that represent tokens that may not be present in parser input.

A whenFollowedBy annotation parameter may be used on conditionally optional fields. If provied, parser will test the following characters for exact match with whenFollowedBy value and fail parent token if the test fails. It is a better practice, however, to mark conditionally optional tokens with @SkipIfFollowedBy annotation.

whenFieldIsNull and whenFieldNotNull context-aware annotations were added in version 0.8. These annotations allow to mark some fields as optional at the parsing stage by analyzing the status of previously populated (or skipped) fields. These annotations take field name as their value.

@SkipIfFollowedBy

Thi annotation should be used on fields that represent conditionally optional tokens.

It takes a string value and works similarly to @OptionalToken annotation with whenFollowedBy parameter.

@CaptureLimit

This annotation should be used on array fields to impose minimum and/or maximum number of tokens to populate the array with.

It takes two int parameters: min and max

@CapturePattern

Thi annotation should be used on String fields to define a regular expression pattern that a token for that field should match.

It takes several parameters:

  • value (or its deprecated alternative pattern): Accepts a regular expression that will be used to match characters from the input. If provided then until parameter will be ignored
  • replacement: Accepts a regular expression replacement parameter that can be used either to:
    • transform matched by defined as value regexp text
    • transform matched by until limiter and append transformation result to the end of captured text
  • until: Accepts a regular expression that Parser will use as stop token for capturing process.
    • If no replacement is specified, then matched by this expression stop token will be discarded.
    • If replacement is specified, then stop token will be transformed using that value and appended to captured text
    • Ignored if either value or pattern are not empty

@CustomMatcher

Should be used on fields that require a custom TokenMatcher. May not be fully supported in latest versions.

@ContextAware

This annotation (added in version 0.8) allows configuring field matcher to exactly match a value previously matched for another field inside a grammar rule represented by the same CompoundToken. The annotation takes one parameter matchField that accepts the name of previosly populated field to be matched.

Clone this wiki locally