|
|
@@ -2,8 +2,8 @@ Definitions.
|
|
|
|
|
|
Control = [()&|!=~><:*]
|
|
|
White = [\s\t\n\r]+
|
|
|
-StringChars = [^()&|!=~><:*\t\n\r]
|
|
|
-Escape = \\{Control}|\\{White}
|
|
|
+StringChars = [^()&|!=~><:*\t\n\r\\]
|
|
|
+Escape = \\\\|\\{Control}|\\{White}
|
|
|
String = ({Escape}|{StringChars})+
|
|
|
|
|
|
Rules.
|
|
|
@@ -23,7 +23,7 @@ Rules.
|
|
|
{White} : skip_token.
|
|
|
{String} : {token, {string, TokenLine, to_string(TokenChars)}}.
|
|
|
%% Leex will hang if a composite operation is missing a character
|
|
|
-{Control} : {error, lists:flatten(io_lib:format("Unexpected Tokens:~ts", [TokenChars]))}.
|
|
|
+{Control} : {error, format("Unexpected Tokens:~ts", [TokenChars])}.
|
|
|
|
|
|
Erlang code.
|
|
|
|
|
|
@@ -34,4 +34,19 @@ Erlang code.
|
|
|
%% so after the tokenization we should remove all escape character
|
|
|
to_string(TokenChars) ->
|
|
|
String = string:trim(TokenChars),
|
|
|
- lists:flatten(string:replace(String, "\\", "", all)).
|
|
|
+ trim_escape(String).
|
|
|
+
|
|
|
+%% because of the below situation, we can't directly use the `replace` to trim the escape character
|
|
|
+%%trim_escape([$\\, $\\ | T]) ->
|
|
|
+%% [$\\ | trim_escape(T)];
|
|
|
+trim_escape([$\\, Char | T]) ->
|
|
|
+ [Char | trim_escape(T)];
|
|
|
+%% the underneath is impossible to occur because it is not valid in the lexer
|
|
|
+%% trim_escape([$\\])
|
|
|
+trim_escape([Char | T]) ->
|
|
|
+ [Char | trim_escape(T)];
|
|
|
+trim_escape([]) ->
|
|
|
+ [].
|
|
|
+
|
|
|
+format(Fmt, Args) ->
|
|
|
+ lists:flatten(io_lib:format(Fmt, Args)).
|