-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding some tests, breaking out ampgen style and dec style particles.
- Loading branch information
Showing
5 changed files
with
150 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import re | ||
|
||
getname = re.compile(r''' | ||
^ # Beginning of string | ||
(?P<name> \w+? ) # One or more characters, non-greedy | ||
(?:\( (?P<family> [udsctb][\w]*) \) )? # Optional family like (s) | ||
(?:\( (?P<state> \d+ ) \) # Optional state in () | ||
(?= \*? \( ) )? # - lookahead for mass | ||
(?P<star> \* )? # Optional star | ||
(?:\( (?P<mass> \d+ ) \) )? # Optional mass in () | ||
(?P<bar> (bar|~) )? # Optional bar | ||
(?P<charge> [0\+\-][+-]?) # Required 0, -, --, or +, ++ | ||
$ # End of string | ||
''', re.VERBOSE) | ||
|
||
getdec = re.compile(r''' | ||
^ # Beginning of string | ||
(?P<bar> (anti-) )? # Optional anti- | ||
(?P<name> [a-zA-Z]+? ) # One or more characters, non-greedy | ||
(?P<prime> '* ) # Optional prime(s) | ||
(?: _ (?P<state> \d+ ) )? # Optional state in () | ||
(?: (?P<family> _[udsctb][\w]*) )? # Optional family like (s) | ||
(?:\( (?P<mass> \d+ ) \) )? # Optional mass in () | ||
(?P<star> \*? ) # Optional star | ||
(?P<charge> [0\+\-][+-]?) # Required 0, -, --, or +, ++ | ||
$ # End of string | ||
''', re.VERBOSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from decaylanguage import data | ||
from decaylanguage.particle import Particle, ParticleNotFound | ||
from decaylanguage.dec import dec | ||
from lark import Lark, Transformer, Tree | ||
|
||
import pytest | ||
|
||
class TreeToDec2(Transformer): | ||
missing = set() | ||
keyerrs = set() | ||
|
||
def __init__(self, alias_dict): | ||
self.alias_dict = alias_dict | ||
|
||
def particle(self, items): | ||
label, = items | ||
if label in self.alias_dict: | ||
label = self.alias_dict[label] | ||
try: | ||
return Particle.from_string(str(label)) | ||
except ParticleNotFound: | ||
self.missing.add(str(label)) | ||
return str(label) | ||
except KeyError: | ||
self.keyerrs.add(str(label)) | ||
return str(label) | ||
|
||
@pytest.mark.skip | ||
def test_dec_full(): | ||
with data.open_text(data, 'DECAY_LHCB.DEC') as f: | ||
txt = f.read() | ||
|
||
with data.open_text(data, 'decfile.lark') as f: | ||
grammar = f.read() | ||
|
||
l = Lark(grammar, parser='lalr', lexer='standard') # , transformer = TreeToDec()) | ||
|
||
parsed = l.parse(txt) | ||
assert bool(parsed) | ||
|
||
transformed = dec.TreeToDec().transform(parsed) | ||
|
||
define = dec.define(transformed) | ||
pythia_def = dec.pythia_def(transformed) | ||
alias = dec.alias(transformed) | ||
chargeconj = dec.chargeconj(transformed) | ||
global_photos = dec.global_photos(transformed) | ||
decay = dec.decay(transformed) | ||
cdecay = dec.cdecay(transformed) | ||
setlspw = dec.setlspw(transformed) | ||
|
||
for item in pythia_def: | ||
print(item[0], ":", item[1], "=", item[2]) | ||
|
||
|
||
labelled = TreeToDec2(alias).transform(decay) | ||
|
||
print(TreeToDec2.missing) | ||
print(TreeToDec2.keyerrs) | ||
|
||
assert len(TreeToDec2.missing) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters