summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-09-16 09:51:52 +0200
committerGeorg Brandl <georg@python.org>2014-09-16 09:51:52 +0200
commit508e306f64288290c46602f904f8d25d867c0b50 (patch)
tree78579062c1169528dba5049efc7e1793653228e2
parent318728914ec120c42bd892905f98414d01589d3b (diff)
parent36b2888b4a17b28e6bcd7bc76ee57ed706de0f01 (diff)
downloadpygments-508e306f64288290c46602f904f8d25d867c0b50.tar.gz
merge with R4PaSs/pygments-main
-rw-r--r--CHANGES4
-rw-r--r--doc/docs/lexerdevelopment.rst2
-rw-r--r--pygments/lexers/_mapping.py2
-rw-r--r--pygments/lexers/agile.py6
-rw-r--r--pygments/lexers/compiled.py24
-rw-r--r--pygments/lexers/functional.py122
-rw-r--r--pygments/lexers/other.py2
-rw-r--r--tests/examplefiles/99_bottles_of_beer.chpl43
-rw-r--r--tests/examplefiles/example_elixir.ex48
-rw-r--r--tests/examplefiles/rust_example.rs2
10 files changed, 173 insertions, 82 deletions
diff --git a/CHANGES b/CHANGES
index 8459e05a..807319ef 100644
--- a/CHANGES
+++ b/CHANGES
@@ -105,7 +105,9 @@ Version 2.0
- C family lexers: fix parsing of indented preprocessor directives (#944).
-- Rust lexer: update to 0.9 language version (PR#270).
+- Rust lexer: update to 0.9 language version (PR#270, PR#388).
+
+- Elixir lexer: update to 0.15 language version (PR#392).
Version 1.6
diff --git a/doc/docs/lexerdevelopment.rst b/doc/docs/lexerdevelopment.rst
index eab1306a..23f7cdc6 100644
--- a/doc/docs/lexerdevelopment.rst
+++ b/doc/docs/lexerdevelopment.rst
@@ -190,7 +190,7 @@ nevertheless need a group, use a non-capturing group defined using this syntax:
If you find yourself needing a capturing group inside the regex which
shouldn't be part of the output but is used in the regular expressions for
backreferencing (eg: ``r'(<(foo|bar)>)(.*?)(</\2>)'``), you can pass `None`
-to the bygroups function and it will skip that group will be skipped in the
+to the bygroups function and that group will be skipped in the
output.
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index f8454357..b028aee6 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -20,7 +20,7 @@ LEXERS = {
'APLLexer': ('pygments.lexers.other', 'APL', ('apl',), ('*.apl',), ()),
'ActionScript3Lexer': ('pygments.lexers.web', 'ActionScript 3', ('as3', 'actionscript3'), ('*.as',), ('application/x-actionscript3', 'text/x-actionscript3', 'text/actionscript3')),
'ActionScriptLexer': ('pygments.lexers.web', 'ActionScript', ('as', 'actionscript'), ('*.as',), ('application/x-actionscript', 'text/x-actionscript', 'text/actionscript')),
- 'AdaLexer': ('pygments.lexers.compiled', 'Ada', ('ada', 'ada95ada2005'), ('*.adb', '*.ads', '*.ada'), ('text/x-ada',)),
+ 'AdaLexer': ('pygments.lexers.compiled', 'Ada', ('ada', 'ada95', 'ada2005'), ('*.adb', '*.ads', '*.ada'), ('text/x-ada',)),
'AgdaLexer': ('pygments.lexers.functional', 'Agda', ('agda',), ('*.agda',), ('text/x-agda',)),
'AlloyLexer': ('pygments.lexers.other', 'Alloy', ('alloy',), ('*.als',), ('text/x-alloy',)),
'AmbientTalkLexer': ('pygments.lexers.other', 'AmbientTalk', ('at', 'ambienttalk', 'ambienttalk/2'), ('*.at',), ('text/x-ambienttalk',)),
diff --git a/pygments/lexers/agile.py b/pygments/lexers/agile.py
index 576f44ed..1ae369b9 100644
--- a/pygments/lexers/agile.py
+++ b/pygments/lexers/agile.py
@@ -2010,8 +2010,8 @@ class Perl6Lexer(ExtendedRegexLexer):
PERL6_BUILTINS = (
'ACCEPTS', 'HOW', 'REJECTS', 'VAR', 'WHAT', 'WHENCE', 'WHERE', 'WHICH',
'WHO', 'abs', 'acos', 'acosec', 'acosech', 'acosh', 'acotan', 'acotanh',
- 'all', 'any', 'approx', 'arity', 'asec', 'asech', 'asin', 'asinh'
- 'assuming', 'atan', 'atan2', 'atanh', 'attr', 'bless', 'body', 'by'
+ 'all', 'any', 'approx', 'arity', 'asec', 'asech', 'asin', 'asinh',
+ 'assuming', 'atan', 'atan2', 'atanh', 'attr', 'bless', 'body', 'by',
'bytes', 'caller', 'callsame', 'callwith', 'can', 'capitalize', 'cat',
'ceiling', 'chars', 'chmod', 'chomp', 'chop', 'chr', 'chroot',
'circumfix', 'cis', 'classify', 'clone', 'close', 'cmp_ok', 'codes',
@@ -2396,7 +2396,7 @@ class HyLexer(RegexLexer):
]
declarations = [
- 'def' 'defn', 'defun', 'defmacro', 'defclass', 'lambda', 'fn', 'setv'
+ 'def', 'defn', 'defun', 'defmacro', 'defclass', 'lambda', 'fn', 'setv'
]
hy_builtins = []
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py
index 480e4a8f..1cf5fee7 100644
--- a/pygments/lexers/compiled.py
+++ b/pygments/lexers/compiled.py
@@ -2437,7 +2437,7 @@ class AdaLexer(RegexLexer):
"""
name = 'Ada'
- aliases = ['ada', 'ada95' 'ada2005']
+ aliases = ['ada', 'ada95', 'ada2005']
filenames = ['*.adb', '*.ads', '*.ada']
mimetypes = ['text/x-ada']
@@ -3321,7 +3321,7 @@ class RustLexer(RegexLexer):
(r'\s+', Text),
(r'//[/!](.*?)\n', Comment.Doc),
(r'//(.*?)\n', Comment.Single),
- (r'/[*](.|\n)*?[*]/', Comment.Multiline),
+ (r'/\*', Comment.Multiline, 'comment'),
# Keywords
(r'(as|box|break|continue'
@@ -3403,6 +3403,12 @@ class RustLexer(RegexLexer):
(r'([A-Za-z_]\w*)!\s*([A-Za-z_]\w*)?\(',
bygroups(Comment.Preproc, Name), 'macro('),
],
+ 'comment': [
+ (r'[^*/]+', Comment.Multiline),
+ (r'/\*', Comment.Multiline, '#push'),
+ (r'\*/', Comment.Multiline, '#pop'),
+ (r'[*/]', Comment.Multiline),
+ ],
'number_lit': [
(r'(([ui](8|16|32|64)?)|(f(32|64)?))?', Keyword, '#pop'),
],
@@ -3920,11 +3926,11 @@ class ChapelLexer(RegexLexer):
(r'(false|nil|true)\b', Keyword.Constant),
(r'(bool|complex|imag|int|opaque|range|real|string|uint)\b',
Keyword.Type),
- (r'(atomic|begin|break|by|cobegin|coforall|continue|iter|'
+ (r'(align|atomic|begin|break|by|cobegin|coforall|continue|'
r'delete|dmapped|do|domain|else|enum|export|extern|for|forall|'
- r'if|index|inline|label|lambda|let|local|new|on|otherwise|'
- r'reduce|return|scan|select|serial|single|sparse|'
- r'subdomain|sync|then|use|when|where|while|yield|zip)\b',
+ r'if|index|inline|iter|label|lambda|let|local|new|noinit|on|'
+ r'otherwise|pragma|reduce|return|scan|select|serial|single|sparse|'
+ r'subdomain|sync|then|use|when|where|while|with|yield|zip)\b',
Keyword),
(r'(proc)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'procname'),
(r'(class|module|record|union)(\s+)', bygroups(Keyword, Text),
@@ -3946,15 +3952,17 @@ class ChapelLexer(RegexLexer):
(r'0[bB][0-1]+', Number.Bin),
# -- hex
(r'0[xX][0-9a-fA-F]+', Number.Hex),
+ # -- octal
+ (r'0[oO][0-7]+', Number.Oct),
# -- decimal
- (r'(0|[1-9][0-9]*)', Number.Integer),
+ (r'[0-9]+', Number.Integer),
# strings
(r'["\'](\\\\|\\"|[^"\'])*["\']', String),
# tokens
(r'(=|\+=|-=|\*=|/=|\*\*=|%=|&=|\|=|\^=|&&=|\|\|=|<<=|>>=|'
- r'<=>|\.\.|by|#|\.\.\.|'
+ r'<=>|<~>|\.\.|by|#|\.\.\.|'
r'&&|\|\||!|&|\||\^|~|<<|>>|'
r'==|!=|<=|>=|<|>|'
r'[+\-*/%]|\*\*)', Operator),
diff --git a/pygments/lexers/functional.py b/pygments/lexers/functional.py
index a22c4f55..2c13dce3 100644
--- a/pygments/lexers/functional.py
+++ b/pygments/lexers/functional.py
@@ -1530,7 +1530,7 @@ class IdrisLexer(RegexLexer):
'let','proof','of','then','static','where','_','with',
'pattern', 'term', 'syntax','prefix',
'postulate','parameters','record','dsl','impossible','implicit',
- 'tactics','intros','intro','compute','refine','exaxt','trivial']
+ 'tactics','intros','intro','compute','refine','exact','trivial']
ascii = ['NUL','SOH','[SE]TX','EOT','ENQ','ACK',
'BEL','BS','HT','LF','VT','FF','CR','S[OI]','DLE',
@@ -3135,7 +3135,7 @@ def gen_elixir_string_rules(name, symbol, token):
(r'[^#%s\\]+' % (symbol,), token),
include('escapes'),
(r'\\.', token),
- (r'(%s)(:?)' % (symbol,), bygroups(token, Punctuation), "#pop"),
+ (r'(%s)' % (symbol,), bygroups(token), "#pop"),
include('interpol')
]
return states
@@ -3169,7 +3169,7 @@ class ElixirLexer(RegexLexer):
mimetypes = ['text/x-elixir']
KEYWORD = ['fn', 'do', 'end', 'after', 'else', 'rescue', 'catch']
- KEYWORD_OPERATOR = ['not', 'and', 'or', 'xor', 'when', 'in']
+ KEYWORD_OPERATOR = ['not', 'and', 'or', 'when', 'in']
BUILTIN = [
'case', 'cond', 'for', 'if', 'unless', 'try', 'receive', 'raise',
'quote', 'unquote', 'unquote_splicing', 'throw', 'super'
@@ -3184,15 +3184,19 @@ class ElixirLexer(RegexLexer):
PSEUDO_VAR = ['_', '__MODULE__', '__DIR__', '__ENV__', '__CALLER__']
- OPERATORS3 = ['<<<', '>>>', '|||', '&&&', '^^^', '~~~', '===', '!==']
+
+ OPERATORS3 = [
+ '<<<', '>>>', '|||', '&&&', '^^^', '~~~', '===', '!==',
+ '~>>', '<~>', '|~>', '<|>',
+ ]
OPERATORS2 = [
- '==', '!=', '<=', '>=', '&&', '||', '<>', '++', '--', '|>', '=~'
+ '==', '!=', '<=', '>=', '&&', '||', '<>', '++', '--', '|>', '=~',
+ '->', '<-', '|', '.', '=', '~>', '<~',
]
OPERATORS1 = ['<', '>', '+', '-', '*', '/', '!', '^', '&']
PUNCTUATION = [
- '\\\\', '<<', '>>', '::', '->', '<-', '=>', '|', '(', ')',
- '{', '}', ';', ',', '.', '[', ']', '%', '='
+ '\\\\', '<<', '>>', '=>', '(', ')', ':', ';', ',', '[', ']'
]
def get_tokens_unprocessed(self, text):
@@ -3218,20 +3222,19 @@ class ElixirLexer(RegexLexer):
yield index, token, value
def gen_elixir_sigil_rules():
- # these braces are balanced inside the sigil string
- braces = [
+ # all valid sigil terminators (excluding heredocs)
+ terminators = [
(r'\{', r'\}', 'cb'),
(r'\[', r'\]', 'sb'),
(r'\(', r'\)', 'pa'),
(r'\<', r'\>', 'ab'),
+ (r'/', r'/', 'slas'),
+ (r'\|', r'\|', 'pipe'),
+ ('"', '"', 'quot'),
+ ("'", "'", 'apos'),
]
- # these are also valid sigil terminators, they are not balanced
- terms = [
- (r'/', 'slas'), (r'\|', 'pipe'), ('"', 'quot'), ("'", 'apos'),
- ]
-
- # heredocs have slightly different rules, they are not balanced
+ # heredocs have slightly different rules
triquotes = [(r'"""', 'triquot'), (r"'''", 'triapos')]
token = String.Other
@@ -3255,33 +3258,14 @@ class ElixirLexer(RegexLexer):
include('heredoc_no_interpol'),
]
- for term, name in terms:
+ for lterm, rterm, name in terminators:
states['sigils'] += [
- (r'~[a-z]' + term, token, name + '-intp'),
- (r'~[A-Z]' + term, token, name + '-no-intp'),
+ (r'~[a-z]' + lterm, token, name + '-intp'),
+ (r'~[A-Z]' + lterm, token, name + '-no-intp'),
]
-
- # Similar states to the braced sigils, but no balancing of
- # terminators
- states[name +'-intp'] = gen_elixir_sigstr_rules(term, token)
+ states[name +'-intp'] = gen_elixir_sigstr_rules(rterm, token)
states[name +'-no-intp'] = \
- gen_elixir_sigstr_rules(term, token, interpol=False)
-
- for lbrace, rbrace, name in braces:
- states['sigils'] += [
- (r'~[a-z]' + lbrace, token, name + '-intp'),
- (r'~[A-Z]' + lbrace, token, name + '-no-intp')
- ]
-
- states[name +'-intp'] = [
- (r'\\.', token),
- (lbrace, token, '#push'),
- ] + gen_elixir_sigstr_rules(rbrace, token)
-
- states[name +'-no-intp'] = [
- (r'\\.', token),
- (lbrace, token, '#push'),
- ] + gen_elixir_sigstr_rules(rbrace, token, interpol=False)
+ gen_elixir_sigstr_rules(rterm, token, interpol=False)
return states
@@ -3290,28 +3274,35 @@ class ElixirLexer(RegexLexer):
op1_re = "|".join(re.escape(s) for s in OPERATORS1)
ops_re = r'(?:%s|%s|%s)' % (op3_re, op2_re, op1_re)
punctuation_re = "|".join(re.escape(s) for s in PUNCTUATION)
- name_re = r'[a-z_][a-zA-Z_0-9]*[!\?]?'
- modname_re = r'[A-Z][A-Za-z_]*(?:\.[A-Z][A-Za-z_]*)*'
+ alnum = '[A-Za-z_0-9]'
+ name_re = r'(?:\.\.\.|[a-z_]%s*[!\?]?)' % alnum
+ modname_re = r'[A-Z]%(alnum)s*(?:\.[A-Z]%(alnum)s*)*' % {'alnum': alnum}
complex_name_re = r'(?:%s|%s|%s)' % (name_re, modname_re, ops_re)
special_atom_re = r'(?:\.\.\.|<<>>|%{}|%|{})'
+ long_hex_char_re = r'(\\x{)([\da-fA-F]+)(})'
+ hex_char_re = r'(\\x[\da-fA-F]{1,2})'
+ escape_char_re = r'(\\[abdefnrstv])'
+
tokens = {
'root': [
(r'\s+', Text),
(r'#.*$', Comment.Single),
# Various kinds of characters
- (r'(?i)(\?)(\\x{)([\da-f]+)(})',
+ (r'(\?)' + long_hex_char_re,
bygroups(String.Char,
String.Escape, Number.Hex, String.Escape)),
- (r'(?i)(\?)(\\x[\da-f]{1,2})',
- bygroups(String.Char, String.Escape)),
- (r'(\?)(\\[0-7]{1,3})',
+ (r'(\?)' + hex_char_re,
bygroups(String.Char, String.Escape)),
- (r'(\?)(\\[abdefnrstv])',
+ (r'(\?)' + escape_char_re,
bygroups(String.Char, String.Escape)),
(r'\?\\?.', String.Char),
+ # '::' has to go before atoms
+ (r':::', String.Symbol),
+ (r'::', Operator),
+
# atoms
(r':' + special_atom_re, String.Symbol),
(r':' + complex_name_re, String.Symbol),
@@ -3325,6 +3316,10 @@ class ElixirLexer(RegexLexer):
# @attributes
(r'@' + name_re, Name.Attribute),
+ # identifiers
+ (name_re, Name),
+ (r'(%%?)(%s)' % (modname_re,), bygroups(Punctuation, Name.Class)),
+
# operators and punctuation
(op3_re, Operator),
(op2_re, Operator),
@@ -3332,14 +3327,10 @@ class ElixirLexer(RegexLexer):
(r'&\d', Name.Entity), # anon func arguments
(op1_re, Operator),
- # identifiers
- (name_re, Name),
- (modname_re, Name.Class),
-
# numbers
- (r'0[bB][01]+', Number.Bin),
- (r'0[0-7]+', Number.Oct),
- (r'(?i)0x[\da-f]+', Number.Hex),
+ (r'0b[01]+', Number.Bin),
+ (r'0o[0-7]+', Number.Oct),
+ (r'0x[\da-fA-F]+', Number.Hex),
(r'\d(_?\d)*\.\d(_?\d)*([eE][-+]?\d(_?\d)*)?', Number.Float),
(r'\d(_?\d)*', Number.Integer),
@@ -3350,6 +3341,9 @@ class ElixirLexer(RegexLexer):
(r"'", String.Single, 'string_single'),
include('sigils'),
+
+ (r'%{', Punctuation, 'map_key'),
+ (r'{', Punctuation, 'tuple'),
],
'heredoc_double': [
(r'^\s*"""', String.Heredoc, '#pop'),
@@ -3372,11 +3366,10 @@ class ElixirLexer(RegexLexer):
(r'\n+', String.Heredoc),
],
'escapes': [
- (r'(?i)(\\x{)([\da-f]+)(})',
+ (long_hex_char_re,
bygroups(String.Escape, Number.Hex, String.Escape)),
- (r'(?i)\\x[\da-f]{1,2}', String.Escape),
- (r'\\[0-7]{1,3}', String.Escape),
- (r'\\[abdefnrstv]', String.Escape),
+ (hex_char_re, String.Escape),
+ (escape_char_re, String.Escape),
],
'interpol': [
(r'#{', String.Interpol, 'interpol_string'),
@@ -3385,6 +3378,21 @@ class ElixirLexer(RegexLexer):
(r'}', String.Interpol, "#pop"),
include('root')
],
+ 'map_key': [
+ include('root'),
+ (r':', Punctuation, 'map_val'),
+ (r'=>', Punctuation, 'map_val'),
+ (r'}', Punctuation, '#pop'),
+ ],
+ 'map_val': [
+ include('root'),
+ (r',', Punctuation, '#pop'),
+ (r'(?=})', Punctuation, '#pop'),
+ ],
+ 'tuple': [
+ include('root'),
+ (r'}', Punctuation, '#pop'),
+ ],
}
tokens.update(gen_elixir_string_rules('double', '"', String.Double))
tokens.update(gen_elixir_string_rules('single', "'", String.Single))
diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py
index 608e499d..0075fc07 100644
--- a/pygments/lexers/other.py
+++ b/pygments/lexers/other.py
@@ -2473,7 +2473,7 @@ class ProtoBufLexer(RegexLexer):
(r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single),
(r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment.Multiline),
(r'\b(import|option|optional|required|repeated|default|packed|'
- r'ctype|extensions|to|max|rpc|returns)\b', Keyword),
+ r'ctype|extensions|to|max|rpc|returns|oneof)\b', Keyword),
(r'(int32|int64|uint32|uint64|sint32|sint64|'
r'fixed32|fixed64|sfixed32|sfixed64|'
r'float|double|bool|string|bytes)\b', Keyword.Type),
diff --git a/tests/examplefiles/99_bottles_of_beer.chpl b/tests/examplefiles/99_bottles_of_beer.chpl
index f73be7b1..47fcaaf6 100644
--- a/tests/examplefiles/99_bottles_of_beer.chpl
+++ b/tests/examplefiles/99_bottles_of_beer.chpl
@@ -112,7 +112,50 @@ c = nil;
c = new Oval(r=1.0, r2=2.0);
writeln("Area of oval: " + c.area());
+// This is a valid decimal integer:
+var x = 0000000000012;
+
union U {
var i: int;
var r: real;
}
+
+// chapel ranges are awesome.
+var r1 = 1..10, // 1 2 3 4 5 6 7 8 9 10
+ r2 = 10..1, // no values in this range
+ r3 = 1..10 by -1, // 10 9 8 7 6 5 4 3 2 1
+ r4 = 1..10 by 2, // 1 3 5 7 9
+ r5 = 1..10 by 2 align 0, // 2 4 6 8 10
+ r6 = 1..10 by 2 align 2, // 2 4 6 8 10
+ r7 = 1..10 # 3, // 1 2 3
+ r8 = 1..10 # -2, // 9 10
+ r9 = 1..100 # 10 by 2, // 1 3 5 7 9
+ ra = 1..100 by 2 # 10, // 1 3 5 7 9 11 13 15 17 19
+ rb = 1.. # 100 by 10; // 1 11 21 31 41 51 61 71 81 91
+
+// create a variable with default initialization
+var myVarWithoutInit: real = noinit;
+myVarWithoutInit = 1.0;
+
+// Chapel has <~> operator for read and write I/O operations.
+class IntPair {
+ var x: int;
+ var y: int;
+ proc readWriteThis(f) {
+ f <~> x <~> new ioLiteral(",") <~> y <~> new ioNewline();
+ }
+}
+var ip = new IntPair(17,2);
+write(ip);
+
+var targetDom: {1..10},
+ target: [targetDom] int;
+coforall i in targetDom with (ref target) {
+ targetDom[i] = i ** 3;
+}
+
+var wideOpen = 0o777,
+ mememe = 0o600,
+ clique_y = 0O660,
+ zeroOct = 0o0,
+ minPosOct = 0O1;
diff --git a/tests/examplefiles/example_elixir.ex b/tests/examplefiles/example_elixir.ex
index 0912d099..ddca7f60 100644
--- a/tests/examplefiles/example_elixir.ex
+++ b/tests/examplefiles/example_elixir.ex
@@ -1,13 +1,19 @@
# Numbers
0b0101011
-1234 ; 0x1A ; 0xbeef ; 0763
+1234 ; 0x1A ; 0xbeef ; 0763 ; 0o123
3.14 ; 5.0e21 ; 0.5e-12
100_000_000
+# these are not valid numbers
+0b012 ; 0xboar ; 0o888
+0B01 ; 0XAF ; 0O123
+
# Characters
?a ; ?1 ; ?\n ; ?\s ; ?\c ; ? ; ?,
?\x{12} ; ?\x{abcd}
-?\x34 ; ?\xf
+?\x34 ; ?\xF
+
+# these show that only the first digit is part of the character
?\123 ; ?\12 ; ?\7
# Atoms
@@ -18,12 +24,13 @@
line ' \s \123 \xff
atom"
:... ; :<<>> ; :%{} ; :% ; :{}
-:++; :--; :*; :~~~
+:++; :--; :*; :~~~; :::
+:% ; :. ; :<-
# Strings
"Hello world"
-"Interspersed \x{ff} codes \7 \8 \65 \016 and \t\s\z\+ \\ escapes"
-"Quotes ' inside \" \123 the \"\" \xF string \\\" end"
+"Interspersed \x{ff} codes \7 \8 \65 \016 and \t\s\\s\z\+ \\ escapes"
+"Quotes ' inside \" \123 the \"\" \xF \\xF string \\\" end"
"Multiline
string"
@@ -45,18 +52,28 @@ atom"
~w(hello #{ ["has" <> "123", '\c\d', "\123 interpol" | []] } world)s
~W(hello #{no "123" \c\d \123 interpol} world)s
+~s{Escapes terminators \{ and \}, but no {balancing} # outside of sigil here }
+
~S"No escapes \s\t\n and no #{interpolation}"
:"atoms work #{"to" <> "o"}"
# Operators
x = 1 + 2.0 * 3
-y = true and false; z = false xor true
+y = true and false; z = false or true
... = 144
... == !x && y || z
"hello" |> String.upcase |> String.downcase()
{^z, a} = {true, x}
+# Free operators (added in 1.0.0)
+p ~>> f = bind(p, f)
+p1 ~> p2 = pair_right(p1, p2)
+p1 <~ p2 = pair_left(p1, p2)
+p1 <~> p2 = pair_both(p1, p2)
+p |~> f = map(p, f)
+p1 <|> p2 = either(p1, p2)
+
# Lists, tuples, maps, keywords
[1, :a, 'hello'] ++ [2, 3]
[:head | [?t, ?a, ?i, ?l]]
@@ -75,13 +92,18 @@ map = %{shortcut: "syntax"}
# Comprehensions
for x <- 1..10, x < 5, do: {x, x}
pixels = "12345678"
-for << <<r::4, g::4, b::4, a::4>> <- pixels >> do
+for << <<r::4, g::4, b::4, a::size(4)>> <- pixels >> do
[r, {g, %{"b" => a}}]
end
# String interpolation
"String #{inspect "interpolation"} is quite #{1+4+7} difficult"
+# Identifiers
+abc_123 = 1
+_018OP = 2
+A__0 == 3
+
# Modules
defmodule Long.Module.Name do
@moduledoc "Simple module docstring"
@@ -89,7 +111,12 @@ defmodule Long.Module.Name do
@doc """
Multiline docstring
"with quotes"
- and #{ %{"interpolation" => "in" <> "action"} }
+ and #{ inspect %{"interpolation" => "in" <> "action"} }
+ now with #{ {:a, 'tuple'} }
+ and #{ inspect {
+ :tuple,
+ %{ with: "nested #{ inspect %{ :interpolation => %{} } }" }
+ } }
"""
defstruct [:a, :name, :height]
@@ -110,7 +137,8 @@ end
# Structs
defmodule Second.Module do
s = %Long.Module.Name{name: "Silly"}
- %{s | height: {192, :cm}}
+ %Long.Module.Name{s | height: {192, :cm}}
+ ".. #{%Long.Module.Name{s | height: {192, :cm}}} .."
end
# Types, pseudo-vars, attributes
@@ -182,7 +210,7 @@ end
# Lexical scope modifiers
import Kernel, except: [spawn: 1, +: 2, /: 2, Unless: 2]
-alias Long.Module.Name, as: Namen
+alias Long.Module.Name, as: N0men123_and4
use Bitwise
4 &&& 5
diff --git a/tests/examplefiles/rust_example.rs b/tests/examplefiles/rust_example.rs
index 1c0a70c3..8ffbaf6b 100644
--- a/tests/examplefiles/rust_example.rs
+++ b/tests/examplefiles/rust_example.rs
@@ -11,6 +11,8 @@
// based on:
// http://shootout.alioth.debian.org/u32/benchmark.php?test=nbody&lang=java
+/* nest some /* comments */ */
+
extern mod std;
use core::os;