rexical 1.0.5 → 1.0.7
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 +7 -0
- data/CHANGELOG.rdoc +13 -1
- data/DOCUMENTATION.en.rdoc +210 -214
- data/README.rdoc +13 -6
- data/Rakefile +3 -1
- data/lib/rexical.rb +5 -5
- data/lib/rexical/generator.rb +147 -161
- data/lib/rexical/rexcmd.rb +3 -1
- data/sample/calc3.tab.rb +1 -1
- data/sample/error1.rex +1 -1
- data/sample/error2.rex +1 -1
- data/sample/sample.rex +1 -1
- data/sample/sample.rex.rb +92 -100
- data/test/assets/test.rex +4 -0
- data/test/test_generator.rb +59 -3
- metadata +78 -61
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d6b78dc8daf9900783617edca9228ca4d4640f808b6251775e7105f6f20d1e9b
|
4
|
+
data.tar.gz: 01dd220d9a85cc3236f79b6596fa6b64b9f95456b71d5340fb4284c48db20fa5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6fcd99b73957780f3617ddc9317d24207dd9be43c9bb42d55863c1b4f7cfa591d2a48a9f9b0e200089303dbb0c8cf64628c1514c9181220e555721b1274c28f7
|
7
|
+
data.tar.gz: d6f222da2d448cbb7b5b2a849f7a1549cde2870301e557217825e428668fd57c02eb05ffcf8332f993d8ddf14ab6dca7d5a39e2ec0bb0fa5fe444b3bfff083b2
|
data/CHANGELOG.rdoc
CHANGED
data/DOCUMENTATION.en.rdoc
CHANGED
@@ -1,215 +1,211 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
-
|
15
|
-
-
|
16
|
-
-
|
17
|
-
|
18
|
-
--independent independent mode.
|
1
|
+
= REX: Ruby Lex for Racc
|
2
|
+
|
3
|
+
|
4
|
+
== About
|
5
|
+
|
6
|
+
Lexical Scanner Generator used with Racc for Ruby
|
7
|
+
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
rex [options] grammarfile
|
12
|
+
|
13
|
+
-o --output-file filename designate output filename
|
14
|
+
-s --stub append stub main for debugging
|
15
|
+
-i --ignorecase ignore character case
|
16
|
+
-C --check-only only check syntax
|
17
|
+
--independent independent mode
|
19
18
|
-d --debug print debug information
|
20
|
-
-h --help print usage
|
21
|
-
--version print version
|
22
|
-
--copyright print copyright
|
23
|
-
|
24
|
-
|
25
|
-
== Default Output Filename
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
require 'foo.rex'
|
31
|
-
|
32
|
-
|
33
|
-
== Grammar File Format
|
34
|
-
|
35
|
-
A definition
|
36
|
-
and
|
37
|
-
|
38
|
-
|
39
|
-
Summary:
|
40
|
-
|
41
|
-
[Header
|
42
|
-
"class" Foo
|
43
|
-
["option"
|
44
|
-
[options] ]
|
45
|
-
["inner"
|
46
|
-
[methods] ]
|
47
|
-
["macro"
|
48
|
-
[macro-name regular-expression] ]
|
49
|
-
"rule"
|
50
|
-
[start-state] pattern [actions]
|
51
|
-
"end"
|
52
|
-
[Footer
|
53
|
-
|
54
|
-
|
55
|
-
=== Grammar File Example
|
56
|
-
|
57
|
-
class Foo
|
58
|
-
macro
|
59
|
-
BLANK \s+
|
60
|
-
DIGIT \d+
|
61
|
-
rule
|
62
|
-
{BLANK}
|
63
|
-
{DIGIT} { [:NUMBER, text.to_i] }
|
64
|
-
. { [text, text] }
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
== Header
|
69
|
-
|
70
|
-
All the contents described before the
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
== Footer
|
75
|
-
|
76
|
-
All the contents described after the
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
== Rule
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
The class name
|
85
|
-
If
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
=== Rule
|
90
|
-
|
91
|
-
class Foo
|
92
|
-
class Bar::Foo
|
93
|
-
|
94
|
-
|
95
|
-
== Option Section ( Optional )
|
96
|
-
|
97
|
-
"option"
|
98
|
-
|
99
|
-
"ignorecase"
|
100
|
-
"stub" append stub main for
|
101
|
-
"independent" independent mode,
|
102
|
-
|
103
|
-
|
104
|
-
== Inner Section ( Optional )
|
105
|
-
|
106
|
-
"inner"
|
107
|
-
The contents defined here are defined by the
|
108
|
-
of the generated scanner.
|
109
|
-
|
110
|
-
|
111
|
-
== Macro Section ( Optional )
|
112
|
-
|
113
|
-
"macro"
|
114
|
-
|
115
|
-
A
|
116
|
-
|
117
|
-
|
118
|
-
=== Macro
|
119
|
-
|
120
|
-
DIGIT \d+
|
121
|
-
IDENT [a-zA-Z_][a-zA-Z0-9_]*
|
122
|
-
BLANK [\ \t]+
|
123
|
-
REMIN \/\*
|
124
|
-
REMOUT \*\/
|
125
|
-
|
126
|
-
|
127
|
-
== Rule Section
|
128
|
-
|
129
|
-
"rule"
|
130
|
-
|
131
|
-
[state] pattern [actions]
|
132
|
-
|
133
|
-
|
134
|
-
=== state: Start State ( Optional )
|
135
|
-
|
136
|
-
A start state is
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
The
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
{
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
This specification is provisional and may be changed without a preliminary
|
214
|
-
announcement.
|
215
|
-
|
19
|
+
-h --help print usage
|
20
|
+
--version print version
|
21
|
+
--copyright print copyright
|
22
|
+
|
23
|
+
|
24
|
+
== Default Output Filename
|
25
|
+
|
26
|
+
The destination file for foo.rex is foo.rex.rb.
|
27
|
+
To use, include the following in the Ruby source code file.
|
28
|
+
|
29
|
+
require 'foo.rex'
|
30
|
+
|
31
|
+
|
32
|
+
== Grammar File Format
|
33
|
+
|
34
|
+
A definition consists of a header section, a rule section,
|
35
|
+
and a footer section. The rule section includes one or more clauses.
|
36
|
+
Each clause starts with a keyword.
|
37
|
+
|
38
|
+
Summary:
|
39
|
+
|
40
|
+
[Header section]
|
41
|
+
"class" Foo
|
42
|
+
["option"
|
43
|
+
[options] ]
|
44
|
+
["inner"
|
45
|
+
[methods] ]
|
46
|
+
["macro"
|
47
|
+
[macro-name regular-expression] ]
|
48
|
+
"rule"
|
49
|
+
[start-state] pattern [actions]
|
50
|
+
"end"
|
51
|
+
[Footer section]
|
52
|
+
|
53
|
+
|
54
|
+
=== Grammar File Description Example
|
55
|
+
|
56
|
+
class Foo
|
57
|
+
macro
|
58
|
+
BLANK \s+
|
59
|
+
DIGIT \d+
|
60
|
+
rule
|
61
|
+
{BLANK}
|
62
|
+
{DIGIT} { [:NUMBER, text.to_i] }
|
63
|
+
. { [text, text] }
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
== Header Section ( Optional )
|
68
|
+
|
69
|
+
All of the contents described before the definitions in the rule section are
|
70
|
+
copied to the beginning of the output file.
|
71
|
+
|
72
|
+
|
73
|
+
== Footer Section ( Optional )
|
74
|
+
|
75
|
+
All the contents described after the definitions in the rule section are
|
76
|
+
copied to the end of the output file.
|
77
|
+
|
78
|
+
|
79
|
+
== Rule Section
|
80
|
+
|
81
|
+
The rule section starts at the line beginning with the "class" keyword
|
82
|
+
and ends at the line beginning with the "end" keyword.
|
83
|
+
The class name is specified after the "class" keyword.
|
84
|
+
If a module name is specified, the class will be included in the module.
|
85
|
+
A class that inherits Racc::Parser is generated.
|
86
|
+
|
87
|
+
|
88
|
+
=== Example of Rule Section Definition
|
89
|
+
|
90
|
+
class Foo
|
91
|
+
class Bar::Foo
|
92
|
+
|
93
|
+
|
94
|
+
== Option Section ( Optional )
|
95
|
+
|
96
|
+
This section begins with the "option" keyword.
|
97
|
+
|
98
|
+
"ignorecase" ignore the character case when pattern matching
|
99
|
+
"stub" append stub main for debugging
|
100
|
+
"independent" independent mode, do not inherit Racc.
|
101
|
+
|
102
|
+
|
103
|
+
== Inner Section for User Code ( Optional )
|
104
|
+
|
105
|
+
This section begins with the "inner" keyword.
|
106
|
+
The contents defined here are defined by the contents of the class
|
107
|
+
of the generated scanner.
|
108
|
+
|
109
|
+
|
110
|
+
== Macro Section ( Optional )
|
111
|
+
|
112
|
+
This section begins with the "macro" keyword.
|
113
|
+
A name is assigned to one regular expression.
|
114
|
+
A space character (0x20) can be included by using a backslash \ to escape.
|
115
|
+
|
116
|
+
|
117
|
+
=== Example of Macro Definition
|
118
|
+
|
119
|
+
DIGIT \d+
|
120
|
+
IDENT [a-zA-Z_][a-zA-Z0-9_]*
|
121
|
+
BLANK [\ \t]+
|
122
|
+
REMIN \/\*
|
123
|
+
REMOUT \*\/
|
124
|
+
|
125
|
+
|
126
|
+
== Rule Section
|
127
|
+
|
128
|
+
This section begins with the "rule" keyword.
|
129
|
+
|
130
|
+
[state] pattern [actions]
|
131
|
+
|
132
|
+
|
133
|
+
=== state: Start State ( Optional )
|
134
|
+
|
135
|
+
A start state is indicated by an identifier beginning with ":", a Ruby symbol.
|
136
|
+
If uppercase letters follow the ":", the state becomes an exclusive start state.
|
137
|
+
If lowercase letters follow the ":", the state becomes an inclusive start state.
|
138
|
+
The initial value and the default value of a start state are nil.
|
139
|
+
|
140
|
+
|
141
|
+
=== pattern: String Pattern
|
142
|
+
|
143
|
+
A regular expression specifies a character string.
|
144
|
+
A regular expression description may include a macro definition enclosed
|
145
|
+
by curly braces { }.
|
146
|
+
A macro definition is used when the regular expression includes whitespace.
|
147
|
+
|
148
|
+
|
149
|
+
=== actions: Processing Actions ( Optional )
|
150
|
+
|
151
|
+
An action is executed when the pattern is matched.
|
152
|
+
The action defines the process for creating the appropriate token.
|
153
|
+
A token is a two-element array containing a type and a value, or is nil.
|
154
|
+
The following elements can be used to create a token.
|
155
|
+
|
156
|
+
lineno Line number ( Read Only )
|
157
|
+
text Matched string ( Read Only )
|
158
|
+
state Start state ( Read/Write )
|
159
|
+
|
160
|
+
The action is a block of Ruby code enclosed by { }.
|
161
|
+
Do not use functions that exit the block and change the control flow.
|
162
|
+
( return, exit, next, break, ... )
|
163
|
+
If the action is omitted, the matched character string is discarded,
|
164
|
+
and the process advances to the next scan.
|
165
|
+
|
166
|
+
|
167
|
+
=== Example of Rule Section Definition
|
168
|
+
|
169
|
+
{REMIN} { state = :REM ; [:REM_IN, text] }
|
170
|
+
:REM {REMOUT} { state = nil ; [:REM_OUT, text] }
|
171
|
+
:REM (.+)(?={REMOUT}) { [:COMMENT, text] }
|
172
|
+
{BLANK}
|
173
|
+
-?{DIGIT} { [:NUMBER, text.to_i] }
|
174
|
+
{WORD} { [:word, text] }
|
175
|
+
. { [text, text] }
|
176
|
+
|
177
|
+
== Comments ( Optional )
|
178
|
+
|
179
|
+
Any text following a "#" to the end of the line becomes a comment.
|
180
|
+
|
181
|
+
|
182
|
+
== Using the Generated Class
|
183
|
+
|
184
|
+
=== scan_setup( str )
|
185
|
+
|
186
|
+
Initializes the scanner with the str string argument.
|
187
|
+
This is redefined and used.
|
188
|
+
|
189
|
+
|
190
|
+
=== scan_str( str )
|
191
|
+
|
192
|
+
Parses the string described in the defined grammar.
|
193
|
+
The tokens are stored internally.
|
194
|
+
|
195
|
+
|
196
|
+
=== scan_file( filename )
|
197
|
+
|
198
|
+
Reads in a file described in the defined grammar.
|
199
|
+
The tokens are stored internally.
|
200
|
+
|
201
|
+
|
202
|
+
=== next_token
|
203
|
+
|
204
|
+
The tokens stored internally are extracted one by one.
|
205
|
+
When there are no more tokens, nil is returned.
|
206
|
+
|
207
|
+
|
208
|
+
== Notice
|
209
|
+
|
210
|
+
This specification is provisional and may be changed without prior notice.
|
211
|
+
|