Skip to content

Commit

Permalink
Improve cell cards
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Apr 13, 2024
1 parent 1a81973 commit 2cbbca4
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 49 deletions.
64 changes: 45 additions & 19 deletions MCNP.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ variables:
contexts:
main:
- include: comments
- include: surface-cards
- include: cell-cards
- include: surface-cards
- include: data-cards
- include: numbers
- include: operators
Expand Down Expand Up @@ -161,32 +161,58 @@ contexts:
###[ CELL CARDS ]##############################################################

cell-cards:
# like-cell-cards
- match: (?i)^\s{0,4}(\d+)\s+(like)\s+\d+\s+(but){{break}}
captures:
1: keyword.cellnumber.mcnp
2: constant.language.mcnp
3: constant.language.mcnp
# Form 2: j LIKE n BUT list
- match: (?i)^\s{0,4}(\d+)\s+(like)\s+(\d+)\s+(but){{break}}
scope: meta.cell.mcnp
captures:
1: entity.name.cell.mcnp
2: keyword.other.mcnp
3: meta.number.integer.decimal.mcnp constant.numeric.value.mcnp
4: keyword.other.mcnp
push: cell-body
# material-cell-cards
- match: (?i)^\s{0,4}(\d+)\s+(?=[1-9]\d*\s+\S+)
# Form 1: j m d geom params
# does not look like a numberd surface
- match: (?i)^\s{0,4}(\d+)\s+(?=\d+(?!\s+[a-z]))
scope: meta.cell.mcnp
captures:
1: keyword.cellnumber.mcnp
push: cell-body
# void-cell-cards
- match: (?i)^\s{0,4}(\d+)\s+(0){{break}}
captures:
1: keyword.cellnumber.mcnp
2: constant.numeric.cellmaterial.mcnp
1: entity.name.cell.mcnp
push: cell-body

cell-body:
- meta_content_scope: meta.cell.mcnp
- include: statement-end
- include: comments
- include: numbers
- include: operators
- match: (?i:IMP|VOL|PWT|EXT|FCL|WWN|DXC|NONU|PD|TMP|TRCL|LAT|FILL|ELPT|COSY|BFLCL|UNC|U)\b
scope: variable.other.mcnp
- include: cell-groups
- include: cell-operators
- match: (?i:IMP|VOL|PWT|EXT|FCL|WWN|DXC|NONU|PD|TMP|TRCL|LAT|FILL|ELPT|COSY|BFLCL|UNC|U)(?i:(:)[np]?)?
scope: variable.parameter.mcnp
captures:
1: punctuation.separator.colon.mcnp

cell-groups:
- match: \(
scope: punctuation.section.group.begin.mcnp
push: cell-group-body

cell-group-body:
- meta_scope: meta.group.mcnp
- match: \)
scope: punctuation.section.group.begin.mcnp
pop: 1
- include: statement-end
- include: comments
- include: numbers
- include: cell-groups
- include: cell-operators

cell-operators:
- match: =
scope: keyword.operator.assignment.mcnp
- match: \#
scope: keyword.operator.complement.mcnp
- match: ':'
scope: keyword.operator.union.mcnp

###[ SURFACE CARDS ]###########################################################

Expand Down
20 changes: 20 additions & 0 deletions Symbol List - Cell Cards.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>scope</key>
<string>source.mcnp meta.cell</string>
<key>settings</key>
<dict>
<key>showInSymbolList</key>
<integer>1</integer>
<key>symbolTransformation</key>
<string><![CDATA[
s/\$.*\n//g; # strip inline comments
s/^\s{,4}[cC].*\n//g; # strip line comments
s/^\s*//g; # strip leading whitespace
s/\s*$//g; # strip all trailing whitespace
s/\s+/ /g; # convert (multiple) whitespace to one space
]]></string>
</dict>
</dict>
</plist>
149 changes: 119 additions & 30 deletions tests/syntax_test_mcnp.mcnp
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,98 @@ $ comment
$ <- comment.line.mcnp punctuation.definition.comment.mcnp
$^^^^^^^^ comment.line.mcnp - punctuation

