fop_lang 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62ded9f974ca670a6eca5d4b293f98195af25ab476e9b3571e7def5299499fa9
4
- data.tar.gz: b53b6e276ee31f122571a096dd534ed5c1407d27384fab78d216886322751fcb
3
+ metadata.gz: 711af4fad2907616e057049dcb84bce16ffdb381b3601a387dc7260cc16057d3
4
+ data.tar.gz: 40da554ca0cb21f275748593921bdc616dcf8cdfe5d4fa31494f588f2c25d66c
5
5
  SHA512:
6
- metadata.gz: 45509b09122e4f76f1f8219d8c0f094bc5ac77231dec25f6e0e9818932b68186d74c71dd74db80638dcfc9bae210892b563e660004cfd32c25f439c761c3edc2
7
- data.tar.gz: 49c6153cf728e909e60bc8fa1f1214dcdd8f9532703c8bc3455999aac1aa421c629370e1c7669bc9a846b5886fa2f10b7f5b698426cae2830e73ca9623a32a4a
6
+ metadata.gz: 0253a6446b88b6de112f00a95c81f1d5f710a859998e5b3d8df21d64caecc8e013ab1edec2b68047558f8053ce135b60082078f85db1f7aa16a93b86aa487093
7
+ data.tar.gz: c7f0cb0387df52a3ea121e3e91a35e0444afe8862aabe054ec433d889955ee9221129fd0c07f7e36d6c71e6b9ab33f30cd16264447dfda24d29babb671112140
data/README.md CHANGED
@@ -1,44 +1,75 @@
1
1
  # fop_lang
2
2
 
3
- Fop is a tiny expression language implemented in Ruby for text filtering and modification.
3
+ Fop (Filter and OPperations language) is an experimental, tiny expression language in the vein of awk and sed. This is a Ruby implementation. It is useful for simultaneously matching and transforming text input.
4
4
 
5
- ## Examples
5
+ ## Release Number Example
6
+
7
+ This example takes in GitHub branch names, decides if they're release branches, and if so, increments the version number.
6
8
 
7
9
  ```ruby
8
- f = Fop("release-{N}.{N+1}.{N=0}")
10
+ f = Fop('release-{N}.{N+1}.{N=0}')
9
11
 
10
- puts f.apply("release-5.99.1")
11
- => "release-5.100.0"
12
+ puts f.apply('release-5.99.1')
13
+ => 'release-5.100.0'
12
14
 
13
- puts f.apply("release-5")
15
+ puts f.apply('release-5')
14
16
  => nil
15
17
  # doesn't match the pattern
16
18
  ```
17
19
 
20
+ ## Anatomy of a Fop expression
21
+
22
+ `Text Literal {Operation}`
23
+
24
+ The above expression contains the only two parts of Fop (except for the wildcard and escape characters).
25
+
26
+ **Text Literals**
27
+
28
+ A text literal works how it sounds: the input must match it exactly. The only exception is the `*` (wildcard) character, which matches 0 or more of anything. Wildcards can be used anywhere except inside `{...}` (operations).
29
+
30
+ If `\` (escape) is used before the special characters `*`, `{` or `}`, then that character is treated like a text literal. It's recommended to use single-quoted Ruby strings with Fop expressions that so you don't need to double-escape.
31
+
32
+ **Operations**
33
+
34
+ Operations are the interesting part of Fop, and are specified between `{` and `}`. An Operation can consist of one to three parts:
35
+
36
+ 1. Matching character class (required): Defines what characters the operation will match and operate on.
37
+ * `N` is the numeric class and will match one or more digits.
38
+ * `A` is the alpha class and will match one or more letters (lower or upper case).
39
+ * `W` is the word class and matches alphanumeric chars and underscores.
40
+ * `*` is the wildcard class and greedily matches everything after it.
41
+ 3. Operator (optional): What to do to the matching characters.
42
+ * `=` Replace the matching character(s) with the given argument. If no argument is given, drop the matching chars.
43
+ * `+` Perform addition on the matching number and the argument (`N` only).
44
+ * `-` Subtract the argument from the matching number (`N` only).
45
+ 5. Operator argument (required for some operators): meaning varies by operator.
46
+
47
+ ## More Examples
48
+
18
49
  ```ruby
19
- f = Fop("release-{N=5}.{N+1}.{N=0}")
50
+ f = Fop('release-{N=5}.{N+1}.{N=0}')
20
51
 
21
- puts f.apply("release-4.99.1")
22
- => "release-5.100.0"
52
+ puts f.apply('release-4.99.1')
53
+ => 'release-5.100.0'
23
54
  ```
24
55
 
25
56
  ```ruby
26
- f = Fop("release-*{N=5}.{N+100}.{N=0}")
57
+ f = Fop('release-*{N=5}.{N+100}.{N=0}')
27
58
 
28
- puts f.apply("release-foo-4.100.1")
29
- => "release-foo-5.200.0"
59
+ puts f.apply('release-foo-4.100.1')
60
+ => 'release-foo-5.200.0'
30
61
  ```
31
62
 
32
63
  ```ruby
33
- f = Fop("release-{N=5}.{N+1}.{N=0}{*=}")
64
+ f = Fop('release-{N=5}.{N+1}.{N=0}{*=}')
34
65
 
35
- puts f.apply("release-4.100.1.foo.bar")
36
- => "release-5.101.0"
66
+ puts f.apply('release-4.100.1.foo.bar')
67
+ => 'release-5.101.0'
37
68
  ```
38
69
 
39
70
  ```ruby
40
- f = Fop("{W=version}-{N=5}.{N+1}.{N=0}")
71
+ f = Fop('{W=version}-{N=5}.{N+1}.{N=0}')
41
72
 
42
- puts f.apply("release-4.100.1")
43
- => "version-5.101.0"
73
+ puts f.apply('release-4.100.1')
74
+ => 'version-5.101.0'
44
75
  ```
data/lib/fop/nodes.rb CHANGED
@@ -15,6 +15,7 @@ module Fop
15
15
  Match = Struct.new(:wildcard, :tokens) do
16
16
  NUM = "N".freeze
17
17
  WORD = "W".freeze
18
+ ALPHA = "A".freeze
18
19
  WILD = "*".freeze
19
20
  BLANK = "".freeze
20
21
 
@@ -37,7 +38,8 @@ module Fop
37
38
  @regex =
38
39
  case @match
39
40
  when NUM then Regexp.new((wildcard ? ".*?" : "^") + "[0-9]+")
40
- when WORD then Regexp.new((wildcard ? ".*?" : "^") + "[a-zA-Z]+")
41
+ when WORD then Regexp.new((wildcard ? ".*?" : "^") + "\\w+")
42
+ when ALPHA then Regexp.new((wildcard ? ".*?" : "^") + "[a-zA-Z]+")
41
43
  when WILD then /.*/
42
44
  else raise ParserError, "Unknown match type '#{@match}'"
43
45
  end
data/lib/fop/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fop
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fop_lang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger