Skip to content

Commit

Permalink
sync with LAMMPS version 2 August 2023
Browse files Browse the repository at this point in the history
  • Loading branch information
akohlmey committed Oct 10, 2023
1 parent 6c8ac48 commit 286b34e
Showing 1 changed file with 71 additions and 27 deletions.
98 changes: 71 additions & 27 deletions pygments_lammps/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,34 @@

__all__ = ["LAMMPSLexer"]

LAMMPS_COMMANDS = ("angle_coeff", "angle_style", "atom_modify", "atom_style",
"balance", "bond_coeff", "bond_style", "bond_write", "boundary", "box",
"clear", "comm_modify", "comm_style",
"compute_modify", "create_atoms", "create_bonds", "create_box", "delete_atoms",
"delete_bonds", "dielectric", "dihedral_coeff", "dihedral_style", "dimension",
"displace_atoms", "dump_modify", "dynamical_matrix", "echo", "elif", "else",
"fix_modify", "group2ndx", "hyper", "if", "improper_coeff",
"improper_style", "include", "info", "jump", "kim",
"kspace_modify", "kspace_style", "label", "lattice",
"log", "mass", "message", "minimize", "min_modify", "min_style", "molecule",
"ndx2group", "neb", "neb/spin", "neighbor", "neigh_modify", "newton", "next",
"package", "pair_coeff", "pair_modify", "pair_style", "pair_write",
"partition", "prd", "print", "processors", "python", "quit", "read_data",
"read_dump", "read_restart", "replicate", "rerun", "reset_ids",
"reset_timestep", "restart", "run", "run_style", "server", "set", "shell",
"special_bonds", "suffix", "tad", "temper", "temper/grem", "temper/npt", "then",
"thermo", "thermo_modify", "thermo_style", "third_order", "timer", "timestep",
"units", "velocity", "write_coeff",
"write_data", "write_restart")
LAMMPS_COMMANDS = ("angle_coeff", "angle_style", "atom_modify",
"atom_style", "angle_write", "balance", "bond_coeff",
"bond_style", "bond_write", "boundary", "clear",
"comm_modify", "comm_style", "compute_modify",
"create_atoms", "create_bonds", "create_box",
"delete_atoms", "delete_bonds", "dielectric",
"dihedral_coeff", "dihedral_style", "dihedral_write",
"dimension", "displace_atoms", "dump_modify",
"dynamical_matrix", "echo", "fitpod",
"fix_modify", "group2ndx", "hyper",
"improper_coeff", "improper_style", "include",
"info", "jump", "kim", "kspace_modify",
"kspace_style", "label", "labelmap", "lattice",
"log", "mass", "mdi", "message", "minimize",
"min_modify", "min_style", "molecule", "ndx2group",
"neb", "neb/spin", "neighbor", "neigh_modify",
"newton", "next", "package", "pair_coeff",
"pair_modify", "pair_style", "pair_write",
"partition", "plugin", "prd", "print", "processors",
"python", "quit", "read_data", "read_dump",
"read_restart", "replicate", "rerun", "reset_atoms",
"reset_timestep", "restart", "run", "run_style",
"server", "set", "shell", "special_bonds", "suffix",
"tad", "temper", "temper/grem", "temper/npt",
"thermo", "thermo_modify", "thermo_style",
"third_order", "timer", "timestep", "units",
"velocity", "write_coeff", "write_data",
"write_restart")

