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
start
= sections:(StringResponse / NumericalResponse / MultipleChoice / Paragraph / PreservedLinebreaks)+
= sections:(Image /
NumericalOrStringResponse /
StudentProducedResponseIdentifier
NumericalResponse /
= '='
MultipleChoice /
Paragraph /
PreservedLinebreaks)+
/* Image */
ImageLink
= DoubleQuotedString
/ chars:( (!')' [^\n])+)
{
return $.trim(chars.map(function(element) { return element[1]; }).join(""));
}
NumericalToleranceValueType
ImageTitle
= decimal / percentage / integer
= chars:( !'(' [^\n\[\]] )+
{
return $.trim(chars.map(function(element) { return element[1]; }).join(""));
}
NumericalToleranc
e
Imag
e
=
'+-' OptionalSpaces value:NumericalToleranceValueType OptionalSpaces
=
ImageIdentifier title:ImageTitle? OptionalSpaces '(' OptionalSpaces url:ImageLink ')' OptionalSpaces Linebreak
{
{
return
value
;
return
{'type': 'image', 'url': url, 'title': title}
;
}
}
NumericalResponse
/* First character in a line as identifier */
= StudentProducedResponseIdentifier OptionalSpaces '(' OptionalSpaces value:NumericalValue OptionalSpaces tolerance:NumericalTolerance? ')' OptionalSpaces Linebreak
ChoiceIdentifier
= '(' parenthesized:[x ]? ')'
{
{
if (tolerance == "")
return parenthesized == 'x';
tolerance = "5%"
return {'type': 'numerical', 'answer': value, 'tolerance': tolerance};
}
}
ImageIdentifier
= '!'
StudentProducedResponseIdentifier
= '='
/* StringResponse */
StringResponse
StringResponse
= StudentProducedResponseIdentifier OptionalSpaces !'(' value:Text Linebreak
= StudentProducedResponseIdentifier OptionalSpaces !'(' value:Text Linebreak
{
{
return {'type': 'string', 'answer': $.trim(value)};
return {'type': 'string', 'answer': $.trim(value)};
}
}
/* MultipleChoice */
NumericalOrStringResponse
ChoiceIdentifier
= StudentProducedResponseIdentifier OptionalSpaces value:NumericalValue OptionalSpaces tolerance:NumericalTolerance? OptionalSpaces Linebreak
= '(' parenthesized:[x ]? ')'
{
{
return parenthesized == 'x';
if (tolerance == "")
tolerance = "5%"
return {'type': 'numerical', 'answer': value, 'tolerance': tolerance};
}
}
/ StringResponse
/* MultipleChoice */
ChoiceTextLine
ChoiceTextLine
= !ChoiceIdentifier line:Line
= !ChoiceIdentifier line:Line
...
@@ -52,10 +78,10 @@ MultipleChoice
...
@@ -52,10 +78,10 @@ MultipleChoice
return {'type': 'multiple_choice', 'choices': choices};
return {'type': 'multiple_choice', 'choices': choices};
}
}
/* Paragraph */
/* Paragraph */
ParagraphTextLine
ParagraphTextLine
= !ChoiceIdentifier !StudentProducedResponseIdentifier line:Line
= !
ImageIdentifier !
ChoiceIdentifier !StudentProducedResponseIdentifier line:Line
{
{
return line;
return line;
}
}
...
@@ -67,6 +93,7 @@ Paragraph
...
@@ -67,6 +93,7 @@ Paragraph
}
}
/* Base symbols */
/* Base symbols */
Line
Line
= text:Text terminator:Linebreak
= text:Text terminator:Linebreak
{
{
...
@@ -79,8 +106,11 @@ Text
...
@@ -79,8 +106,11 @@ Text
return chars.join("");
return chars.join("");
}
}
OptionalSpacesAndLines
= (' ' / '\n' / '\t')*
OptionalSpaces
OptionalSpaces
=
' '
*
=
(' ' / '\t')
*
PreservedLinebreaks
PreservedLinebreaks
= terminators:('\n')+
= terminators:('\n')+
...
@@ -91,10 +121,45 @@ PreservedLinebreaks
...
@@ -91,10 +121,45 @@ PreservedLinebreaks
Linebreak
Linebreak
= ('\n')
= ('\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
NumericalValue
= additive
= additive
/* Mathematical rules */
/* Mathematical rules */
additive
additive
= left:multiplicative "+" right:additive { return left + right; }
= left:multiplicative "+" right:additive { return left + right; }
/ 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"
>
<section
class=
"capa-edit"
>
<div
class=
"parser-message-box"
style=
"display:none;"
>
Input parsed successfully.
</div>
<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 source-box"
rows=
"8"
cols=
"40"
></textarea>
<textarea
name=
""
class=
"edit-box capa-box"
rows=
"8"
cols=
"40"
>
${data}
</textarea>
<textarea
name=
""
class=
"edit-box capa-box"
rows=
"8"
cols=
"40"
>
${data}
</textarea>
</section>
</section>
common/lib/capa/capa/responsetypes.py
View file @
75eca718
...
@@ -1179,10 +1179,10 @@ class FormulaResponse(LoncapaResponse):
...
@@ -1179,10 +1179,10 @@ class FormulaResponse(LoncapaResponse):
value
=
random
.
uniform
(
*
ranges
[
var
])
value
=
random
.
uniform
(
*
ranges
[
var
])
instructor_variables
[
str
(
var
)]
=
value
instructor_variables
[
str
(
var
)]
=
value
student_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
)
instructor_result
=
evaluator
(
instructor_variables
,
dict
(),
expected
,
cs
=
self
.
case_sensitive
)
try
:
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
,
student_result
=
evaluator
(
student_variables
,
dict
(),
dict
(),
given
,
given
,
...
...
common/lib/xmodule/xmodule/capa_module.py
View file @
75eca718
...
@@ -446,6 +446,8 @@ class CapaModule(XModule):
...
@@ -446,6 +446,8 @@ class CapaModule(XModule):
try
:
try
:
old_state
=
self
.
lcp
.
get_state
()
old_state
=
self
.
lcp
.
get_state
()
lcp_id
=
self
.
lcp
.
problem_id
lcp_id
=
self
.
lcp
.
problem_id
import
pdb
pdb
.
set_trace
()
correct_map
=
self
.
lcp
.
grade_answers
(
answers
)
correct_map
=
self
.
lcp
.
grade_answers
(
answers
)
except
StudentInputError
as
inst
:
except
StudentInputError
as
inst
:
# TODO (vshnayder): why is this line here?
# 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
...
@@ -10,7 +10,7 @@ class @CapaDescriptor
save
:
->
@
edit_box
.
val
()
save
:
->
@
edit_box
.
val
()
buildParser
:
->
buildParser
:
->
$
.
get
"/static/grammar.jspeg"
,
(
data
)
=>
$
.
get
"/static/grammar
s/main
.jspeg"
,
(
data
)
=>
@
grammar
=
data
@
grammar
=
data
@
parser
=
PEG
.
buildParser
@
grammar
@
parser
=
PEG
.
buildParser
@
grammar
,
"text"
,
"text"
...
@@ -56,6 +56,17 @@ class @CapaDescriptor
...
@@ -56,6 +56,17 @@ class @CapaDescriptor
newel
=
create_text_element
(
section
.
text
)
newel
=
create_text_element
(
section
.
text
)
problem
.
append
(
newel
)
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'
else
if
section
.
type
==
'linebreaks'
text
=
create_text_element
(
''
)
text
=
create_text_element
(
''
)
for
i
in
[
0
..
section
.
count
]
by
1
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