onigmo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 60ce173c124c6d7750e87ccd1d834128600923d9abb9b375d42ae21e1da3aa11
4
+ data.tar.gz: f0cebe1ed576df5fc0a360f313fd1d34108e3ce613d7489e57daed87ceed48a1
5
+ SHA512:
6
+ metadata.gz: 7b8fbdd6c0e2c5b751f4e11b5e5f5887596b1ebefe76485b3ae7eafaf8363cacaa960fc8f8cf6667d0fb76072aaa76bd46854938beef61eeba130d0c58be9340
7
+ data.tar.gz: 40a6843a44559aeaa03d074835f4f21d6e57100a777e712fce96753f845446e909815d7ff0bb663982a63b9569da93c120df15a613b24a141092f7eb1893249f
@@ -0,0 +1,31 @@
1
+ name: Main
2
+
3
+ on:
4
+ - push
5
+ - pull_request
6
+
7
+ jobs:
8
+ ci:
9
+ name: CI
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ ruby:
14
+ - "3.0"
15
+ - "3.1"
16
+ - "3.2"
17
+ - "3.3"
18
+ - "head"
19
+ os:
20
+ - "ubuntu-latest"
21
+ - "macos-latest"
22
+ - "windows-latest"
23
+ runs-on: ${{ matrix.os }}
24
+ steps:
25
+ - uses: actions/checkout@master
26
+ - uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: ${{ matrix.ruby }}
29
+ bundler-cache: true
30
+ - name: Test
31
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ /lib/onigmo/onigmo.bundle
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "bundler"
6
+ gem "rake-compiler"
7
+ gem "rake"
8
+ gem "simplecov"
9
+ gem "test-unit"
data/Gemfile.lock ADDED
@@ -0,0 +1,29 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ docile (1.4.0)
5
+ power_assert (2.0.3)
6
+ rake (13.0.6)
7
+ rake-compiler (1.2.5)
8
+ rake
9
+ simplecov (0.22.0)
10
+ docile (~> 1.1)
11
+ simplecov-html (~> 0.11)
12
+ simplecov_json_formatter (~> 0.1)
13
+ simplecov-html (0.12.3)
14
+ simplecov_json_formatter (0.1.4)
15
+ test-unit (3.6.2)
16
+ power_assert
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ bundler
23
+ rake
24
+ rake-compiler
25
+ simplecov
26
+ test-unit
27
+
28
+ BUNDLED WITH
29
+ 2.4.13
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2024-present, Shopify Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # Onigmo
2
+
3
+ A Ruby wrapper around the onigmo regular expression library.
4
+
5
+ > [!WARNING]
6
+ > This library purposefully accesses internal headers of the onigmo library, and as such no compatibility is guaranteed. This library should be used only for debugging, testing, and educational purposes.
7
+
8
+ ## Installation
9
+
10
+ Install the gem and add to the application's Gemfile by executing:
11
+
12
+ $ bundle add onigmo
13
+
14
+ If bundler is not being used to manage dependencies, install the gem by executing:
15
+
16
+ $ gem install onigmo
17
+
18
+ ## Usage
19
+
20
+ The `Onigmo` module provides two methods: `parse` and `compile`.
21
+
22
+ ### parse
23
+
24
+ `Onigmo.parse(source)` gives you back the abstract syntax tree (AST) of the regular expression.
25
+
26
+ ```
27
+ irb(main):001> Onigmo.parse("aaa|bbb*")
28
+ =>
29
+ alternation(
30
+ string("aaa"),
31
+ list(
32
+ string("bb"),
33
+ quantifier(
34
+ lower: 0,
35
+ upper: nil,
36
+ greedy: true,
37
+ string("b")
38
+ )
39
+ )
40
+ )
41
+ ```
42
+
43
+ These nodes each have their own APIs for their respective fields. They also share the following common APIs:
44
+
45
+ * `deconstruct_keys(keys)` - an implementation of pattern matching
46
+ * `pretty_print(q)` - an implementation of pretty printing
47
+ * `as_json` - returns a hash suitable for serialization
48
+ * `to_json` - returns a JSON string suitable for serialization
49
+
50
+ ### compile
51
+
52
+ `Onigmo.compile(source)` gives you back the list of bytecode instructions that onigmo will use to execute the regular expression.
53
+
54
+ ```
55
+ irb(main):001> Onigmo.compile("aaa|bbb*")
56
+ # =>
57
+ [[:push, 9],
58
+ [:exact3, "aaa"],
59
+ [:jump, 15],
60
+ [:exact2, "bb"],
61
+ [:push, 7],
62
+ [:exact1, "b"],
63
+ [:jump, -12],
64
+ [:end]]
65
+ ```
66
+
67
+ Every instruction in the list will be an array. The operands to the instructions will be simple values (i.e., strings, symbols, integers, or arrays).
68
+
69
+ ### visit
70
+
71
+ With the abstract syntax tree, the `Onigmo` module also provides some ability to visit the nodes in the tree. This is done through visitors. A visitor is an object that responds to one or more `visit_*` methods corresponding to the names of the nodes in the tree. For example, if you wanted to visit only the strings in the tree, you could write:
72
+
73
+ ```ruby
74
+ class StringVisitor < Visitor
75
+ attr_reader :strings
76
+
77
+ def initialize(strings)
78
+ @strings = strings
79
+ end
80
+
81
+ def visit_string_node(node)
82
+ strings << node.value
83
+ end
84
+ end
85
+ ```
86
+
87
+ By implementing more `visit_*` methods, you can have access to more nodes in the tree. The default behavior is to walk every node in the tree. You can modify this behavior depending on how you implement the visitor node. If you want to stop visiting (like in the example above) you do nothing. If you want to visit specific child nodes, you would call `visit(child_node)`. If you want to visit all nodes (the default behavior) then you can simply call `super`.
88
+
89
+ ## Development
90
+
91
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test-unit` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
92
+
93
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
94
+
95
+ ## Contributing
96
+
97
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/onigmo.
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/extensiontask"
5
+ require "rake/testtask"
6
+
7
+ desc("Create tmp directory")
8
+ directory("tmp")
9
+
10
+ desc("Clone onigmo repository")
11
+ directory("tmp/onigmo" => "tmp") do
12
+ sh("git clone --depth 1 https://github.com/k-takata/Onigmo.git tmp/onigmo")
13
+ end
14
+
15
+ onigmo_headers = ["regenc.h", "regint.h", "regparse.h"]
16
+ onigmo_headers.each do |filepath|
17
+ desc("Download #{filepath} from onigmo repository")
18
+ file("tmp/onigmo/#{filepath}" => "tmp/onigmo")
19
+
20
+ desc("Copy #{filepath} from onigmo repository")
21
+ file("ext/onigmo/#{filepath}" => "tmp/onigmo/#{filepath}") do
22
+ cp("tmp/onigmo/#{filepath}", "ext/onigmo/#{filepath}")
23
+ end
24
+ end
25
+
26
+ Rake::ExtensionTask.new(:compile) do |ext|
27
+ ext.name = "onigmo"
28
+ ext.ext_dir = "ext/onigmo"
29
+ ext.lib_dir = "lib/onigmo"
30
+ ext.gem_spec = Gem::Specification.load("onigmo.gemspec")
31
+ end
32
+
33
+ Rake::Task[:compile].prerequisites.prepend(
34
+ *onigmo_headers.map { |filepath| "ext/onigmo/#{filepath}" }
35
+ )
36
+
37
+ Rake::TestTask.new(:test) do |t|
38
+ t.libs << "test"
39
+ t.pattern = "test/**/*_test.rb"
40
+ t.verbose = true
41
+ end
42
+
43
+ Rake::Task[:test].enhance([:compile])
44
+
45
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+
6
+ $:.unshift(File.expand_path("../lib", __dir__))
7
+ require "onigmo"
8
+
9
+ require "irb"
10
+ IRB.start(__FILE__)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+
5
+ append_cflags("-Wno-missing-noreturn")
6
+
7
+ create_makefile("onigmo/onigmo")