1
###########################################################################/**
2
# @RdocClass RspExpression
3
#
4
# @title "The RspExpression class"
5
#
6
# \description{
7
#  @classhierarchy
8
#
9
#  An RspExpression is an @see RspConstruct of format \code{<\% ... \%>}.
10
# }
11
#
12
# @synopsis
13
#
14
# \arguments{
15
#   \item{object}{A R object.}
16
#   \item{...}{Not used.}
17
# }
18
#
19
# \section{Fields and Methods}{
20
#  @allmethods
21
# }
22
#
23
# @author
24
#
25
# @keyword internal
26
#*/###########################################################################
27
setConstructorS3("RspExpression", function(...) {
28 1
  extend(RspConstruct(...), "RspExpression")
29
})
30

31

32
###########################################################################/**
33
# @RdocClass RspUnparsedExpression
34
#
35
# @title "The RspUnparsedExpression class"
36
#
37
# \description{
38
#  @classhierarchy
39
#
40
#  An RspUnparsedExpression is an @see RspExpression that still has not
41
#  been parsed for its class and content.  After @see "parse":ing such
42
#  an object, the class of this RSP expression will be known.
43
# }
44
#
45
# @synopsis
46
#
47
# \arguments{
48
#   \item{...}{Arguments passed to @see "RspExpression".}
49
# }
50
#
51
# \section{Fields and Methods}{
52
#  @allmethods
53
# }
54
#
55
# @author
56
#
57
# @keyword internal
58
#*/###########################################################################
59
setConstructorS3("RspUnparsedExpression", function(...) {
60 1
  extend(RspExpression(...), "RspUnparsedExpression")
61
})
62

63

64
#########################################################################/**
65
# @RdocMethod parseExpression
66
#
67
# @title "Parses the unknown RSP expression for its class"
68
#
69
# \description{
70
#  @get "title".
71
# }
72
#
73
# @synopsis
74
#
75
# \arguments{
76
#   \item{...}{Not used.}
77
# }
78
#
79
# \value{
80
#  Returns an @see "RspExpression" of known class.
81
# }
82
#
83
# @author
84
#
85
# \seealso{
86
#   @seeclass
87
# }
88
#*/#########################################################################
89
setMethodS3("parseExpression", "RspUnparsedExpression", function(expr, ...) {
90 1
  suffixSpecs <- attr(expr, "suffixSpecs")
91 1
  body <- expr
92

93
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
94
  # RSP Scripting Elements and Variables
95
  #
96
  # <%=[expression]%>
97
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
98 1
  pattern <- "^=(.*)$"
99 1
  if (regexpr(pattern, body) != -1L) {
100 1
    code <- gsub(pattern, "\\1", body)
101 1
    code <- trim(code)
102 1
    res <- RspCodeChunk(code, return=TRUE)
103 1
    attr(res, "suffixSpecs") <- suffixSpecs
104 1
    return(res)
105
  }
106

107
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
108
  # RSP Scripting Elements and Variables
109
  #
110
  # <%:[expression]%>
111
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
112 1
  pattern <- "^:(|[ \t\v]*(\n|\r|\r\n))(.*)$"
113 1
  if (regexpr(pattern, body) != -1L) {
114 0
    code <- gsub(pattern, "\\3", body)
115 0
    res <- RspCode(code, echo=TRUE)
116 0
    attr(res, "suffixSpecs") <- suffixSpecs
117 0
    return(res)
118
  }
119

120
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
121
  # RSP Scripting Elements and Variables
122
  #
123
  # <% [expressions] %>
124
  #
125
  # This applies to anything not recognized above.
126
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127 1
  res <- RspCode(trim(body))
128 1
  attr(res, "suffixSpecs") <- suffixSpecs
129 1
  res
130
})

Read our documentation on viewing source code .

Loading