Class: LexerKit::Builder
- Inherits:
-
Object
- Object
- LexerKit::Builder
- Includes:
- DSL
- Defined in:
- lib/lexer_kit/builder.rb,
lib/lexer_kit/builder/compiler.rb,
lib/lexer_kit/builder/mode_def.rb,
lib/lexer_kit/builder/token_def.rb,
lib/lexer_kit/builder/validator.rb,
lib/lexer_kit/builder/conflict_detector.rb
Overview
Builder provides the DSL for defining lexers.
Defined Under Namespace
Modules: DSL Classes: Compiler, ConflictDetector, ModeDef, TokenDef, Validator
Instance Attribute Summary collapse
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
-
#mode_defs ⇒ Object
readonly
Returns the value of attribute mode_defs.
-
#token_defs ⇒ Object
readonly
Returns the value of attribute token_defs.
Instance Method Summary collapse
-
#check_conflicts ⇒ Array<ConflictDetector::Conflict>
Check for pattern conflicts.
-
#check_conflicts!(io: $stderr) ⇒ Array<ConflictDetector::Conflict>
Check for pattern conflicts and print warnings.
-
#compile ⇒ IR::CompiledProgram
Compile to IR.
-
#error_token ⇒ Symbol
Error token is always :INVALID.
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
Methods included from DSL
#define_keywords, #delimited, #keyword, #mode, #scan_until, #token, #version
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
165 166 167 168 169 170 171 172 |
# File 'lib/lexer_kit/builder.rb', line 165 def initialize @token_defs = [] @mode_defs = { default: ModeDef.new(:default, location: nil) } @current_mode = :default @keywords = {} @version = 1 @internal_mode_counter = 0 end |
Instance Attribute Details
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
157 158 159 |
# File 'lib/lexer_kit/builder.rb', line 157 def keywords @keywords end |
#mode_defs ⇒ Object (readonly)
Returns the value of attribute mode_defs.
157 158 159 |
# File 'lib/lexer_kit/builder.rb', line 157 def mode_defs @mode_defs end |
#token_defs ⇒ Object (readonly)
Returns the value of attribute token_defs.
157 158 159 |
# File 'lib/lexer_kit/builder.rb', line 157 def token_defs @token_defs end |
Instance Method Details
#check_conflicts ⇒ Array<ConflictDetector::Conflict>
Check for pattern conflicts
185 186 187 |
# File 'lib/lexer_kit/builder.rb', line 185 def check_conflicts ConflictDetector.new(self).detect end |
#check_conflicts!(io: $stderr) ⇒ Array<ConflictDetector::Conflict>
Check for pattern conflicts and print warnings
192 193 194 195 196 197 198 |
# File 'lib/lexer_kit/builder.rb', line 192 def check_conflicts!(io: $stderr) conflicts = check_conflicts conflicts.each do |conflict| io.puts "warning: #{conflict.token1} vs #{conflict.token2}: #{conflict.description}" end conflicts end |
#compile ⇒ IR::CompiledProgram
Compile to IR
176 177 178 179 180 181 |
# File 'lib/lexer_kit/builder.rb', line 176 def compile Validator.new(self).validate! program = Compiler.new(self).compile program.load_native! if LexerKit.native? program end |
#error_token ⇒ Symbol
Error token is always :INVALID
161 162 163 |
# File 'lib/lexer_kit/builder.rb', line 161 def error_token :INVALID end |