Skip to content

Commit

Permalink
Add Slice lexer (#867)
Browse files Browse the repository at this point in the history
This commit adds a lexer for the Slice language.
  • Loading branch information
jolkdarr authored and pyrmont committed Nov 20, 2019
1 parent b8b955c commit 184848a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/rouge/demos/slice
@@ -0,0 +1,10 @@
// Printer.ice
module Demo
{
interface Printer
{
// A client can invoke this operation on a server.
// In this example we print the string s
void printString(string s);
}
}
32 changes: 32 additions & 0 deletions lib/rouge/lexers/slice.rb
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
module Lexers
load_lexer 'c.rb'

class Slice < C
tag 'slice'
filenames '*.ice'
mimetypes 'text/slice'

title "Slice"
desc "Specification Language for Ice (doc.zeroc.com)"

def self.keywords
@keywords ||= Set.new %w(
extends implements enum interface struct class module dictionary
const optional out throws exception local idempotent sequence

Object LocalObject Value
)
end

def self.keywords_type
@keywords_type ||= Set.new %w(
bool string byte long float double int void short
)
end
end
end
end
18 changes: 18 additions & 0 deletions spec/lexers/slice_spec.rb
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

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

describe 'guessing' do
include Support::Guessing

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

it 'guesses by mimetype' do
assert_guess :mimetype => 'text/slice'
end
end
end
27 changes: 27 additions & 0 deletions spec/visual/samples/slice
@@ -0,0 +1,27 @@
// File system module.
module Filesystem {

// Node interface:
interface Node {
idempotent string name();
}

exception GenericError {
string reason;
}

sequence<string> Lines;

["java:implements:java.lang.AutoCloseable"]
interface File extends Node {
idempotent Lines read();
idempotent void write(Lines text) throws GenericError;
}

sequence<Node*> NodeSeq;

// Directory interface:
interface Directory extends Node {
idempotent NodeSeq list();
}
}

0 comments on commit 184848a

Please sign in to comment.