class
Ameba::AST::MacroCodeScanner
- Ameba::AST::MacroCodeScanner
- Reference
- Object
Overview
Scans the raw text of a macro body (its MacroLiteral nodes),
telling the code apart from the comments and the literals.
Macro bodies are kept as a raw MacroLiteral text, split at macro
expressions and control nodes, so i.e. a comment or a string literal
can span multiple nodes - hence the scanner keeps its state between
the subsequent #scan calls, which must follow the order of the nodes.
scanner = MacroCodeScanner.new
scanner.scan(%(foo "bar" # baz\n)) # => "foo \n"
Defined in:
ameba/ast/macro_code_scanner.crInstance Method Summary
-
#after_value! : Nil
Marks the end of a value placed in between the scanned macro literals, i.e.
-
#clone : self
Returns a deep copy of the scanner, i.e.
-
#scan(literal : String) : String
Returns the macro literal with all of the comments, string, char, command, symbol, percent, regex and heredoc literals blanked out, while keeping the code within their interpolations.
Instance Method Detail
Marks the end of a value placed in between the scanned macro literals,
i.e. the output of a {{ ... }} macro expression, so that the following
/ or % are treated as operators, not literal delimiters.
Returns a deep copy of the scanner, i.e. to scan alternative macro branches starting from the same lexical state.
Returns the macro literal with all of the comments, string, char, command, symbol, percent, regex and heredoc literals blanked out, while keeping the code within their interpolations.
The returned string has the same number of characters and lines as literal, as the blanked out characters (but newlines) are replaced with spaces.