Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions latticejson/madx.lark
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ string : ESCAPED_STRING
word : /[\w\.]+/

start : (_statement ";")*
_statement : element | lattice | command | assignment
_statement : element | lattice | sequence | command | assignment

element : word ":" [word] ("," attribute)* ","?
attribute : word ("=" | ":=") (expr | string)


lattice : word ":" "LINE"i "=" arrangement
arrangement : [int "*"] [/-/] "(" object ("," object)* ")"
?object : ref_name | arrangement
ref_name : [int "*"] [/-/] word

sequence : word ":" "SEQUENCE"i ("," attribute)* ";" seq_elements "ENDSEQUENCE"i
seq_elements: (element ";")*

command : word ("," (word | string | attribute))*

// Arithmeitc Expressions
Expand Down
10 changes: 8 additions & 2 deletions latticejson/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def transform(self, tree):
string = lambda self, item: item[1:-1]

def element(self, name, type_, *attributes):
self.elements[name.lower()] = type_.lower(), dict(attributes)
self.elements[name.upper()] = type_.upper(), dict(attributes)
return name

def attribute(self, name, value):
return name.lower(), value
Expand Down Expand Up @@ -150,7 +151,12 @@ def command(self, *items):

@v_args(inline=True)
class MADXTransformer(ArithmeticTransformer, AbstractLatticeFileTransformer):
pass
def sequence(self, name, *items):
*attributes, elements = items
self.lattices[name.upper()] = elements

def seq_elements(self, *elements):
return list(elements)


@v_args(inline=True)
Expand Down