Commit 716fd646 authored by MARTINEZ Thierry 's avatar MARTINEZ Thierry

Functions should be valid identifiers

parent c718c372
......@@ -494,11 +494,7 @@ filter_id([], []).
filter_id([Char | Tail], [Char | TailId]) :-
(
'0' @=< Char, Char @=< '9'
;
'A' @=< Char, Char @=< 'Z'
;
'a' @=< Char, Char @=< 'z'
alphanumeric_char(Char)
;
Char = '_'
;
......@@ -1142,11 +1138,7 @@ parse_latex_command(Chars, Command, Argument, Tail) :-
parse_latex_command_name([Head | Tail], CommandChars, Others) :-
(
'A' @=< Head, Head @=< 'Z'
;
'a' @=< Head, Head @=< 'z'
),
alphabetic_char(Head),
!,
CommandChars = [Head | TailCommandChars],
parse_latex_command_name(Tail, TailCommandChars, Others).
......
......@@ -26,6 +26,13 @@ function(FunctionList) :-
\+ (
Function =.. [Functor | _Arguments],
check_identifier_kind(Functor, function),
(
identifier_name(Functor)
->
true
;
throw(error(invalid_identifier_name(Functor)))
),
catch(
(
find_item([kind: function, key: Functor, id: Id]),
......
......@@ -173,7 +173,7 @@ condition(not Condition) :-
arithmetic_expression([A]) :-
object(A).
name(A).
arithmetic_expression(+ ArithmeticExpression0) :-
arithmetic_expression(ArithmeticExpression0).
......@@ -238,7 +238,7 @@ arithmetic_expression(Number) :-
number(Number).
arithmetic_expression(Name) :-
object(Name).
name(Name).
patch_arithmetic_expression(
......
......@@ -226,6 +226,7 @@ check_grammar_body(
) :-
!,
functor(Item, Functor, Arity),
identifier_name(Functor),
Item =.. [Functor | Arguments],
length(NewArguments, Arity),
NewItem =.. [Functor | NewArguments],
......
......@@ -29,7 +29,11 @@
clean/1,
check_cleaned/1,
join_op/3,
sublist/2
sublist/2,
alphabetic_char/1,
alphanumeric_char/1,
numeric_char/1,
identifier_name/1
]).
name_variables(L) :-
......@@ -431,3 +435,51 @@ sublist([H | T], [H | TT]) :-
sublist(T, [_ | TT]) :-
sublist(T, TT).
uppercase_char(Char) :-
Char @>= 'A', Char @=< 'Z'.
lowercase_char(Char) :-
Char @>= 'a', Char @=< 'z'.
alphabetic_char(Char) :-
(
uppercase_char(Char)
;
lowercase_char(Char)
),
!.
numeric_char(Char) :-
Char @>= 0, Char @=< 9.
alphanumeric_char(Char) :-
(
alphabetic_char(Char)
;
numeric_char(Char)
).
identifier_name(Atom) :-
atom_chars(Atom, [First | Chars]),
alphabetic_char(First),
\+ (
member(Char, Chars),
\+ (
(
alphanumeric_char(Char)
;
Char = '-'
;
Char = '_'
;
Char = '.'
)
)
).
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment