Skip to content

Commit

Permalink
Update Alloy for Alloy 6 (PR #1963) manual cherry-pick
Browse files Browse the repository at this point in the history
  • Loading branch information
hwayne committed Nov 19, 2022
1 parent 9aa5fc0 commit f1283e6
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 55 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -21,6 +21,7 @@ Version 2.14.0

- Updated lexers:

* Alloy: update for Alloy 6 (#1963)
* C family (C, C++ and many others): fix an issue where a chunk would
be wrongly recognized as a function definition due to braces in
comments (#2210)
Expand Down
22 changes: 15 additions & 7 deletions pygments/lexers/dsls.py
Expand Up @@ -601,7 +601,8 @@ class AlloyLexer(RegexLexer):

flags = re.MULTILINE | re.DOTALL

iden_rex = r'[a-zA-Z_][\w\']*'
iden_rex = r'[a-zA-Z_][\w]*"*'
string_rex = r'"\b(\\\\|\\[^\\]|[^"\\])*"'
text_tuple = (r'[^\S\n]+', Whitespace)

tokens = {
Expand All @@ -621,6 +622,10 @@ class AlloyLexer(RegexLexer):
(r'\{', Operator, '#pop'),
(iden_rex, Name, '#pop'),
],
'fact': [
include('fun'),
(string_rex, String, '#pop'),
],
'root': [
(r'--.*?$', Comment.Single),
(r'//.*?$', Comment.Single),
Expand All @@ -631,17 +636,20 @@ class AlloyLexer(RegexLexer):
(r'(sig|enum)(\s+)', bygroups(Keyword.Declaration, Whitespace), 'sig'),
(r'(iden|univ|none)\b', Keyword.Constant),
(r'(int|Int)\b', Keyword.Type),
(r'(this|abstract|extends|set|seq|one|lone|let)\b', Keyword),
(r'(var|this|abstract|extends|set|seq|one|lone|let)\b', Keyword),
(r'(all|some|no|sum|disj|when|else)\b', Keyword),
(r'(run|check|for|but|exactly|expect|as)\b', Keyword),
(r'(run|check|for|but|exactly|expect|as|steps)\b', Keyword),
(r'(always|after|eventually|until|release)\b', Keyword), # future time operators
(r'(historically|before|once|since|triggered)\b', Keyword), # past time operators
(r'(and|or|implies|iff|in)\b', Operator.Word),
(r'(fun|pred|fact|assert)(\s+)', bygroups(Keyword, Whitespace), 'fun'),
(r'!|#|&&|\+\+|<<|>>|>=|<=>|<=|\.|->', Operator),
(r'[-+/*%=<>&!^|~{}\[\]().]', Operator),
(r'(fun|pred|assert)(\s+)', bygroups(Keyword, Whitespace), 'fun'),
(r'(fact)(\s+)', bygroups(Keyword, Whitespace), 'fact'),
(r'!|#|&&|\+\+|<<|>>|>=|<=>|<=|\.\.|\.|->', Operator),
(r'[-+/*%=<>&!^|~{}\[\]().\';]', Operator),
(iden_rex, Name),
(r'[:,]', Punctuation),
(r'[0-9]+', Number.Integer),
(r'"(\\\\|\\[^\\]|[^"\\])*"', String),
(string_rex, String),
(r'\n', Whitespace),
]
}
Expand Down
40 changes: 20 additions & 20 deletions tests/examplefiles/alloy/example.als
Expand Up @@ -32,8 +32,8 @@ module examples/systems/views
*
* As a terminological convention, when there are two
* complementary view relationships, we will give them types
* t and t'. For example, KeySetView propagates from map to
* set, and KeySetView' propagates from set to map.
* t and t". For example, KeySetView propagates from map to
* set, and KeySetView" propagates from set to map.
*
* author: Daniel Jackson
*/
Expand Down Expand Up @@ -76,12 +76,12 @@ sig SetRef extends Ref {}
fact {State.obj[SetRef] in Set}

abstract sig ViewType {}
one sig KeySetView, KeySetView', IteratorView extends ViewType {}
one sig KeySetView, KeySetView", IteratorView extends ViewType {}
fact ViewTypes {
State.views[KeySetView] in MapRef -> SetRef
State.views[KeySetView'] in SetRef -> MapRef
State.views[KeySetView"] in SetRef -> MapRef
State.views[IteratorView] in IteratorRef -> SetRef
all s: State | s.views[KeySetView] = ~(s.views[KeySetView'])
all s: State | s.views[KeySetView] = ~(s.views[KeySetView"])
}

/**
Expand All @@ -107,20 +107,20 @@ pred allocates [pre, post: State, rs: set Ref] {
}

/**
* models frame condition that limits change to view object from v to v' when backing object changes to b'
* models frame condition that limits change to view object from v to v" when backing object changes to b"
*/
pred viewFrame [t: ViewType, v, v', b': Object] {
t in KeySetView => v'.elts = dom [b'.map]
t in KeySetView' => b'.elts = dom [v'.map]
t in KeySetView' => (b'.elts) <: (v.map) = (b'.elts) <: (v'.map)
t in IteratorView => v'.elts = b'.left + b'.done
pred viewFrame [t: ViewType, v, v", b": Object] {
t in KeySetView => v".elts = dom [b".map]
t in KeySetView" => b".elts = dom [v".map]
t in KeySetView" => (b".elts) <: (v.map) = (b".elts) <: (v".map)
t in IteratorView => v".elts = b".left + b".done
}

pred MapRef.keySet [pre, post: State, setRefs: SetRef] {
post.obj[setRefs].elts = dom [pre.obj[this].map]
modifies [pre, post, none]
allocates [pre, post, setRefs]
post.views = pre.views + KeySetView->this->setRefs + KeySetView'->setRefs->this
post.views = pre.views + KeySetView->this->setRefs + KeySetView"->setRefs->this
}

pred MapRef.put [pre, post: State, k, v: Ref] {
Expand All @@ -141,22 +141,22 @@ pred SetRef.iterator [pre, post: State, iterRef: IteratorRef] {
}

pred IteratorRef.remove [pre, post: State] {
let i = pre.obj[this], i' = post.obj[this] {
i'.left = i.left
i'.done = i.done - i.lastRef
no i'.lastRef
let i = pre.obj[this], i" = post.obj[this] {
i".left = i.left
i".done = i.done - i.lastRef
no i".lastRef
}
modifies [pre,post,this]
allocates [pre, post, none]
pre.views = post.views
}

pred IteratorRef.next [pre, post: State, ref: Ref] {
let i = pre.obj[this], i' = post.obj[this] {
let i = pre.obj[this], i" = post.obj[this] {
ref in i.left
i'.left = i.left - ref
i'.done = i.done + ref
i'.lastRef = ref
i".left = i.left - ref
i".done = i.done + ref
i".lastRef = ref
}
modifies [pre, post, this]
allocates [pre, post, none]
Expand Down
56 changes: 28 additions & 28 deletions tests/examplefiles/alloy/example.als.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f1283e6

Please sign in to comment.