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 Xojo lexer. #1131

Merged
merged 6 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/rouge/demos/xojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Dim f As FolderItem
f = GetOpenFolderItem(FileTypes1.jpeg) // defined in the File Type Set editor
If not f.Exists Then
Beep
MsgBox("The file " + f.NativePath + "doesn't ""exist.""")
Else // document exists
ImageWell1.image=Picture.Open(f)
End If
if f isa folderitem then
msgbox(f.name)
end if
Exception err As NilObjectException
MsgBox("Invalid pathname!")
66 changes: 66 additions & 0 deletions lib/rouge/lexers/xojo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
module Lexers
class Xojo < RegexLexer
title "Xojo"
desc "Xojo"
tag 'xojo'
aliases 'realbasic'
filenames '*.xojo_code', '*.xojo_window', '*.xojo_toolbar', '*.xojo_menu'

keywords = %w(
jimmckay marked this conversation as resolved.
Show resolved Hide resolved
addhandler aggregates array asc assigns attributes begin break
byref byval call case catch class const continue char ctype declare
delegate dim do downto each else elseif end enum event exception
exit extends false finally for function global goto if
implements inherits interface lib loop mod module
new next nil object of optional paramarray
private property protected public raise raiseevent rect redim
removehandler return select shared soft static step sub super
then to true try until using uend uhile
)

keywords_type = %w(
boolean cfstringref cgfloat cstring curency date double int8 int16
int32 int64 integer ostype pstring ptr short single
single string structure variant uinteger uint8 uint16 uint32 uint64
ushort windowptr wstring
)

operator_words = %w(
addressof and as in is isa mod not or xor
)

state :whitespace do
jimmckay marked this conversation as resolved.
Show resolved Hide resolved
rule /\s+/, Text
rule /rem\b.*?$/i, Comment::Single
jimmckay marked this conversation as resolved.
Show resolved Hide resolved
rule /\/\/.*$/, Comment::Single
rule /\#tag Note.*\#tag EndNote/m, Comment::Doc
rule /".*"/, Literal::String
jimmckay marked this conversation as resolved.
Show resolved Hide resolved
end


state :root do
mixin :whitespace
rule /\s*[#].*$/x, Comment::Preproc
rule /[(){}!#,:]/, Punctuation
rule /\b(?:#{keywords.join('|')})\b/i, Keyword
rule /\b(?:#{keywords_type.join('|')})\b/i, Keyword::Declaration
rule /\b(?:#{operator_words.join('|')})\b/i, Operator

rule(
%r(<=|>=|<>|[=><\+\-\*\/\\]),
Operator
)

rule /[+-]?(\d+\.\d*|\d*\.\d+)(f[+-]?\d+)?/i, Literal::Number::Float
jimmckay marked this conversation as resolved.
Show resolved Hide resolved
rule /[+-]?\d+/, Literal::Number::Integer
rule /&[CH][0-9a-f]+/i, Literal::Number::Integer
jimmckay marked this conversation as resolved.
Show resolved Hide resolved
rule /&O[0-7]+/i, Literal::Number::Oct
rule /\b[\w\.]+\b/i, Text
end
end
end
end
18 changes: 18 additions & 0 deletions spec/lexers/xojo_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

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

describe 'guessing' do
include Support::Guessing

it 'guesses by filename' do
assert_guess :filename => 'foo.xojo_code'
assert_guess :filename => 'foo.xojo_window'
assert_guess :filename => 'foo.xojo_toolbar'
assert_guess :filename => 'foo.xojo_menu'
end

end
end
Loading