Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for dynamic templates #762

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
Loading