Skip to content

Commit

Permalink
Praat: support matrix and string vector type (#1820)
Browse files Browse the repository at this point in the history
Signed-off-by: syuparn <s.hello.spagetti@gmail.com>
  • Loading branch information
Syuparn committed Aug 8, 2022
1 parent 61a9cdf commit 8d5a130
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
22 changes: 20 additions & 2 deletions lib/rouge/lexers/praat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ def self.detect?(text)
linear randomGauss randomInteger randomUniform zero
)

functions_matrix = %w(
linear mul mul_fast mul_metal mul_nt mul_tn mul_tt outer peaks
randomGamma randomGauss randomInteger randomUniform softmaxPerRow
solve transpose zero
)

functions_string_vector = %w(
empty fileNames folderNames readLinesFromFile splitByWhitespace
)

objects = %w(
Activation AffineTransform AmplitudeTier Art Artword Autosegment
BarkFilter BarkSpectrogram CCA Categories Cepstrogram Cepstrum
Expand Down Expand Up @@ -142,6 +152,7 @@ def self.detect?(text)

mixin :variable_name
mixin :number
mixin :vector_literal

rule %r/"/, Literal::String, :string

Expand Down Expand Up @@ -196,6 +207,8 @@ def self.detect?(text)
state :function_call do
rule %r/\b(#{functions_string.join('|')})\$(?=\s*[:(])/, Name::Function, :function
rule %r/\b(#{functions_array.join('|')})#(?=\s*[:(])/, Name::Function, :function
rule %r/\b(#{functions_matrix.join('|')})##(?=\s*[:(])/, Name::Function, :function
rule %r/\b(#{functions_string_vector.join('|')})\$#(?=\s*[:(])/, Name::Function, :function
rule %r/\b(#{functions_numeric.join('|')})(?=\s*[:(])/, Name::Function, :function
end

Expand All @@ -214,7 +227,7 @@ def self.detect?(text)
groups Text, Punctuation
end

rule %r/\s*[\])\n]/, Text, :pop!
rule %r/\s*[\]\})\n]/, Text, :pop!

rule %r/\s+/, Text
rule %r/"/, Literal::String, :string
Expand All @@ -224,6 +237,7 @@ def self.detect?(text)
mixin :variable_name
mixin :operator
mixin :number
mixin :vector_literal

rule %r/[()]/, Text
rule %r/,/, Punctuation
Expand Down Expand Up @@ -257,11 +271,15 @@ def self.detect?(text)
push :object_reference
end

rule %r/\.?[a-z][a-zA-Z0-9_.]*(\$|#)?/, Text
rule %r/\.?[a-z][a-zA-Z0-9_.]*(\$#|##|\$|#)?/, Text
rule %r/[\[\]]/, Text, :comma_list
mixin :string_interpolated
end

state :vector_literal do
rule %r/(\{)/, Text, :comma_list
end

state :object_reference do
mixin :string_interpolated
rule %r/([a-z][a-zA-Z0-9_]*|\d+)/, Name::Builtin
Expand Down
12 changes: 11 additions & 1 deletion spec/visual/samples/praat
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,24 @@ a$ = e$
a$ = pi$

# Arrays are not comments
a# = zero# (5, 6)
a# = zero#(5)
a [3], 5 = 7
printline 'a[3,5]', 'a[3]'
a [1] = 2
b [a [1]] = 3
assert b [a [1]] = 3
printline 'b[2]'

# Matrices
m## = zero##(5, 6)
m## = {{1, 2}, {3, 4}}
m##[1, 2] = 3

# String vectors
strVec$# = empty$#(10)
strVec$# = {"foo", "bar"}
strVec$#[1] = "baz"

# if-block with built-in variables
if windows
# We are on Windows
Expand Down

0 comments on commit 8d5a130

Please sign in to comment.