Skip to content

Commit

Permalink
Adding more macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Officer committed Feb 17, 2012
1 parent 5d6f1f1 commit c698bd6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
3 changes: 3 additions & 0 deletions DicomDSL/DicomDSL.booproj
Expand Up @@ -49,6 +49,9 @@
<Compile Include="LOMacro.boo" />
<Compile Include="LTMacro.boo" />
<Compile Include="PNMacro.boo" />
<Compile Include="SHMacro.boo" />
<Compile Include="SLMacro.boo" />
<Compile Include="SQMacro.boo" />
<Compile Include="TagMacro.boo" />
<Compile Include="UIMacro.boo" />
<Compile Include="ULMacro.boo" />
Expand Down
2 changes: 1 addition & 1 deletion DicomDSL/PNMacro.boo
Expand Up @@ -3,7 +3,7 @@
import System
import Boo.Lang.Compiler.Ast

class PersonNameMacro(TagMacro):
final class PersonNameMacro(TagMacro):
"""Description of PNMacro"""
public def constructor():
pass
Expand Down
25 changes: 25 additions & 0 deletions DicomDSL/SHMacro.boo
@@ -0,0 +1,25 @@
namespace DicomDSL

import System
import Boo.Lang.Compiler.Ast

final class ShortStringMacro(TagMacro):
"""Description of SHMacro"""
public def constructor():
pass

VR:
get: return "SH"

def ReadTagValues(data_arguments as ExpressionCollection):
values = List[of string](data_arguments.Count)
for arg in data_arguments:
raise TagException(arg.LexicalInfo, "The tag values must be a $NodeType.StringLiteralExpression") if arg.NodeType != NodeType.StringLiteralExpression
v = (arg as StringLiteralExpression).Value
raise TagException(arg.LexicalInfo, "An $VR value cannot contain the LF character.") if char(0x0A) in v
raise TagException(arg.LexicalInfo, "An $VR value cannot contain the FF character.") if char(0x0C) in v
raise TagException(arg.LexicalInfo, "An $VR value cannot contain the CR character.") if char(0x0D) in v
raise TagException(arg.LexicalInfo, "An $VR value cannot contain the \\ character.") if char(0x5C) in v
values.Add(v)
return values

33 changes: 33 additions & 0 deletions DicomDSL/SLMacro.boo
@@ -0,0 +1,33 @@
namespace DicomDSL

import System
import Boo.Lang.Compiler.Ast

final class SignedLongMacro(TagMacro):
"""Description of SLMacro"""
public def constructor():
pass

public static final error_msg = "The tag values must be positive or negative integers"

VR:
get: return "SL"

private def AssertValueIsLong(node as Expression):
raise TagException(node.LexicalInfo, error_msg) if node.NodeType != NodeType.IntegerLiteralExpression

def ReadTagValues(data_arguments as ExpressionCollection):
# This can't actually return its values as a string because it needs to be serialized as an integer"
values = List[of string](data_arguments.Count)
for arg in data_arguments:
if arg.NodeType == NodeType.UnaryExpression:
expr = arg as UnaryExpression
raise TagException(arg.LexicalInfo, error_msg) if expr.Operator != UnaryOperatorType.UnaryNegation
AssertValueIsLong(expr.Operand)
v = -(expr.Operand as IntegerLiteralExpression).Value
else:
AssertValueIsLong(arg)
v = (arg as IntegerLiteralExpression).Value
values.Add(v.ToString())
return values

12 changes: 12 additions & 0 deletions DicomDSL/SQMacro.boo
@@ -0,0 +1,12 @@
namespace DicomDSL

import System
import System.Collections.Generic

# This will have a child macro called SequenceItemMacro and the tags will be nested below this.
# Tags pass TagNode up to SequenceItem, SequenceItem passes TagNode collection up to Sequence, Sequence passes the whole thing up to Dicom Macro
macro SQ:
all_tags = self.__macro["tags"] as IEnumerable[of KeyValuePair[of uint, byte]]
for tag in all_tags:
print "$tag.Key : $tag.Value"

0 comments on commit c698bd6

Please sign in to comment.