Skip to content
Snippets Groups Projects
Commit bbc40dd7 authored by http://jneen.net/'s avatar http://jneen.net/
Browse files

new lexer: tulip

parent 57cfd278
No related branches found
No related tags found
No related merge requests found
# ref.tlp
@module ref
ref value = Instance (spawn [! loop value ])
loop value = receive [
.set new-value => loop new-value
p, .get => (send p value; loop value)
]
@module Instance pid [
set val = .set val > send pid
get! = .get > send-wait pid
]
module Rouge
module Lexers
class Tulip < RegexLexer
tag 'tulip'
aliases 'tlp'
filenames '*.tlp'
desc 'The tulip programming language http://github.com/jneen/tulip'
id = /\w[\w-]*/
def self.analyze_text(text)
return 1 if text.shebang?('tulip')
end
state :root do
rule /\s+/, Text
rule /#.*?\n/, Comment
rule /%#{id}/, Keyword::Type
rule /@#{id}/, Keyword
rule /[.][.]?#{id}/, Name::Label
rule /-#{id}[?]?/, Str::Symbol
rule /\d+/, Num
rule %r(/#{id}?), Name::Decorator
rule %r((#{id}/)(#{id})) do
groups Name::Namespace, Name::Variable
end
rule /"{/, Str, :string_interp
rule /'?{/, Str, :string
rule /['"][^\s)\]]+/, Str
rule /[$]/, Name::Variable
rule /[-+:;~!()\[\]=?>|_%,]/, Punctuation
rule /[.][.][.]/, Punctuation
rule id, Name
end
state :string_base do
rule /{/ do
token Str; push
end
rule /}/, Str, :pop!
rule /[$]/, Str
rule /[^${}\\]+/, Str
end
state :string do
mixin :string_base
rule /\\/, Str
end
state :interp do
rule(/[(]/) { token Punctuation; push }
rule /[)]/, Punctuation, :pop!
mixin :root
end
state :interp_root do
rule /[(]/, Str::Interpol, :interp
rule /[)]/, Str::Interpol, :pop!
mixin :root
end
state :string_interp do
rule /\\./, Str::Escape
rule /[$][(]/, Str::Interpol, :interp_root
rule /[$]#{id}?/, Name::Variable
mixin :string_base
end
end
end
end
describe Rouge::Lexers::Tulip do
let(:subject) { Rouge::Lexers::Tulip.new }
describe 'guessing' do
include Support::Guessing
it 'guesses by filename' do
assert_guess :filename => 'foo.tlp'
end
it 'guesses by source' do
assert_guess :source => '#!/usr/bin/env tulip'
end
end
end
.foo bar baz -zot
/list[1; 2; 3]
/[1; 2; 3]
@module Foo bar [
baz = [ zot : %zot => glorb ]
]
str = {some string}
nested = {nes{t{e}d{}}}
regex = /r'foo
regex = /r{foo}
interp = "{foo$(bar)}
interp_nested = "{foo$(bar (baz (zot ())))} # comment
String/split '/ 'foo/bar
escapes = "{\$(string)\{} # comment
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment