Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
75eca718
Commit
75eca718
authored
Jul 31, 2012
by
Mike Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added image and moved everything to grammars folder
parent
386aa43e
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
242 additions
and
25 deletions
+242
-25
cms/static/grammars/main.jspeg
+86
-21
cms/static/grammars/peg-0.7.0.min.js
+0
-0
cms/static/grammars/xml-validator.js
+65
-0
cms/static/grammars/xmltag.jspeg
+73
-0
cms/templates/widgets/capa-edit.html
+2
-1
common/lib/capa/capa/responsetypes.py
+2
-2
common/lib/xmodule/xmodule/capa_module.py
+2
-0
common/lib/xmodule/xmodule/js/src/capa/edit.coffee
+12
-1
No files found.
cms/static/grammar.jspeg
→
cms/static/grammar
s/main
.jspeg
View file @
75eca718
start
= sections:(StringResponse / NumericalResponse / MultipleChoice / Paragraph / PreservedLinebreaks)+
StudentProducedResponseIdentifier
= '='
= sections:(Image /
NumericalOrStringResponse /
NumericalResponse /
MultipleChoice /
Paragraph /
PreservedLinebreaks)+
/* Image */
ImageLink
= DoubleQuotedString
/ chars:( (!')' [^\n])+)
{
return $.trim(chars.map(function(element) { return element[1]; }).join(""));
}
NumericalToleranceValueType
= decimal / percentage / integer
ImageTitle
= chars:( !'(' [^\n\[\]] )+
{
return $.trim(chars.map(function(element) { return element[1]; }).join(""));
}
NumericalToleranc
e
=
'+-' OptionalSpaces value:NumericalToleranceValueType OptionalSpaces
Imag
e
=
ImageIdentifier title:ImageTitle? OptionalSpaces '(' OptionalSpaces url:ImageLink ')' OptionalSpaces Linebreak
{
return
value
;
return
{'type': 'image', 'url': url, 'title': title}
;
}
NumericalResponse
= StudentProducedResponseIdentifier OptionalSpaces '(' OptionalSpaces value:NumericalValue OptionalSpaces tolerance:NumericalTolerance? ')' OptionalSpaces Linebreak
/* First character in a line as identifier */
ChoiceIdentifier
= '(' parenthesized:[x ]? ')'
{
if (tolerance == "")
tolerance = "5%"
return {'type': 'numerical', 'answer': value, 'tolerance': tolerance};
return parenthesized == 'x';
}
ImageIdentifier
= '!'
StudentProducedResponseIdentifier
= '='
/* StringResponse */
StringResponse
= StudentProducedResponseIdentifier OptionalSpaces !'(' value:Text Linebreak
{
return {'type': 'string', 'answer': $.trim(value)};
}
/* MultipleChoice */
ChoiceIdentifier
= '(' parenthesized:[x ]? ')'
NumericalOrStringResponse
= StudentProducedResponseIdentifier OptionalSpaces value:NumericalValue OptionalSpaces tolerance:NumericalTolerance? OptionalSpaces Linebreak
{
return parenthesized == 'x';
if (tolerance == "")
tolerance = "5%"
return {'type': 'numerical', 'answer': value, 'tolerance': tolerance};
}
/ StringResponse
/* MultipleChoice */
ChoiceTextLine
= !ChoiceIdentifier line:Line
...
...
@@ -52,10 +78,10 @@ MultipleChoice
return {'type': 'multiple_choice', 'choices': choices};
}
/* Paragraph */
ParagraphTextLine
= !ChoiceIdentifier !StudentProducedResponseIdentifier line:Line
= !
ImageIdentifier !
ChoiceIdentifier !StudentProducedResponseIdentifier line:Line
{
return line;
}
...
...
@@ -67,6 +93,7 @@ Paragraph
}
/* Base symbols */
Line
= text:Text terminator:Linebreak
{
...
...
@@ -79,8 +106,11 @@ Text
return chars.join("");
}
OptionalSpacesAndLines
= (' ' / '\n' / '\t')*
OptionalSpaces
=
' '
*
=
(' ' / '\t')
*
PreservedLinebreaks
= terminators:('\n')+
...
...
@@ -91,10 +121,45 @@ PreservedLinebreaks
Linebreak
= ('\n')
DoubleQuotedString
= "\"\"" { return ""; }
/ "\"" str:(!UnescapedQuote .)* last:UnescapedQuote {
return str.map(function(element) { return element[1]; }).join("") + last;
}
UnescapedQuote
= last:[^\\] "\"" {return last;}
AlphanumericalText
= chars:[a-zA-Z0-9]+
{
return chars.join("");
}
/* NumericalResponse */
NumericalToleranceValueType
= decimal / percentage / integer
NumericalTolerance
= '+-' OptionalSpaces value:NumericalToleranceValueType OptionalSpaces
{
return value;
}
NumericalResponse
= StudentProducedResponseIdentifier OptionalSpaces '(' OptionalSpaces value:NumericalValue OptionalSpaces tolerance:NumericalTolerance? ')' OptionalSpaces Linebreak
{
if (tolerance == "")
tolerance = "5%"
return {'type': 'numerical', 'answer': value, 'tolerance': tolerance};
}
NumericalValue
= additive
/* Mathematical rules */
additive
= left:multiplicative "+" right:additive { return left + right; }
/ left:multiplicative "-" right:additive { return left - right; }
...
...
cms/static/
js/vendor
/peg-0.7.0.min.js
→
cms/static/
grammars
/peg-0.7.0.min.js
View file @
75eca718
File moved
cms/static/grammars/xml-validator.js
0 → 100644
View file @
75eca718
/*
1. Stealed from W3Schools XML Validator <www.w3schools.com/xml/xml_validator.asp>
2. Beautified with jsbeautifier.org
3. Feed in XML string and use return instead of alert.
*/
var
xt
=
""
,
h3OK
=
1
;
function
checkErrorXML
(
x
)
{
xt
=
""
;
h3OK
=
1
;
checkXML
(
x
);
}
function
checkXML
(
n
)
{
var
l
,
i
,
nam
;
nam
=
n
.
nodeName
;
if
(
nam
==
"h3"
)
{
if
(
h3OK
==
0
)
{
return
;
}
h3OK
=
0
}
if
(
nam
==
"#text"
)
{
xt
=
xt
+
n
.
nodeValue
+
"
\
n"
}
l
=
n
.
childNodes
.
length
for
(
i
=
0
;
i
<
l
;
i
++
)
{
checkXML
(
n
.
childNodes
[
i
])
}
}
function
validateXML
(
txt
)
{
// code for IE
console
.
log
(
txt
);
if
(
window
.
ActiveXObject
)
{
var
xmlDoc
=
new
ActiveXObject
(
"Microsoft.XMLDOM"
);
xmlDoc
.
async
=
false
;
xmlDoc
.
loadXML
(
txt
);
if
(
xmlDoc
.
parseError
.
errorCode
!=
0
)
{
txt
=
"Error Code: "
+
xmlDoc
.
parseError
.
errorCode
+
"
\
n"
;
txt
=
txt
+
"Error Reason: "
+
xmlDoc
.
parseError
.
reason
;
txt
=
txt
+
"Error Line: "
+
xmlDoc
.
parseError
.
line
;
return
false
;
}
else
{
return
true
;
}
}
// code for Mozilla, Firefox, Opera, etc.
else
if
(
document
.
implementation
.
createDocument
)
{
var
parser
=
new
DOMParser
();
var
xmlDoc
=
parser
.
parseFromString
(
txt
,
"text/xml"
);
if
(
xmlDoc
.
getElementsByTagName
(
"parsererror"
).
length
>
0
)
{
checkErrorXML
(
xmlDoc
.
getElementsByTagName
(
"parsererror"
)[
0
]);
return
false
;
}
else
{
return
true
;
}
}
else
{
}
}
\ No newline at end of file
cms/static/grammars/xmltag.jspeg
0 → 100644
View file @
75eca718
start
= XMLRootElement
XMLComment
= '<!--' chars:(!'-->' .)+ '-->'
{
return '<!--' + chars.map(function(element) { return element[1]; }).join("") + '-->'
}
XMLAttribute
= attr:AlphanumericalText s1:OptionalSpaces '=' s2:OptionalSpaces value:DoubleQuotedString
{
return attr + '=' + "\"" value.replace("\"", "\\"") + "\""
}
XMLTagOpen
= '<' OptionalSpaces name:AlphanumericalText OptionalSpaces attrs:(XMLAttribute / ' ')* OptionalSpaces '>'
{
tag = '<' + name;
if (attrs.length)
tag += ' ' + attrs.join("");
tag += '>';
return tag;
}
XMLTagClose
= '<' OptionalSpaces '/' OptionalSpaces name:AlphanumericalText OptionalSpaces '>'
{
return '</' + name + '>'
}
XMLTagEmpty
= '<' OptionalSpaces name:AlphanumericalText OptionalSpaces attrs:(XMLAttribute / ' ')* OptionalSpaces '/>'
{
tag = '<' + name;
if (attrs.length)
tag += ' ' + attrs.join("");
tag += '/>';
return tag;
}
XMLElement
= chars:((!'>' !'<' .)+)
{
return chars.map(function(element) { return element[2]; }).join("");
}
/ XMLRootElement
XMLRootElement
= XMLTagEmpty
/ open:XMLTagOpen children:(XMLElement+) close:XMLTagClose
{
return open + children.join("") + close;
}
/ XMLTagOpen XMLTagClose
{
return open + close;
}
/ XMLComment
OptionalSpaces
= ' '*
DoubleQuotedString
= "\"\"" { return ""; }
/ "\"" str:(!UnescapedQuote .)* last:UnescapedQuote {
return str.map(function(element) { return element[1]; }).join("") + last;
}
UnescapedQuote
= last:[^\\] "\"" {return last;}
cms/templates/widgets/capa-edit.html
View file @
75eca718
<section
class=
"capa-edit"
>
<div
class=
"parser-message-box"
style=
"display:none;"
>
Input parsed successfully.
</div>
<script
type=
"text/javascript"
src=
"/static/js/vendor/peg-0.7.0.min.js"
></script>
<script
type=
"text/javascript"
src=
"/static/grammars/xml-validator.js"
></script>
<script
type=
"text/javascript"
src=
"/static/grammars/peg-0.7.0.min.js"
></script>
<textarea
name=
""
class=
"edit-box source-box"
rows=
"8"
cols=
"40"
></textarea>
<textarea
name=
""
class=
"edit-box capa-box"
rows=
"8"
cols=
"40"
>
${data}
</textarea>
</section>
common/lib/capa/capa/responsetypes.py
View file @
75eca718
...
...
@@ -1179,10 +1179,10 @@ class FormulaResponse(LoncapaResponse):
value
=
random
.
uniform
(
*
ranges
[
var
])
instructor_variables
[
str
(
var
)]
=
value
student_variables
[
str
(
var
)]
=
value
#
log.debug('formula: instructor_vars=%s, expected=%s' % (instructor_variables,expected))
log
.
debug
(
'formula: instructor_vars=
%
s, expected=
%
s'
%
(
instructor_variables
,
expected
))
instructor_result
=
evaluator
(
instructor_variables
,
dict
(),
expected
,
cs
=
self
.
case_sensitive
)
try
:
#
log.debug('formula: student_vars=%s, given=%s' % (student_variables,given))
log
.
debug
(
'formula: student_vars=
%
s, given=
%
s'
%
(
student_variables
,
given
))
student_result
=
evaluator
(
student_variables
,
dict
(),
given
,
...
...
common/lib/xmodule/xmodule/capa_module.py
View file @
75eca718
...
...
@@ -446,6 +446,8 @@ class CapaModule(XModule):
try
:
old_state
=
self
.
lcp
.
get_state
()
lcp_id
=
self
.
lcp
.
problem_id
import
pdb
pdb
.
set_trace
()
correct_map
=
self
.
lcp
.
grade_answers
(
answers
)
except
StudentInputError
as
inst
:
# TODO (vshnayder): why is this line here?
...
...
common/lib/xmodule/xmodule/js/src/capa/edit.coffee
View file @
75eca718
...
...
@@ -10,7 +10,7 @@ class @CapaDescriptor
save
:
->
@
edit_box
.
val
()
buildParser
:
->
$
.
get
"/static/grammar.jspeg"
,
(
data
)
=>
$
.
get
"/static/grammar
s/main
.jspeg"
,
(
data
)
=>
@
grammar
=
data
@
parser
=
PEG
.
buildParser
@
grammar
,
"text"
...
...
@@ -56,6 +56,17 @@ class @CapaDescriptor
newel
=
create_text_element
(
section
.
text
)
problem
.
append
(
newel
)
else
if
section
.
type
==
'image'
center
=
$
(
doc
.
createElement
(
'center'
))
img
=
$
(
doc
.
createElement
(
'img'
))
img
.
attr
'src'
,
section
.
url
center
.
append
img
if
section
.
title
title
=
create_text_element
(
section
.
title
)
center
.
append
doc
.
createElement
(
'br'
)
center
.
append
title
problem
.
append
center
else
if
section
.
type
==
'linebreaks'
text
=
create_text_element
(
''
)
for
i
in
[
0
..
section
.
count
]
by
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment