Class: Textlint::Parser
- Inherits:
-
Object
- Object
- Textlint::Parser
- Defined in:
- lib/textlint/parser.rb
Defined Under Namespace
Classes: RubyToTextlintAST
Class Method Summary collapse
-
.build_document(src) ⇒ Textlint::Nodes::TxtParentNode
Parse ruby code to TxtParentNode.
-
.parse(src) ⇒ Textlint::Nodes::TxtParentNode
Parse ruby code to AST for textlint.
Instance Method Summary collapse
-
#call ⇒ Textlint::Nodes::TxtParentNode
Parse ruby code to AST for textlint.
-
#initialize(src) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(src) ⇒ Parser
Returns a new instance of Parser.
186 187 188 |
# File 'lib/textlint/parser.rb', line 186 def initialize(src) @src = src end |
Class Method Details
.build_document(src) ⇒ Textlint::Nodes::TxtParentNode
Parse ruby code to TxtParentNode
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/textlint/parser.rb', line 167 def self.build_document(src) Textlint::Nodes::TxtParentNode.new( type: Textlint::Nodes::DOCUMENT, raw: src, range: 0...src.size, loc: Textlint::Nodes::TxtNodeLineLocation.new( start: Textlint::Nodes::TxtNodePosition.new( line: 1, column: 0 ), end: Textlint::Nodes::TxtNodePosition.new( line: src.split(Textlint::BREAK_RE).size + 1, column: src.match(LAST_LINE_RE).to_s.size # extract last line ) ) ) end |
.parse(src) ⇒ Textlint::Nodes::TxtParentNode
Parse ruby code to AST for textlint
158 159 160 |
# File 'lib/textlint/parser.rb', line 158 def self.parse(src) new(src).call end |
Instance Method Details
#call ⇒ Textlint::Nodes::TxtParentNode
Parse ruby code to AST for textlint
193 194 195 196 197 198 |
# File 'lib/textlint/parser.rb', line 193 def call check_syntax! document = self.class.build_document(@src) RubyToTextlintAST.new(@src).parse(document) end |