Giter Club home page Giter Club logo

Comments (9)

kkos avatar kkos commented on August 28, 2024

Oniguruma has variable syntax/behavior function.
I don't know which syntax mode you are using.
If you are using default syntax(== Ruby), then [^\/] can match a newline.
ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC flag is disabled in default syntax.

if /(/)(?=[^\/]/[ix])/ =~ "/\n/ix"
puts "MATCH"
else
puts "NOT MATCH"
end

==> MATCH
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

You should go to ruby community if you ask about behavior of ruby regexp.

from oniguruma.

hediyi avatar hediyi commented on August 28, 2024

Thank you very much for the reply! πŸ˜‡

I'm trying to fix some bug of the Ruby language package of Atom, which I believe is using oniguruma as their regex engine. Actually, the bug is the package can't recognize a multi-line regex. The problem lies somewhere in

(?<![\\w)])((/))(?![?*+])
(?=
  (\\\\/|[^/])*
  /[eimnosux]*\\s*
)

which is basically a more verbose version of the previous example. It's really tricky to differentiate the division operator / and regex delimiter / without parsing the Ruby code. πŸ˜‚

from oniguruma.

hediyi avatar hediyi commented on August 28, 2024

I even tried ((/))(?=[^/]*/), it matches a single-line regex, but still not multi-line regex, so I suspected that [^/] in the lookahead doesn't match a LF.

Now that I think about it, maybe I've looked into the wrong spot.

from oniguruma.

kkos avatar kkos commented on August 28, 2024

I have never used Atom. I don't know about it.
But if atom/language-ruby uses oniguruma as regexp engine, why the package.json dosn't include dependencies to oniguruma module.
Is Atom running on JavaScript on Browser?

from oniguruma.

hediyi avatar hediyi commented on August 28, 2024

Pretty much, it's written in CoffeeScript, to be exact, and running on Node.js. The UI is basically parsed HTML and CSS, I guess you can call it a desktop editor created with Web technologies πŸ˜„

why the package.json dosn't include dependencies to oniguruma module

It has, in the core: https://github.com/atom/atom/blob/9ea68024acccd7dc7494f50d03496c16b193c0c4/package.json#L46
I think oniguruma backs up all its language packages, and also the find-and-replace feature.

from oniguruma.

kkos avatar kkos commented on August 28, 2024

I have installed Atom 1.8.0 in Windows.
I tried to run your last regexp in it.
(Very difficult for me to run coffee-script in Atom. I hacked character-count package.)
And it match with multi-line string.
m[0] = '/'.

file: .atom/.apm/character-count/lib/character-count.coffee
module.exports =
count: ->
m = "/\n\n\n/".match(/((/))(?=[^\/]*/)/)
alert(m[0])

activate: (state) ->
atom.commands.add 'atom-workspace', 'character-count:count', => @count()

from oniguruma.

hediyi avatar hediyi commented on August 28, 2024

πŸ‘ @kkos.

I also tried /[^/]*/ in the find-and-replace (to find slashes in ) with regex, it worked. But in the grammar file of a language package, no luck; even /\n*/ doesn't work, no idea why.

To minimize the possibilities why this doesn't work, I wrote a grammar file from scratch, this is the only rule in the grammar:

image

When the slashes are in the same line, it matches (see the scopes at cursor):

image

But if put newlines in between, it doesn't (see the scopes at cursor and the change of color):

image

It looks like a pattern in the grammar file doesn't search across linesβ€”if it can't find a match in a line, it just starts fresh in the next line.

from oniguruma.

hediyi avatar hediyi commented on August 28, 2024

Found the answer in TextMate's manual which Atom's grammars are based on:

Note that the regular expressions are matched against only a single line of the document at a time. That means it is not possible to use a pattern that matches multiple lines. The reason for this is technical: being able to restart the parser at an arbitrary line and having to re-parse only the minimal number of lines affected by an edit. In most situations, it is possible to use the begin/end model to overcome this limitation.

Thanks for your time, really really appreciate it πŸ˜‰

from oniguruma.

kkos avatar kkos commented on August 28, 2024

I thank for your investigation.

from oniguruma.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.