Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Basic Ada Language Support #1021

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/rouge/demos/ada
@@ -0,0 +1,5 @@
with Text_IO; use Text_IO;
procedure Hello is
begin
Put_Line("Hello, World!");
end Hello;
57 changes: 57 additions & 0 deletions lib/rouge/lexers/ada.rb
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
module Lexers
class Ada < RegexLexer
tag 'ada'
filenames '*.adb', '*.ads', '*.gpr'
mimetypes 'text/x-adasrc'

title "Ada"
desc "The Ada programming language"

def self.keywords
@keywords ||= Set.new %w(
abort abs abstract accept access aliased all and array at begin
body case constant declare delay delta digits do else elsif end
entry exception exit for function generic goto if in interface
is limited loop mod new not null of or others out overriding
package pragma private procedure protected raise range record
rem renames requeue return reverse select separate some subtype
synchronized tagged task terminate then type until use when
while with xor
)
end

def self.keywords_type
@keywords_type ||= Set.new %w(
Boolean Character Float Integer Natural Positive String
Wide_Character Wide_Wide_Character
)
end

id = /[a-zA-Z_][a-zA-Z_0-9]*/

state :root do
rule /[\s\n]+/, Text::Whitespace
rule /--.*?$/, Comment::Single
rule /[~^*!%&\[\](){}<>\|+=:;',.\/?-]/, Operator
rule /"(\\\\|\\"|[^"])*"/, Str
rule /\d+[lu]*/i, Num::Integer

rule id do |m|
name = m[0]

if self.class.keywords.include? name
token Keyword
elsif self.class.keywords_type.include? name
token Keyword::Type
else
token Name
end
end
end
end
end
end
20 changes: 20 additions & 0 deletions spec/lexers/ada_spec.rb
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

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

describe 'guessing' do
include Support::Guessing

it 'guesses by filename' do
assert_guess :filename => 'foo.adb'
assert_guess :filename => 'foo.ads'
assert_guess :filename => 'foo.gpr'
end

it 'guesses by mimetype' do
assert_guess :mimetype => 'text/x-adasrc'
end
end
end