// Create looks for identifier in symboltable and creates a pointer if missing. func (s *SymbolTable) Create(q *ast.QuestionNode) { identifier := q.Identifier() label := q.Label() qType := q.Type() pos := q.Pos() primitive := q.Primitive() _, ok := s.symbolExistP(identifier) if ok { s.appendErrf("%s:symboltable error: duplicated identifier found at symbol table: %s", pos, identifier) return } var symbol interface{} switch qType { case ast.ScalarQuestionType: newSymbol, err := scalarQuestionFactory(primitive) if err != nil { s.appendErrf("%s:symboltable error: %s", pos, err.Error()) } symbol = newSymbol case ast.ComputedQuestionType: symbol = new(ComputedQuestion) } s.upsert(identifier, symbol) s.detectRepeatedLabel(identifier, label) }
// QuestionNode adds question to symbol table, and dispatch to frontend // rendering. func (exec Execute) QuestionNode(q *ast.QuestionNode) { exec.symboltable.Create(q) r := exec.symboltable.Read(q.Identifier()) if q.Type() == ast.ComputedQuestionType { expr := q.Content().(*ast.ComputedQuestion).Expression() r.(symboltable.StringParser).From( exec.resolveExpressionIntoString(expr), ) } exec.toFrontend <- &plumbing.Frontend{ Type: plumbing.UpdateQuestion, Identifier: q.Identifier(), Label: q.Label(), Value: r.(fmt.Stringer).String(), } }
// QuestionNode adds question to symbol table, and dispatch to frontend // rendering. func (d Draw) QuestionNode(q *ast.QuestionNode) { qcpy := q.Clone() visible := plumbing.Hidden if 0 == d.nest { visible = plumbing.Visible } ftyp := "" if qcpy.Type() == ast.ScalarQuestionType { ftyp = qcpy.Primitive() } d.toFrontend <- &plumbing.Frontend{ Type: plumbing.DrawQuestion, Identifier: qcpy.Identifier(), Label: qcpy.Label(), FieldType: ftyp, Visible: visible, } }