From c5bf2491a3f5612d3029508167e2e772a55972ea Mon Sep 17 00:00:00 2001 From: christophkloeffel Date: Mon, 30 Oct 2023 15:42:58 +0100 Subject: [PATCH] removes the builtin function syntax --- documentation/TUTORIAL-CI.md | 6 +++--- documentation/architecture.md | 6 +----- language-reference-manual/lrm.trlc | 10 ---------- tests-system/builtin-2/legacy.rsl | 10 ---------- tests-system/builtin-2/output | 3 --- tests-system/builtin-2/output.brief | 0 tests-system/builtin-2/output.json | 2 -- tests-system/builtin-2/output.smtlib | 3 --- tests-system/builtin-2/tracing | 1 - tests-unit/test_lexer.py | 6 ------ trlc/ast.py | 17 ----------------- trlc/lexer.py | 12 +----------- trlc/parser.py | 18 +++--------------- 13 files changed, 8 insertions(+), 86 deletions(-) delete mode 100644 tests-system/builtin-2/legacy.rsl delete mode 100644 tests-system/builtin-2/output delete mode 100644 tests-system/builtin-2/output.brief delete mode 100644 tests-system/builtin-2/output.json delete mode 100644 tests-system/builtin-2/output.smtlib delete mode 100644 tests-system/builtin-2/tracing diff --git a/documentation/TUTORIAL-CI.md b/documentation/TUTORIAL-CI.md index e338dd7f..06252d1b 100644 --- a/documentation/TUTORIAL-CI.md +++ b/documentation/TUTORIAL-CI.md @@ -51,9 +51,9 @@ produces additional messages that may be helpful. For example it warns you about deprecated language features: ``` - len == trlc:len(str), warning "potato", len - ^^^^^^^^ legacy.rsl:9: warning: deprecated feature, please use function len instead -Verified 1 model(s) and check(s) and found 1 warning(s) +checks MyType { + ^^^^^^ enum-ok/checks.check:4: issue: move this check block into bar.rsl:1 [deprecated_feature] +Processed 1 model, 1 check and 1 requirement file and found 1 warning ``` ## Return code diff --git a/documentation/architecture.md b/documentation/architecture.md index 60cd97fc..41acd7d7 100644 --- a/documentation/architecture.md +++ b/documentation/architecture.md @@ -313,10 +313,6 @@ Symbol_Table Builtin_Boolean Builtin_String Builtin_Markup_String - Builtin_Function trlc:len - Builtin_Function trlc:startswith - Builtin_Function trlc:endswith - Builtin_Function trlc:matches Builtin_Function len Builtin_Function startswith Builtin_Function endswith @@ -860,7 +856,7 @@ same assumption about `normal_error_1`, any checks under We model types as follows | TRLC Type | PyVCG Sort | SMTLIB Sort | -|------------------|-----------------|-------------| +| ---------------- | --------------- | ----------- | | Builtin_Boolean | BUILTIN_BOOLEAN | Bool | | Builtin_Integer | BUILTIN_INTEGER | Int | | Builtin_Decimal | BUILTIN_REAL | Real | diff --git a/language-reference-manual/lrm.trlc b/language-reference-manual/lrm.trlc index b536ebbf..8057f3bc 100644 --- a/language-reference-manual/lrm.trlc +++ b/language-reference-manual/lrm.trlc @@ -78,13 +78,6 @@ section "Lexing" { "Kitten_Exploder"] } - Terminal Builtin_Identifier { - text = '''There is also a legacy "builtin" identifier that is - deprecated. It will be removed in a future major release.''' - def = "BUILTIN_IDENTIFIER ::= [a-z]+:[a-zA-Z][a-zA-Z0-9_]*" - examples = ["trlc:len"] - } - Keywords TRLC_Keywords { text = '''A keyword is an identifier that is one of the following reserved words:''' @@ -1105,7 +1098,6 @@ section "Names" { Grammar Names { bnf = ''' name ::= qualified_name - | BUILTIN_IDENTIFIER | name '.' IDENTIFIER | name '[' expression ']' | name '(' parameter_list ')' @@ -1116,8 +1108,6 @@ section "Names" { bullets = [ '''A qualified name referring to either some object, a component (in a record) or field (in a tuple), or an enumeration type.''', - '''(Deprecated) A builtin identifier for an old-style - builtin function.''', '''A tuple field or enumeration literal.''', '''An index into an array.''', '''A (builtin) function call.''' diff --git a/tests-system/builtin-2/legacy.rsl b/tests-system/builtin-2/legacy.rsl deleted file mode 100644 index fe091b27..00000000 --- a/tests-system/builtin-2/legacy.rsl +++ /dev/null @@ -1,10 +0,0 @@ -package Legacy - -type T { - str String - len Integer -} - -checks T { - len == trlc:len(str), warning "potato", len -} diff --git a/tests-system/builtin-2/output b/tests-system/builtin-2/output deleted file mode 100644 index c4e639f9..00000000 --- a/tests-system/builtin-2/output +++ /dev/null @@ -1,3 +0,0 @@ -len == trlc:len(str), warning "potato", len - ^^^^^^^^ builtin-2/legacy.rsl:9: issue: please use function len instead [deprecated_feature] -Processed 1 model, 0 checks and 0 requirement files and found 1 warning diff --git a/tests-system/builtin-2/output.brief b/tests-system/builtin-2/output.brief deleted file mode 100644 index e69de29b..00000000 diff --git a/tests-system/builtin-2/output.json b/tests-system/builtin-2/output.json deleted file mode 100644 index d14b35c4..00000000 --- a/tests-system/builtin-2/output.json +++ /dev/null @@ -1,2 +0,0 @@ -{} -Processed 1 model, 0 checks and 0 requirement files and found no issues diff --git a/tests-system/builtin-2/output.smtlib b/tests-system/builtin-2/output.smtlib deleted file mode 100644 index c4e639f9..00000000 --- a/tests-system/builtin-2/output.smtlib +++ /dev/null @@ -1,3 +0,0 @@ -len == trlc:len(str), warning "potato", len - ^^^^^^^^ builtin-2/legacy.rsl:9: issue: please use function len instead [deprecated_feature] -Processed 1 model, 0 checks and 0 requirement files and found 1 warning diff --git a/tests-system/builtin-2/tracing b/tests-system/builtin-2/tracing deleted file mode 100644 index 5c0ff838..00000000 --- a/tests-system/builtin-2/tracing +++ /dev/null @@ -1 +0,0 @@ -LRM.Builtin_Identifier \ No newline at end of file diff --git a/tests-unit/test_lexer.py b/tests-unit/test_lexer.py index 2663c435..6b8a73ba 100644 --- a/tests-unit/test_lexer.py +++ b/tests-unit/test_lexer.py @@ -84,12 +84,6 @@ def testIdentifiers2(self): self.match("IDENTIFIER", "b4r") def testIdentifiers3(self): - # lobster-trace: LRM.Builtin_Identifier - with self.assertRaises(TRLC_Error): - self.input("foo:bar") - self.matchError("builtin function name must start with trlc:") - - def testIdentifiers4(self): # lobster-trace: LRM.Identifier with self.assertRaises(TRLC_Error): self.input("_foo_") diff --git a/trlc/ast.py b/trlc/ast.py index 73b2d387..27e5edfe 100644 --- a/trlc/ast.py +++ b/trlc/ast.py @@ -154,10 +154,6 @@ def dump(self, indent=0): # pragma: no cover Record_Object SomeThing Type: MyType Field description: "Potato" - Builtin_Function trlc:endswith - Builtin_Function trlc:len - Builtin_Function trlc:matches - Builtin_Function trlc:startswith Builtin_Function endswith Builtin_Function len Builtin_Function matches @@ -2199,9 +2195,6 @@ class Builtin_Function(Entity): :attribute arity: number of parameters :type: int - :attribute deprecated: if this functions is deprecated and should no \ - longer be used - :type: bool """ LOCATION = Location(file_name = "") @@ -2210,7 +2203,6 @@ def __init__(self, name, arity): assert isinstance(arity, int) assert arity >= 0 self.arity = arity - self.deprecated = ":" in name def dump(self, indent=0): # pragma: no cover self.write_indent(indent, self.__class__.__name__ + " " + self.name) @@ -3219,15 +3211,6 @@ def create_global_table(cls, mh): stab.register(mh, Builtin_Boolean()) stab.register(mh, Builtin_String()) stab.register(mh, Builtin_Markup_String()) - # The legacy versions - stab.register(mh, - Builtin_Function("trlc:len", 1)) - stab.register(mh, - Builtin_Function("trlc:startswith", 2)) - stab.register(mh, - Builtin_Function("trlc:endswith", 2)) - stab.register(mh, - Builtin_Function("trlc:matches", 2)) # The new-style functions stab.register(mh, diff --git a/trlc/lexer.py b/trlc/lexer.py index 55efda21..d3feebae 100644 --- a/trlc/lexer.py +++ b/trlc/lexer.py @@ -137,7 +137,6 @@ class Token(Token_Base): KIND = { "COMMENT" : "comment", "IDENTIFIER" : "identifier", - "BUILTIN" : "bultin identifier", "KEYWORD" : "keyword", "BRA" : "opening parenthesis '('", "KET" : "closing parenthesis ')'", @@ -161,7 +160,7 @@ class Token(Token_Base): def __init__(self, location, kind, value=None): assert kind in Token.KIND - if kind in ("COMMENT", "IDENTIFIER", "BUILTIN", + if kind in ("COMMENT", "IDENTIFIER", "KEYWORD", "OPERATOR", "STRING"): assert isinstance(value, str) elif kind == "INTEGER": @@ -200,7 +199,6 @@ def __init__(self, mh, content): @staticmethod def is_alpha(char): # lobster-trace: LRM.Identifier - # lobster-trace: LRM.Builtin_Identifier return char.isascii() and char.isalpha() @staticmethod @@ -212,7 +210,6 @@ def is_numeric(char): @staticmethod def is_alnum(char): # lobster-trace: LRM.Identifier - # lobster-trace: LRM.Builtin_Identifier return char.isascii() and char.isalnum() @abstractmethod @@ -591,13 +588,6 @@ def token(self): if value in TRLC_Lexer.KEYWORDS: # lobster-trace: LRM.TRLC_Keywords kind = "KEYWORD" - elif ":" in value: - # lobster-trace: LRM.Builtin_Identifier - kind = "BUILTIN" - if not value.startswith("trlc:"): - self.mh.lex_error(sref, - "builtin function name must start " - "with trlc:") elif kind == "OPERATOR": value = sref.text() diff --git a/trlc/parser.py b/trlc/parser.py index 22d55b3c..764d0f1f 100644 --- a/trlc/parser.py +++ b/trlc/parser.py @@ -1025,15 +1025,6 @@ def parse_builtin(self, scope, n_name, t_name): ast.Builtin_Numeric_Type)) assert isinstance(t_name, Token) - # Lint: complain about old functions - if isinstance(n_name, ast.Builtin_Function) and \ - self.lint_mode and n_name.deprecated: - self.mh.check( - t_name.location, - "please use function %s instead" % - n_name.name.replace("trlc:", ""), - "deprecated_feature") - # Parse the arguments. parameters = [] self.match("BRA") @@ -1056,7 +1047,7 @@ def parse_builtin(self, scope, n_name, t_name): n_name.arity) # Enforce types - if n_name.name in ("len", "trlc:len"): + if n_name.name == "len": if isinstance(parameters[0].typ, ast.Builtin_String): return ast.Unary_Expression( mh = self.mh, @@ -1073,9 +1064,7 @@ def parse_builtin(self, scope, n_name, t_name): n_operand = parameters[0]) elif n_name.name in ("startswith", - "endswith", - "trlc:startswith", - "trlc:endswith"): + "endswith"): return ast.Binary_Expression( mh = self.mh, location = t_name.location, @@ -1086,7 +1075,7 @@ def parse_builtin(self, scope, n_name, t_name): n_lhs = parameters[0], n_rhs = parameters[1]) - elif n_name.name in ("matches", "trlc:matches"): + elif n_name.name == "matches": parameters[1].ensure_type(self.mh, ast.Builtin_String) try: # scope is None on purpose to enforce static context @@ -1134,7 +1123,6 @@ def parse_name(self, scope): # qualified_name ::= [ IDENTIFIER_package_name '.' ] IDENTIFIER_name # # name ::= qualified_name - # | BUILTIN_IDENTIFIER # | name '.' IDENTIFIER # | name '[' expression ']' # | name '(' parameter_list ')'