From 8b1052ac6c606f934eb28dd1d24514bf43111236 Mon Sep 17 00:00:00 2001 From: Julian Rubisch Date: Sat, 23 Mar 2019 13:55:38 +0100 Subject: [PATCH] Introduce mc_identifier token type #13 --- lib/maxy/gen/tokenizer.rb | 1 + spec/maxy/tokenizer_spec.rb | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/maxy/gen/tokenizer.rb b/lib/maxy/gen/tokenizer.rb index 0f1b828..955de37 100644 --- a/lib/maxy/gen/tokenizer.rb +++ b/lib/maxy/gen/tokenizer.rb @@ -3,6 +3,7 @@ module Gen class Tokenizer TOKEN_TYPES = [ [:arguments, /({[^{}]*})/], + [:mc_identifier, /(mc\.[^{}()]+~)(?=[-+=*<{}])?/], [:escaped_identifier, /(\\[\S][^-+={}<()\\]*)(?=[-+=*<{}])?/], [:identifier, /([^-+={}<()\\]+)(?=[-+=*<{}])?/], [:oparen, /(\()/], diff --git a/spec/maxy/tokenizer_spec.rb b/spec/maxy/tokenizer_spec.rb index 1634bc9..e41cf38 100644 --- a/spec/maxy/tokenizer_spec.rb +++ b/spec/maxy/tokenizer_spec.rb @@ -55,4 +55,10 @@ expect(tokens.map(&:type)).to eq(%i[identifier arguments less_than identifier arguments]) expect(tokens.map(&:value)).to eq(%w[int {3} < pack {1\ 2\ 3}]) end -end \ No newline at end of file + + it 'should tokenize an mc chain' do + tokens = Tokenizer.new('mc.cycle~{400}-mc.+~{0.1}').tokenize + expect(tokens.map(&:type)).to eq(%i[mc_identifier arguments dash mc_identifier arguments]) + expect(tokens.map(&:value)).to eq(%w[mc.cycle~ {400} - mc.+~ {0.1}]) + end +end