ACT dnbias $ comment
$ <- keyword.other.mcnp
$^^ keyword.other.mcnp
$ ^^^^^^ variable.other.mcnp
$ ^^^^^^^^^ comment.line.mcnp
c Cell Cards

ACT dnbias $ comment
$ ^^^ keyword.other.mcnp
$ ^^^^^^ variable.other.mcnp
$ ^^^^^^^^^ comment.line.mcnp
1 0 -1 2 -4 $ definition of cell 3
$ <- meta.cell.mcnp entity.name.cell.mcnp
$^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.cell.mcnp
$ ^ meta.number.integer.decimal.mcnp constant.numeric.value.mcnp
$ ^^ meta.number.integer.decimal.mcnp
$ ^ keyword.operator.arithmetic.mcnp
$ ^ constant.numeric.value.mcnp
$ ^ meta.number.integer.decimal.mcnp constant.numeric.value.mcnp
$ ^ meta.number.integer.decimal.mcnp keyword.operator.arithmetic.mcnp
$ ^ meta.number.integer.decimal.mcnp constant.numeric.value.mcnp

ACT dnbias $ comment
$ ^^^ - keyword
$ ^^^^^^ - variable
$ ^^^^^^^^^ comment.line.mcnp
2 0 #1 $ equivalent to each of the next 2 lines
$ <- meta.cell.mcnp entity.name.cell.mcnp
$^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.cell.mcnp
$ ^ meta.number.integer.decimal.mcnp constant.numeric.value.mcnp
$ ^ keyword.operator.complement.mcnp
$ ^ meta.number.integer.decimal.mcnp constant.numeric.value.mcnp

bfld4 type const
$ <- keyword.other.mcnp
$^^^ keyword.other.mcnp
$ ^ constant.numeric.value.mcnp
$ ^^^^ variable.other.mcnp
$ ^^^^^ constant.language.mcnp
2 0 #(-1 2 -4)
$ <- meta.cell.mcnp entity.name.cell.mcnp
$^^^^ meta.cell.mcnp - meta.group
$ ^^^^^^^^^ meta.cell.mcnp meta.group.mcnp
$ ^ constant.numeric.value.mcnp
$ ^ keyword.operator.complement.mcnp
$ ^ punctuation.section.group.begin.mcnp
$ ^^ meta.group.mcnp meta.number.integer.decimal.mcnp
$ ^ keyword.operator.arithmetic.mcnp
$ ^ constant.numeric.value.mcnp
$ ^ meta.number.integer.decimal.mcnp constant.numeric.value.mcnp
$ ^^ meta.number.integer.decimal.mcnp
$ ^ keyword.operator.arithmetic.mcnp
$ ^ constant.numeric.value.mcnp
$ ^ punctuation.section.group.begin.mcnp

bfld4 type = const
$ <- keyword.other.mcnp
$^^^ keyword.other.mcnp
$ ^ constant.numeric.value.mcnp
$ ^^^^ variable.other.mcnp
$ ^ keyword.operator.assignment.mcnp
$ ^^^^^ constant.language.mcnp
2 0 (+1 : -2 : +4)
$ <- meta.cell.mcnp entity.name.cell.mcnp
$^^^ meta.cell.mcnp - meta.group
$ ^^^^^^^^^^^^^ meta.cell.mcnp meta.group.mcnp
$ ^ constant.numeric.value.mcnp
$ ^ punctuation.section.group.begin.mcnp
$ ^^ meta.group.mcnp meta.number.integer.decimal.mcnp
$ ^ keyword.operator.arithmetic.mcnp
$ ^ constant.numeric.value.mcnp
$ ^ keyword.operator.union.mcnp
$ ^^ meta.number.integer.decimal.mcnp
$ ^ keyword.operator.arithmetic.mcnp
$ ^ constant.numeric.value.mcnp
$ ^ keyword.operator.union.mcnp
$ ^ keyword.operator.arithmetic.mcnp
$ ^ constant.numeric.value.mcnp
$ ^ punctuation.section.group.begin.mcnp

