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

Support RegExp #43

Closed
phaux opened this issue Jun 30, 2015 · 9 comments
Closed

Support RegExp #43

phaux opened this issue Jun 30, 2015 · 9 comments

Comments

@phaux
Copy link

phaux commented Jun 30, 2015

Example:

syntax:
  identifier: /\b[a-z_][a-z_0-9]*\b/i
  operator: /// ^ (
    ?: [-=]>             # function
     | [-+*/%<>&|^!?=]=  # compound assign / compare
     | >>>=?             # zero-fill right shift
     | ([-+:])\1         # doubles
     | ([&|<>])\2=?      # logic / shift
     | \?\.              # soak access
     | \.{2,3}           # range or splat
  ) ///

JS Equivalent:

{
  syntax: {
    identifier: /\b[a-z_][a-z_0-9]*\b/i,
    operator: /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/
  }
}

I tried it while writing a custom atom editor syntax plugin and was surprised that it doesn't work.

@ghost
Copy link

ghost commented Jun 30, 2015

Just like JSON is purely for data notation, I don't think CSON should support regular expressions. It's a form of executable code that could be misused.

In your case, you could put it in a string and pass it into new RegExp(pattern).

@jkrems
Copy link
Contributor

jkrems commented Jun 30, 2015

I don't know, since it maps 1:1 to a string, it could arguably be called "data". Since we don't support unquoted strings, there shouldn't be a problem.

@jkrems
Copy link
Contributor

jkrems commented Jun 30, 2015

@phaux Thanks for bringing this up, btw.

As for more arguments in favor of support: We already support static/const expressions for numeric operations. Which is even more similar to "executable code". But we'd have to figure out what we want to support in detail (e.g. coffee-script regex support is not just simple regex literals IIRC).

@phaux
Copy link
Author

phaux commented Jul 1, 2015

@khoomeister

There's a few problems with using strings to contain regexes:

  • No syntax highlighting
  • Need to double escape everything
  • No multi-line regexp
    • No comments inside regexp

The only downside I can think of is that it's not obvious what the JSON representation of v: /abc/gi should be. Should it just turn into string or something like

{
  "v": {
    "$regexp": "abc",
    "$flags": "gi"
  }
}

Or maybe it's not that important?

@jkrems
Copy link
Contributor

jkrems commented Jul 1, 2015

There's no 1:1 mapping between CSON and JSON (see: a: 1/0 which can't be expressed in JSON), so I wouldn't be too concerned about how the JSON-equivalent. :)

@jamen
Copy link

jamen commented Sep 24, 2015

I like the idea, but it doesn't feel right.

As CSON is a declarative language, if there were ever a standard for CSON and parsers made in other languages I would personally omit this aspect because Regex is represented many different ways throughout multiple languages, where as things like numbers, strings, etc. have some uniformity across languages.

@texastoland
Copy link

This is now blocking noseglid/atom-build#178 😿

@jkrems
Copy link
Contributor

jkrems commented Nov 25, 2015

@jamen I think that's not necessarily a concern. E.g. there's precedent in projects like https://github.com/ua-parser/uap-core/blob/master/regexes.yaml where the same set of regexes, in that case stored in a yaml file, is shared across many languages.

@dnalot I'll try to figure out how much it would take to add support.

@jkrems
Copy link
Contributor

jkrems commented Nov 25, 2015

Added supported in v1.3.0

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