Class: Teeth::RuleStatement
- Inherits:
-
Object
- Object
- Teeth::RuleStatement
- Defined in:
- lib/teeth/rule_statement.rb
Instance Attribute Summary collapse
-
#begin ⇒ Object
readonly
Returns the value of attribute begin.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
-
#skip_line ⇒ Object
readonly
Returns the value of attribute skip_line.
-
#strip_ends ⇒ Object
readonly
Returns the value of attribute strip_ends.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #function_body ⇒ Object
-
#initialize(name, regex, options = {}) ⇒ RuleStatement
constructor
A new instance of RuleStatement.
- #scanner_code ⇒ Object
- #yytext_statement ⇒ Object
Constructor Details
#initialize(name, regex, options = {}) ⇒ RuleStatement
Returns a new instance of RuleStatement.
9 10 11 12 13 |
# File 'lib/teeth/rule_statement.rb', line 9 def initialize(name, regex, ={}) @name, @regex = name, regex @strip_ends, @skip_line, @begin = [:strip_ends], [:skip_line], [:begin] @ignore = [:ignore] end |
Instance Attribute Details
#begin ⇒ Object (readonly)
Returns the value of attribute begin.
7 8 9 |
# File 'lib/teeth/rule_statement.rb', line 7 def begin @begin end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/teeth/rule_statement.rb', line 7 def name @name end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex.
7 8 9 |
# File 'lib/teeth/rule_statement.rb', line 7 def regex @regex end |
#skip_line ⇒ Object (readonly)
Returns the value of attribute skip_line.
7 8 9 |
# File 'lib/teeth/rule_statement.rb', line 7 def skip_line @skip_line end |
#strip_ends ⇒ Object (readonly)
Returns the value of attribute strip_ends.
7 8 9 |
# File 'lib/teeth/rule_statement.rb', line 7 def strip_ends @strip_ends end |
Instance Method Details
#==(other) ⇒ Object
15 16 17 |
# File 'lib/teeth/rule_statement.rb', line 15 def ==(other) other.kind_of?(RuleStatement) && other.name == name && other.regex == regex end |
#function_body ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/teeth/rule_statement.rb', line 27 def function_body code = "" code += " BEGIN(#{@begin});\n" if @begin if skip_line code += " return EOF_KVPAIR;\n" else code += " KVPAIR #{name.to_s} = {\"#{name.to_s}\", #{yytext_statement}};\n" + " return #{name.to_s};\n" end code end |
#scanner_code ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/teeth/rule_statement.rb', line 19 def scanner_code if @ignore regex else "#{regex} {\n" + function_body + "}" end end |
#yytext_statement ⇒ Object
39 40 41 |
# File 'lib/teeth/rule_statement.rb', line 39 def yytext_statement strip_ends ? "strip_ends(yytext)" : "yytext" end |