lexical_analyzer 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/lexical_analyzer/lexical_rule.rb +27 -24
- data/lib/lexical_analyzer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbf597af00d3c0d71bdc33a3c045564b93b08651
|
4
|
+
data.tar.gz: e317b6e6b78414b7640d237a758dac69c99a0508
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 134762490b51644c6bdfc648095b821bbaeeaa339a4906f63b13c63e2612eb40dce2c0e67c517c1e44d10cd47168c48092e44a66f124fb6b88d09b0ee5f22a82
|
7
|
+
data.tar.gz: 508603f176c0d591bd80c114bb2e44a09a46238e3bbc98a2347d7a21cf9069b21d328ebf5a4cb3067a145fdf40c9e2c695d17c0d18181c86c6ec5d0a41344450
|
data/README.md
CHANGED
@@ -62,7 +62,7 @@ LexicalRule.new(:equality, /\A==/)
|
|
62
62
|
LexicalRule.new(:spaces, /\A\s+/) {|_value| false }
|
63
63
|
|
64
64
|
# Rule with an integer block returns [:integer, an_integer] on a match.
|
65
|
-
LexicalRule.new(:integer, /\A\d+/) {|value| [
|
65
|
+
LexicalRule.new(:integer, /\A\d+/) {|value| [symbol, value.to_i] }
|
66
66
|
|
67
67
|
# Rule with a block that expands of to a sub-rule. Returns the value of the
|
68
68
|
# lexical analyzer in the captured variable ka.
|
@@ -1,24 +1,27 @@
|
|
1
|
-
# The Ruby Compiler Toolkit Project - Lexical Rule
|
2
|
-
# A rule for lexical analysis.
|
3
|
-
|
4
|
-
class LexicalRule
|
5
|
-
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
# The Ruby Compiler Toolkit Project - Lexical Rule
|
2
|
+
# A rule for lexical analysis.
|
3
|
+
|
4
|
+
class LexicalRule
|
5
|
+
|
6
|
+
# Read access to the symbol instance variable.
|
7
|
+
attr_reader :symbol
|
8
|
+
|
9
|
+
# Create a lexical rule.
|
10
|
+
def initialize(symbol, regex, &action)
|
11
|
+
@symbol = symbol
|
12
|
+
@regex = regex
|
13
|
+
|
14
|
+
define_singleton_method(:call, &action) if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
# Does this rule match?
|
18
|
+
def match(text)
|
19
|
+
text.match(@regex)
|
20
|
+
end
|
21
|
+
|
22
|
+
# The default rule action.
|
23
|
+
def call(value)
|
24
|
+
[symbol, value]
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|