#fix ID group-ID style args
#compute ID group-ID style args
Expand All @@ -49,16 +58,34 @@ class LAMMPSLexer(RegexLexer):
tokens = {
'root': [
(r'fix\s+', Keyword, 'fix'),
(r'fix_modify\s+', Keyword, 'modify_cmd'),
(r'compute\s+', Keyword, 'compute'),
(r'compute_modify\s+', Keyword, 'modify_cmd'),
(r'dump\s+', Keyword, 'dump'),
(r'dump_modify\s+', Keyword, 'modify_cmd'),
(r'region\s+', Keyword, 'region'),
(r'^\s*variable\s+', Keyword, 'variable_cmd'),
(r'variable\s+', Keyword, 'variable_cmd'),
(r'group\s+', Keyword, 'group'),
(r'change_box\s+', Keyword, 'change_box'),
(r'uncompute\s+', Keyword, 'uncompute'),
(r'unfix\s+', Keyword, 'unfix'),
(r'undump\s+', Keyword, 'undump'),
(r'create_box\s+', Keyword, 'create_box'),
(r'delete_bonds\s+', Keyword, 'id_cmd'),
(r'displace_atoms\s+', Keyword, 'id_cmd'),
(r'dynamical_matrix\s+', Keyword, 'id_cmd'),
(r'group2ndx\s+', Keyword, 'ndx_cmd'),
(r'ndx2group\s+', Keyword, 'ndx_cmd'),
(r'jump\s+', Keyword, 'jump_cmd'),
(r'label\s+', Keyword, 'jump_cmd'),
(r'next\s+', Keyword, 'id_cmd'),
(r'kim\s+', Keyword, 'kim_cmd'),
(r'uncompute\s+', Keyword, 'id_cmd'),
(r'unfix\s+', Keyword, 'id_cmd'),
(r'undump\s+', Keyword, 'id_cmd'),
(r'velocity\s+', Keyword, 'id_cmd'),
(r'write_coeff\s+', Keyword, 'ndx_cmd'),
(r'write_data\s+', Keyword, 'ndx_cmd'),
(r'write_dump\s+', Keyword, 'write_dump'),
(r'write_restart\s+', Keyword, 'ndx_cmd'),
include('conditionals'),
include('keywords'),
(r'#.*?\n', Comment),
('"', String, 'string'),
Expand All @@ -73,8 +100,12 @@ class LAMMPSLexer(RegexLexer):
(r'[\+\-\*\^\|\/\!%&=<>]', Operator),
(r'[\~\.\w_:,@\-\/\\0-9]+', Text),
],
'conditionals' : [
(words(('if','else','elif','then'), suffix=r'\b', prefix=r'\b'), Keyword)
]
,
'keywords' : [
(words(LAMMPS_COMMANDS, suffix=r'\b', prefix=r'^'), Keyword)
(words(LAMMPS_COMMANDS, suffix=r'\b', prefix=r'^\s*'), Keyword)
]
,
'variable' : [
Expand All @@ -94,6 +125,10 @@ class LAMMPSLexer(RegexLexer):
('\(', Name.Variable, 'expression'),
('\)', Name.Variable, '#pop'),
],
'modify_cmd' : [
(r'[\w_\-\.\[\]]+', Name.Variable.Identifier),
default('#pop')
],
'fix' : [
(r'[\w_\-\.\[\]]+', Name.Variable.Identifier),
(r'\s+', Whitespace, 'group_id'),
Expand Down Expand Up @@ -125,18 +160,27 @@ class LAMMPSLexer(RegexLexer):
(r'[\w_\-\.\[\]]+', Name.Variable.Identifier),
default('#pop')
],
'unfix' : [
'create_box' : [
(r'[\w_\-\.\[\]]+', Name.Variable.Identifier),
(r'\s+', Whitespace, 'group_id'),
default('#pop')
],
'undump' : [
'id_cmd' : [
(r'[\w_\-\.\[\]]+', Name.Variable.Identifier),
default('#pop')
],
'uncompute' : [
'ndx_cmd' : [
(r'[\w_\-\.\[\]]+', Name.Variable.Identifier),
default('#pop')
],
'jump_cmd' : [
(r'[\w_\-\.\[\]]+', Literal.String.Char),
default('#pop')
],
'kim_cmd' : [
(r'[\w_\-\.\[\]]+', Literal.String.Single),
default('#pop')
],
'write_dump' : [
(r'[\w_\-\.\[\]]+', Name.Variable.Identifier),
default('#pop')
Expand Down

0 comments on commit 286b34e

Please sign in to comment.