Class: Ecu::LabelList::DcmLexer
- Inherits:
-
Object
- Object
- Ecu::LabelList::DcmLexer
- Defined in:
- lib/ecu/interfaces/dcm/dcm_lexer.rb
Constant Summary collapse
- KEYWORDS =
[ "FUNKTIONEN", "FESTWERT", "FESTWERTEBLOCK", "KENNLINIE", "GRUPPENKENNLINIE", "FESTKENNLINIE", "KENNFELD", "GRUPPENKENNFELD", "FESTKENNFELD", "STUETZSTELLENVERTEILUNG", "FKT", "ST/X", "ST/Y", "WERT", "ST_TX/X", "ST_TX/Y", "TEXT", "FUNKTION", "EINHEIT_X", "EINHEIT_Y", "EINHEIT_W", "LANGNAME", "DISPLAYNAME", "END", ].freeze
- HEADER =
"KONSERVIERUNG_FORMAT 2.0"- WHITESPACE =
%r{ [ \t]+ }x
- NEWLINE =
%r{ \r\n|\n }x
- COMMENT =
%r{ ^\*.*$ }x
- DIMENSIONS_SEP =
%r{ @ }x
- QUOTED_TEXT =
%r{ "[^"]*" }x
- IDENTIFIER =
%r{ [A-Za-z][A-Za-z0-9_\.]* }x
- UNSIGNED_INT =
%r{ [0]|[1-9][0-9]* }x
- INT =
%r{ [-]?#{UNSIGNED_INT} }x
- FLOAT_EXP =
%r{ [eE][+-]?[0-9]+ }x
- FLOAT =
%r{ [-+]? (?: #{UNSIGNED_INT}?[.][0-9]+#{FLOAT_EXP} | # 1.23e10 or .45e3 #{UNSIGNED_INT} #{FLOAT_EXP} | # 3e4 #{UNSIGNED_INT}?[.][0-9]+ | # 7.3 or .50 #{UNSIGNED_INT} [.][0-9]* # 3.02 or 9. ) }x
- KW_RE =
/#{Regexp.union(KEYWORDS.sort)}\b/- KW_TABLE =
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Instance Method Summary collapse
-
#initialize(doc) ⇒ DcmLexer
constructor
A new instance of DcmLexer.
- #lineno ⇒ Object
- #next_token ⇒ Object
- #token_value ⇒ Object
Constructor Details
#initialize(doc) ⇒ DcmLexer
Returns a new instance of DcmLexer.
7 8 9 10 |
# File 'lib/ecu/interfaces/dcm/dcm_lexer.rb', line 7 def initialize(doc) @doc = doc @scan = StringScanner.new(doc) end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
6 7 8 |
# File 'lib/ecu/interfaces/dcm/dcm_lexer.rb', line 6 def doc @doc end |
Instance Method Details
#lineno ⇒ Object
72 73 74 75 |
# File 'lib/ecu/interfaces/dcm/dcm_lexer.rb', line 72 def lineno @doc.byteslice(0, @scan.pos).count("\n") + (@scan.beginning_of_line? ? 0 : 1) end |
#next_token ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ecu/interfaces/dcm/dcm_lexer.rb', line 46 def next_token @scan.skip(WHITESPACE) return if @scan.eos? case when @scan.skip(NEWLINE) then :NEWLINE when s = @scan.scan(KW_RE) then KW_TABLE[s] when @scan.skip(QUOTED_TEXT) then :QUOTED_TEXT when @scan.skip(COMMENT) then :COMMENT when @scan.skip(DIMENSIONS_SEP) then :DIMENSIONS_SEP when @scan.skip(HEADER) then :HEADER when @scan.skip(IDENTIFIER) then :IDENTIFIER when @scan.skip(FLOAT) then :FLOAT when @scan.skip(INT) then :INT else @scan.getch :UNKNOWN_CHAR end end |
#token_value ⇒ Object
68 69 70 |
# File 'lib/ecu/interfaces/dcm/dcm_lexer.rb', line 68 def token_value @doc.byteslice(@scan.pos - @scan.matched_size, @scan.matched_size) end |