Skip to content

Commit

Permalink
Support for dynamic templates
Browse files Browse the repository at this point in the history
  • Loading branch information
kmichaelk committed Sep 23, 2024
1 parent 8c7932e commit 3bf75a7
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ttcn3/syntax/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ type (
X Expr // Template expression
}

// A DynamicExpr represents a "@dynamic" expression.
DynamicExpr struct {
Tok Token // Position of "dynamic"
Body *BlockStmt // Template body
}

// A DefKindExpr represents a definition kind expression, used by imports
// and with-attributes.
DefKindExpr struct {
Expand Down Expand Up @@ -360,6 +366,7 @@ func (x *RegexpExpr) exprNode() {}
func (x *PatternExpr) exprNode() {}
func (x *DecmatchExpr) exprNode() {}
func (x *DecodedExpr) exprNode() {}
func (x *DynamicExpr) exprNode() {}
func (x *DefKindExpr) exprNode() {}
func (x *ExceptExpr) exprNode() {}

Expand Down
67 changes: 67 additions & 0 deletions ttcn3/syntax/nodes_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions ttcn3/syntax/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,10 @@ func (p *parser) parseOperand() Expr {
return p.parseCallDecmatch()

case MODIF:
return p.parseDecodedModifier()
return p.parseModifier()

case VALUE:
return p.parseIdent()

default:
p.errorExpected("operand")
Expand Down Expand Up @@ -897,6 +900,13 @@ func (p *parser) parseCallDecmatch() *DecmatchExpr {
return c
}

func (p *parser) parseModifier() Expr {
if p.peek(1).String() == "@dynamic" {
return p.parseDynamicModifier()
}
return p.parseDecodedModifier()
}

func (p *parser) parseDecodedModifier() *DecodedExpr {
d := new(DecodedExpr)
d.Tok = p.expect(MODIF)
Expand All @@ -911,6 +921,13 @@ func (p *parser) parseDecodedModifier() *DecodedExpr {
return d
}

func (p *parser) parseDynamicModifier() *DynamicExpr {
d := new(DynamicExpr)
d.Tok = p.expect(MODIF)
d.Body = p.parseBlockStmt()
return d
}

func (p *parser) parseSelectorExpr(x Expr) *SelectorExpr {
return &SelectorExpr{X: x, Dot: p.consume(), Sel: p.parseRef()}
}
Expand Down Expand Up @@ -1015,7 +1032,7 @@ func (p *parser) parseIdent() *Ident {
switch p.tok {
case UNIVERSAL:
return p.parseUniversalCharstring()
case IDENT, ADDRESS, ALIVE, CHARSTRING, CONTROL, TO, FROM, CREATE:
case IDENT, ADDRESS, ALIVE, CHARSTRING, CONTROL, TO, FROM, CREATE, VALUE:
return p.make_use(p.consume())
default:
p.expect(IDENT) // use expect() error handling
Expand Down

0 comments on commit 3bf75a7

Please sign in to comment.