Skip to content

Commit

Permalink
removes the builtin function syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
christophkloeffel committed Oct 30, 2023
1 parent bc4c5cc commit c5bf249
Show file tree
Hide file tree
Showing 13 changed files with 8 additions and 86 deletions.
6 changes: 3 additions & 3 deletions documentation/TUTORIAL-CI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions documentation/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 |
Expand Down
10 changes: 0 additions & 10 deletions language-reference-manual/lrm.trlc
Original file line number Diff line number Diff line change
Expand Up @@ -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:'''
Expand Down Expand Up @@ -1105,7 +1098,6 @@ section "Names" {
Grammar Names {
bnf = '''
name ::= qualified_name
| BUILTIN_IDENTIFIER
| name '.' IDENTIFIER
| name '[' expression ']'
| name '(' parameter_list ')'
Expand All @@ -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.'''
Expand Down
10 changes: 0 additions & 10 deletions tests-system/builtin-2/legacy.rsl

This file was deleted.

3 changes: 0 additions & 3 deletions tests-system/builtin-2/output

This file was deleted.

Empty file.
2 changes: 0 additions & 2 deletions tests-system/builtin-2/output.json

This file was deleted.

3 changes: 0 additions & 3 deletions tests-system/builtin-2/output.smtlib

This file was deleted.

1 change: 0 additions & 1 deletion tests-system/builtin-2/tracing

This file was deleted.

6 changes: 0 additions & 6 deletions tests-unit/test_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_")
Expand Down
17 changes: 0 additions & 17 deletions trlc/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = "<builtin>")

Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 1 addition & 11 deletions trlc/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ class Token(Token_Base):
KIND = {
"COMMENT" : "comment",
"IDENTIFIER" : "identifier",
"BUILTIN" : "bultin identifier",
"KEYWORD" : "keyword",
"BRA" : "opening parenthesis '('",
"KET" : "closing parenthesis ')'",
Expand All @@ -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":
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 3 additions & 15 deletions trlc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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 ')'
Expand Down

0 comments on commit c5bf249

Please sign in to comment.