Skip to content

Commit

Permalink
Improve comment support in Xojo lexer (#1229)
Browse files Browse the repository at this point in the history
This commit:

- adds single quote and 'rem' style comments;
- fixes parsing with multiple Note sections;
- adds `.xojo_image`, `.rbbas`, `.rbfrm`, `.rbmnu`, `.rbres`, `.rbtbar` 
  file extensions (these are old REALbasic file names); and
- updates demo and test files with added comment styles.
  • Loading branch information
jimmckay authored and pyrmont committed Jul 1, 2019
1 parent 6b00713 commit 6360e1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/rouge/demos/xojo
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Dim f As FolderItem
f = GetOpenFolderItem(FileTypes1.jpeg) // defined in the File Type Set editor
rem - we should check for nil!
If not f.Exists Then
Beep
Beep 'Just for fun
MsgBox("The file " + f.NativePath + "doesn't ""exist.""")
Else // document exists
ImageWell1.image=Picture.Open(f)
Expand Down
8 changes: 4 additions & 4 deletions lib/rouge/lexers/xojo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Xojo < RegexLexer
desc "Xojo"
tag 'xojo'
aliases 'realbasic'
filenames '*.xojo_code', '*.xojo_window', '*.xojo_toolbar', '*.xojo_menu'
filenames '*.xojo_code', '*.xojo_window', '*.xojo_toolbar', '*.xojo_menu', '*.xojo_image', '*.rbbas', '*.rbfrm', '*.rbmnu', '*.rbres', '*.rbtbar'

keywords = %w(
addhandler aggregates array asc assigns attributes begin break
Expand All @@ -30,15 +30,15 @@ class Xojo < RegexLexer
)

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

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

rule %r/rem\b.*?$/i, Comment::Single
rule %r(//.*$), Comment::Single
rule %r/\#tag Note.*\#tag EndNote/m, Comment::Preproc
rule %r([//'].*$), Comment::Single
rule %r/\#tag Note.*?\#tag EndNote/mi, Comment::Preproc
rule %r/\s*[#].*$/x, Comment::Preproc

rule %r/".*?"/, Literal::String::Double
Expand Down
9 changes: 9 additions & 0 deletions spec/visual/samples/xojo
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ End
dim y as double=.1 //also allowed
rem This is an old style comment (throw back to Basic)
dim escaped_quotes as string="this is an ""escaped"" string" //would compile as 'this is an "escaped" string'
'this is a single quote comment
msgbox "ok" 'this should be a comment too!
End Sub
#tag EndEvent

Expand Down Expand Up @@ -227,6 +229,13 @@ End
End Sub
#tag EndEvent
#tag EndEvents

#tag Note, Name = More Notes
This another note to make sure we're not grabbing too much/multiple
notes.

#tag EndNote

#tag ViewBehavior
#tag ViewProperty
Name="BackButtonTitle"
Expand Down

0 comments on commit 6360e1f

Please sign in to comment.