Class: OpenvoxLint::Lexer
- Inherits:
-
Object
- Object
- OpenvoxLint::Lexer
- Defined in:
- lib/openvox-lint/lexer.rb
Overview
Tokenises a Puppet / OpenVox manifest string into an Array of Token objects. The lexer recognises all Puppet 8 / OpenVox 8.x language constructs including heredocs, EPP tags, Deferred/Sensitive types, type aliases, and the full operator set.
Constant Summary collapse
- KEYWORDS =
{ 'and' => :AND, 'application' => :APPLICATION, 'attr' => :ATTR, 'case' => :CASE, 'class' => :CLASS, 'consumes' => :CONSUMES, 'default' => :DEFAULT, 'define' => :DEFINE, 'else' => :ELSE, 'elsif' => :ELSIF, 'false' => :FALSE, 'function' => :FUNCTION, 'if' => :IF, 'import' => :IMPORT, 'in' => :IN, 'inherits' => :INHERITS, 'node' => :NODE, 'not' => :NOT, 'or' => :OR, 'private' => :PRIVATE, 'produces' => :PRODUCES, 'site' => :SITE, 'true' => :TRUE, 'type' => :TYPE, 'undef' => :UNDEF, 'unless' => :UNLESS, }.freeze
- OPERATORS =
[ ['<<|', :LLCOLLECT], ['|>>', :RRCOLLECT], ['<=', :LESSEQUAL], ['>=', :GREATEREQUAL], ['==', :ISEQUAL], ['!=', :NOTEQUAL], ['=~', :MATCH], ['!~', :NOMATCH], ['=>', :FARROW], ['+=', :APPENDS], ['+>', :PARROW], ['->', :IN_EDGE], ['<-', :OUT_EDGE], ['~>', :IN_EDGE_SUB], ['<~', :OUT_EDGE_SUB], ['<<', :LSHIFT], ['>>', :RSHIFT], ['<|', :LCOLLECT], ['|>', :RCOLLECT], ].freeze
- SINGLE_CHAR =
{ '{' => :LBRACE, '}' => :RBRACE, '(' => :LPAREN, ')' => :RPAREN, '[' => :LBRACK, ']' => :RBRACK, ';' => :SEMIC, ',' => :COMMA, '.' => :DOT, '@' => :AT, '|' => :PIPE, '+' => :PLUS, '-' => :MINUS, '*' => :TIMES, '%' => :MODULO, '!' => :NOT, '?' => :QMARK, '\\' => :BACKSLASH, ':' => :COLON, '=' => :EQUALS, '>' => :GREATERTHAN, '<' => :LESSTHAN, }.freeze
- REGEX_PREV =
%i[ NODE LBRACE LBRACK LPAREN COMMA EQUALS ISEQUAL NOTEQUAL MATCH NOMATCH AND OR NOT IF ELSIF CASE RETURN IN ].freeze
Instance Attribute Summary collapse
-
#manifest_lines ⇒ Object
readonly
Returns the value of attribute manifest_lines.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#initialize(code) ⇒ Lexer
constructor
A new instance of Lexer.
Constructor Details
#initialize(code) ⇒ Lexer
Returns a new instance of Lexer.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/openvox-lint/lexer.rb', line 50 def initialize(code) @code = code @manifest_lines = code.lines.map(&:chomp) @tokens = [] @line = 1 @column = 1 @pos = 0 tokenise link_tokens end |
Instance Attribute Details
#manifest_lines ⇒ Object (readonly)
Returns the value of attribute manifest_lines.
48 49 50 |
# File 'lib/openvox-lint/lexer.rb', line 48 def manifest_lines @manifest_lines end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
48 49 50 |
# File 'lib/openvox-lint/lexer.rb', line 48 def tokens @tokens end |