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

. does not match '\u2028' #400

Closed
raine opened this issue Sep 22, 2018 · 4 comments
Closed

. does not match '\u2028' #400

raine opened this issue Sep 22, 2018 · 4 comments

Comments

@raine
Copy link

raine commented Sep 22, 2018

Not sure if intentional. If so, how can I match it?

start -> .
const nearley = require('nearley')
const grammar = require('./test')

const parser = new nearley.Parser(
  nearley.Grammar.fromCompiled(grammar)
)

parser.feed('\u2028')
Error: invalid syntax at line 1 col 1:

  

  ^
Unexpected "
"
@tjvr
Copy link
Collaborator

tjvr commented Sep 23, 2018

I'm not sure, but perhaps you want [^] rather than .?

Sent with GitHawk

@raine
Copy link
Author

raine commented Sep 23, 2018

Interesting. How does that work and why isn't it same as .?

@tjvr
Copy link
Collaborator

tjvr commented Sep 23, 2018

It's a quirk of JS RegExps. Quoting from the readme of a different project:

the dot /./ doesn't include newlines. Use [^] instead if you want to match newlines too.

Since an excluding character ranges like /[^ ]/ (which matches anything but a space) will include newlines, you have to be careful not to include them by accident!

The character class [^] matches anything. ^ in a character class means "anything but", so following it with an empty set just means "anything".

The dot . excludes newlines by default, unless you use the dotAll modifier, which Nearley doesn't.

Sent with GitHawk

@kach kach closed this as completed Dec 21, 2018
@abitrolly
Copy link

@kach is there a place in docs to document dot . behavior and list things like [^]? I came to ask the same question - why . doesn't match newlines.

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

4 participants