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

whitespace is needed to be parsed with square bracket #104

Open
lounlee opened this issue Aug 14, 2017 · 1 comment
Open

whitespace is needed to be parsed with square bracket #104

lounlee opened this issue Aug 14, 2017 · 1 comment

Comments

@lounlee
Copy link

lounlee commented Aug 14, 2017

Like below, when I made a rule as fox[*], it needs a whitespace to parse the part with [*]. I understood square bracket as or, and round bracket as and. The round backets seems to work correctly, but square brackets seems to work differently with or. Was it intended to work like this?

rule: fox[*]
-> fox (O)
-> foxs (X)
-> foxes (X)
-> fox fox (O)

rule: fox[s|es]
-> fox (O)
-> foxs (X)
-> foxes (X)
-> fox s (O)
-> fox es (O)
-> fox fox (X)

rule: fox(*)
-> fox (X)
-> foxs (O)
-> foxes (O)
-> fox fox (O)

rule: fox(s|es)
-> fox (X)
-> foxs (O)
-> foxes (O)
-> fox fox (X)
@kirsle
Copy link
Member

kirsle commented Aug 14, 2017

Optionals are meant to have spaces around them. They're for "optional words", not "or".

The regular expression the optionals turn into makes use of the \b word-boundary metacharacter, which matches on characters that aren't "word characters" (numbers or letters), so if the optional is directly touching a word, no word boundary is detected and it doesn't match properly.

You could use an array for common suffixes. With ! array s = s es, the trigger syntax @s would get expanded into the non-capturing regular expression (?:s|es), so it should work fine directly touching other words in your trigger, like

+ fox@s

# the regexp would become:
/^fox(?:s|es)$/

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