c Cell Cards
1 100 -0.0014 -7 imp:n=1 tmp=2.53e-08
2 200 -7.86 -8 imp:n=1 tmp=2.53e-08
4 0 -1:2:3:-4:5:-6
3 100 -0.0014 -7 imp:n=1 tmp=2.53e-08
$ <- meta.cell.mcnp entity.name.cell.mcnp
$^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.cell.mcnp
$ ^^^ meta.number.integer.decimal.mcnp constant.numeric.value.mcnp
$ ^^^^^^^ meta.number.float.decimal.mcnp
$ ^ keyword.operator.arithmetic.mcnp
$ ^^^^^^ constant.numeric.value.mcnp
$ ^^ meta.number.integer.decimal.mcnp
$ ^^^^^ variable.parameter.mcnp
$ ^ keyword.operator.assignment.mcnp
$ ^ constant.numeric.value.mcnp
$ ^^^ variable.parameter.mcnp
$ ^ keyword.operator.assignment.mcnp
$ ^^^^^^^^ meta.number.float.decimal.mcnp constant.numeric.value.mcnp

4 LIKE 2 BUT IMP:N=10 TRCL=1
$ <- meta.cell.mcnp entity.name.cell.mcnp
$^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.cell.mcnp
$ ^^^^ keyword.other.mcnp
$ ^ constant.numeric.value.mcnp
$ ^^^ keyword.other.mcnp
$ ^^^^^ variable.parameter.mcnp
$ ^ punctuation.separator.colon.mcnp
$ ^ keyword.operator.assignment.mcnp
$ ^^ constant.numeric.value.mcnp
$ ^^^^ variable.parameter.mcnp
$ ^ keyword.operator.assignment.mcnp
$ ^ constant.numeric.value.mcnp

5 LIKE 2 BUT IMP=0
$ ^^^^^^^^^^^^^^^^^^^^^^ - meta.cell
$ ^ meta.number.integer.decimal.mcnp constant.numeric.value.mcnp
$ ^^^^ - keyword
$ ^ meta.number.integer.decimal.mcnp constant.numeric.value.mcnp
$ ^^^ - keyword
$ ^^^ - variable
$ ^ keyword.operator.assignment.mcnp
$ ^ meta.number.integer.decimal.mcnp constant.numeric.value.mcnp

c Surface Cards

Expand Down Expand Up @@ -165,3 +222,35 @@ $ ^^^ constant.language.mcnp
$ ^^^ variable.other.mcnp
$ ^ keyword.operator.assignment.mcnp
$ ^^^^ constant.language.mcnp


ACT dnbias $ comment
$ <- keyword.other.mcnp
$^^ keyword.other.mcnp
$ ^^^^^^ variable.other.mcnp
$ ^^^^^^^^^ comment.line.mcnp

ACT dnbias $ comment
$ ^^^ keyword.other.mcnp
$ ^^^^^^ variable.other.mcnp
$ ^^^^^^^^^ comment.line.mcnp

ACT dnbias $ comment
$ ^^^ - keyword
$ ^^^^^^ - variable
$ ^^^^^^^^^ comment.line.mcnp

bfld4 type const
$ <- keyword.other.mcnp
$^^^ keyword.other.mcnp
$ ^ constant.numeric.value.mcnp
$ ^^^^ variable.other.mcnp
$ ^^^^^ constant.language.mcnp

bfld4 type = const
$ <- keyword.other.mcnp
$^^^ keyword.other.mcnp
$ ^ constant.numeric.value.mcnp
$ ^^^^ variable.other.mcnp
$ ^ keyword.operator.assignment.mcnp
$ ^^^^^ constant.language.mcnp

0 comments on commit 2cbbca4

Please sign in to comment.