Skip to content

Commit

Permalink
Add JSL lexer (#871)
Browse files Browse the repository at this point in the history
This commit adds a lexer for the JMP Scripting Language.
  • Loading branch information
justinc11 authored and pyrmont committed Aug 31, 2019
1 parent 0cc4313 commit 8168673
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rouge/demos/jsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Create Distribution of Big Class
dt = open( "$sample_data\big class.jmp" );
dt << Distribution( Column( :age ), Histograms Only( 1 ) );
55 changes: 55 additions & 0 deletions lib/rouge/lexers/jsl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
module Lexers
class JSL < RegexLexer
title "JSL"
desc "The JMP Scripting Language (JSL) (jmp.com)"

tag 'jsl'
filenames '*.jsl'

state :root do
rule %r/\s+/m, Text::Whitespace

rule %r(//.*?$), Comment::Single
rule %r(/\*.*?\*/)m, Comment::Multiline

# messages
rule %r/(<<)(.*?)(\(|;)/ do |m|
groups Operator, Name::Function, Punctuation
end

# covers built-in and custom functions
rule %r/([a-z_][\w\s'%.\\]*)(\()/i do |m|
groups Keyword, Punctuation
end

rule %r/\b[+-]?(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+|\.)(?:e[+-]?[0-9]+)?i?\b/i, Num

rule %r/\d{2}(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d{2}(\d{2})?(:\d{2}:\d{2}(:\d{2}(\.\d*)?)?)?/i, Literal::Date

rule %r/::[a-z_][\w\s'%.\\]*/i, Name::Variable
rule %r/:\w+/, Name
rule %r/[a-z_][\w\s'%.\\]*/i, Name::Variable
rule %r/"(?:\\!"|[^"])*?"n/m, Name::Variable

rule %r/(")(\\\[)(.*?)(\]\\)(")/m do
groups Str::Double, Str::Escape, Str::Double, Str::Escape, Str::Double # escaped string
end
rule %r/"/, Str::Double, :dq

rule %r/[-+*\/!%&<>\|=:]/, Operator
rule %r/[\[\](){},;]/, Punctuation
end

state :dq do
rule %r/\\![btrnNf0\\"]/, Str::Escape
rule %r/\\/, Str::Double
rule %r/"/, Str::Double, :pop!
rule %r/[^\\"]*/m, Str::Double
end
end
end
end
15 changes: 15 additions & 0 deletions spec/lexers/jsl_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

describe Rouge::Lexers::JSL do
let(:subject) { Rouge::Lexers::JSL.new }

describe 'guessing' do
include Support::Guessing

it 'guesses by filename' do
assert_guess :filename => 'foo.jsl'
end

end
end
24 changes: 24 additions & 0 deletions spec/visual/samples/jsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Single Line Comment
dt = open( "$sample_data\big class.jmp" );
dt << Distribution( Column( :age ), Histograms Only( 1 ) );
/*
Multi-line comment
*/

escapeSequence = "This is an \!b escaped sequence";
escapeQuote = "This is a \!" quotation mark";
escapeStr = "\[This is """"""" an escaped string]\"

list = List( 1, 3, 5 );
alsoAList = {7,9,11};
a name with spaces = 5;
"a-name!with\!"special\characters"n = 5;

scientificNotation = 5e9;
decimal = 1.234;
date = 01jan00;
dateTime = 12dec1999:12:30:00.45;

New Window( "Rouge Test",
Text Box( "Syntax highlighting is great!" )
);

0 comments on commit 8168673

Please sign in to comment.