diff --git a/src/languages/erlang.js b/src/languages/erlang.js index 2a7787b336..4fea7a11ad 100644 --- a/src/languages/erlang.js +++ b/src/languages/erlang.js @@ -76,6 +76,10 @@ export default function(hljs) { } ] }; + const CHAR_LITERAL = { + scope: 'string', + match: /\$(\\([^0-9]|[0-9]{1,3}|)|.)/, + }; const BLOCK_STATEMENTS = { beginKeywords: 'fun receive if try case', @@ -93,7 +97,8 @@ export default function(hljs) { TUPLE, VAR1, VAR2, - RECORD_ACCESS + RECORD_ACCESS, + CHAR_LITERAL ]; const BASIC_MODES = [ @@ -106,7 +111,8 @@ export default function(hljs) { TUPLE, VAR1, VAR2, - RECORD_ACCESS + RECORD_ACCESS, + CHAR_LITERAL ]; FUNCTION_CALL.contains[1].contains = BASIC_MODES; TUPLE.contains = BASIC_MODES; @@ -142,6 +148,7 @@ export default function(hljs) { end: '\\)', contains: BASIC_MODES }; + return { name: 'Erlang', aliases: [ 'erl' ], @@ -183,6 +190,7 @@ export default function(hljs) { VAR1, VAR2, TUPLE, + CHAR_LITERAL, { begin: /\.$/ } // relevance booster ] }; diff --git a/test/markup/erlang/char_literal.expect.txt b/test/markup/erlang/char_literal.expect.txt new file mode 100644 index 0000000000..f564777d55 --- /dev/null +++ b/test/markup/erlang/char_literal.expect.txt @@ -0,0 +1,23 @@ +Character = $a +TabCharacter = $\t +TabCharacterDecimal = $\011 +TextWithDollar = "This is just a normal text with a $ in the middle" +StringStart = $" +Backslash = $\\ +ListStart = $[ +ListEnd = $] +SpaceChar = $ % yes, that works +fun_takes_literal($a) -> ok. +fun_takes_literal_list([$a|Rest]) -> ok. +fun_takes_literal_binary(<<$a, Rest/binary>>) -> ok. +convert_escape_sequence(<<$\\, Escaped, Rest/binary>>) -> + C = case Escaped of + $b -> $\b; + $f -> $\f; + $n -> $\n; + $r -> $\r; + $t -> $\t; + $" -> $"; + $\\ -> $\\; + _ -> error + end diff --git a/test/markup/erlang/char_literal.txt b/test/markup/erlang/char_literal.txt new file mode 100644 index 0000000000..b8402f32af --- /dev/null +++ b/test/markup/erlang/char_literal.txt @@ -0,0 +1,23 @@ +Character = $a +TabCharacter = $\t +TabCharacterDecimal = $\011 +TextWithDollar = "This is just a normal text with a $ in the middle" +StringStart = $" +Backslash = $\\ +ListStart = $[ +ListEnd = $] +SpaceChar = $ % yes, that works +fun_takes_literal($a) -> ok. +fun_takes_literal_list([$a|Rest]) -> ok. +fun_takes_literal_binary(<<$a, Rest/binary>>) -> ok. +convert_escape_sequence(<<$\\, Escaped, Rest/binary>>) -> + C = case Escaped of + $b -> $\b; + $f -> $\f; + $n -> $\n; + $r -> $\r; + $t -> $\t; + $" -> $"; + $\\ -> $\\; + _ -> error + end