scanner 0.0.3 → 0.0.4
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.
- data/lib/scanner/scanner.rb +16 -0
- data/lib/scanner/version.rb +1 -1
- metadata +4 -4
data/lib/scanner/scanner.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# THis is the module to include in your class to inherit the scanner functionality
|
1
2
|
module Scanner
|
2
3
|
|
3
4
|
def self.append_features(aModule)
|
@@ -10,6 +11,20 @@ module Scanner
|
|
10
11
|
@check_for_token_separator = {}
|
11
12
|
@separator = nil
|
12
13
|
|
14
|
+
# defines a token of the language
|
15
|
+
# Each token is defined by a symbol, used to identify the token, and a
|
16
|
+
# regular expression that the token should match. An optional third
|
17
|
+
# parameter accepts a hash of options. For example:
|
18
|
+
#
|
19
|
+
# token :number, '\d+'
|
20
|
+
#
|
21
|
+
# will match strings containing digits.
|
22
|
+
#
|
23
|
+
# Some care is needed when defining tokens that collide with other
|
24
|
+
# tokens. For instance, a languange may define the token '==' and the
|
25
|
+
# token '='. You need to define the double equals before the single
|
26
|
+
# equals, otherwise the string '==' will be identified as two '=' tokens,
|
27
|
+
# instead of a '==' token.
|
13
28
|
def token(token_symbol, regular_expression, options = {})
|
14
29
|
modified_reg_exp = "\\A#{regular_expression}"
|
15
30
|
@language_tokens[token_symbol] = /#{modified_reg_exp}/
|
@@ -60,6 +75,7 @@ module Scanner
|
|
60
75
|
|
61
76
|
include Enumerable
|
62
77
|
|
78
|
+
# Sets the string to parse
|
63
79
|
def parse(program)
|
64
80
|
@program = program
|
65
81
|
@token_list = []
|
data/lib/scanner/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scanner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -77,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
77
|
version: '0'
|
78
78
|
segments:
|
79
79
|
- 0
|
80
|
-
hash: -
|
80
|
+
hash: -1550862085541949899
|
81
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
82
|
none: false
|
83
83
|
requirements:
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
version: '0'
|
87
87
|
segments:
|
88
88
|
- 0
|
89
|
-
hash: -
|
89
|
+
hash: -1550862085541949899
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project:
|
92
92
|
rubygems_version: 1.8.24
|