Comments (3)
More banging on PEG.js reveals a pretty powerful parser for these cases:
/* test for CAP DSL */
/* currently parsing works, but no results generated */
/* Javascript goes inside the {} */
Expression
= Spacing Rule+ EndOfFile
Rule
/* define specific rules for the activity types */
= head:ExamActivity _ tail:Timing Spacing {
return head + ':' + tail;
}
/ activity:MoodleQuizActivity _ opens:MoodleQuizOpenTime _ closes:MoodleQuizCloseTime Spacing {
return activity + ':\n opens:' + opens + ',\n closes: ' + closes;
}
/ activity:MoodleHomeworkActivity _ opens:MoodleHomeworkAllowSubmissionsTime _ due:MoodleHomeworkDueTime _ cutoff:MoodleHomeworkCutoffTime Spacing {
return activity + ':\n allow submissions after:' + opens + ',\n due date: ' + due + ',\n cutoff date: ' + cutoff;
}
ExamActivity
= head:EXAM_ACTIVITY_CODE tail:Integer {
return head + tail;
}
MoodleQuizActivity
= head:MOODLE_QUIZ_ACTIVITY_CODE tail:Integer {
return head + tail;
}
MoodleQuizOpenTime "Moodle Quiz Open Time" = Timing
MoodleQuizCloseTime "Moodle Quiz Close Time" = Timing
MoodleHomeworkActivity
= head:MOODLE_HOMEWORK_ACTIVITY_CODE tail:Integer {
return head + tail;
}
MoodleHomeworkAllowSubmissionsTime "Moodle Homework Allow Submissions Time" = Timing
MoodleHomeworkDueTime "Moodle Homework Due Time" = Timing
MoodleHomeworkCutoffTime "Moodle Homework Cutoff Time" = Timing
Activity "Activity Number (e.g., E1 for Exam 1)"
= head:ActivityCode tail:Integer {
return head + tail;
}
Timing
/* Case for Session, Labs, Practica */
= head:MeetingSequence tail:TimeModifier? {
var result = head, i;
if (tail !== null) {
for (i=0; i<tail.length; i++) {
result += tail[i];
}
}
return result;
}
ActivityCode
= code:(EXAM_ACTIVITY_CODE / MOODLE_QUIZ_ACTIVITY_CODE / MOODLE_HOMEWORK_ACTIVITY_CODE) { return code; }
MeetingSequence "Meeting Number (e.g., S2 for Seminar 2)"
= meeting:(SEMINAR_MEETING / LABORATORY_MEETING / PRACTICUM_MEETING) number:Integer { return meeting + ' ' + number}
TimeModifier
= time:(MEETING_START / MEETING_END) adjust:((('-'/'+') DeltaTime) ('@' HHMM)?)?
DeltaTime
= Integer ('m' / 'h' / 'd' / 'w')
/* http://stackoverflow.com/a/20123018/1168342 -- except the order is different in PEG (first match) and there's a bug with the ? between [0-1]?[0-9] */
HHMM
= ([2][0-3] / [0-1]?[0-9] / [0-9]) ':' [0-5][0-9] { return text() }
Integer "integer"
= [0-9]+ { return parseInt(text(), 10); }
_ "whitespace"
= [ \t]*
EXAM_ACTIVITY_CODE
= EXAM_ACTIVITY_CODE:'E' { return "Exam "}
MOODLE_QUIZ_ACTIVITY_CODE
= 'Q' { return "Moodle Quiz "}
MOODLE_HOMEWORK_ACTIVITY_CODE
= 'H' { return "Moodle Homework "}
SEMINAR_MEETING
= 'S' {return 'Seminar'; }
LABORATORY_MEETING
= 'L' {return 'Laboratory'; }
PRACTICUM_MEETING
= 'P' {return 'Practicum'; }
MEETING_START
= 'S' {return '(start)'; }
MEETING_END
= 'F' {return '(end)'; }
Spacing
= (Space / Comment)*
Comment
= '#' (!EndOfLine .)* EndOfLine { return 'comment';}
Space
= ' ' / '\t' / EndOfLine
EndOfLine
= '\r\n' / '\n' / '\r'
EndOfFile
= !. { return "EOF"; }
Here's the sample it parses:
# here's a comment
E1 S2
Q1 S1F S2S-30m
H1 L2F L3S-1d@23:55 L3S-1d@23:55
and the resulting output:
[
[
"comment"
],
[
"Exam 1:Seminar 2",
"Moodle Quiz 1:
opens:Seminar 1(end)null,
closes: Seminar 2(start)-,30,m,",
"Moodle Homework 1:
allow submissions after:Laboratory 2(end)null,
due date: Laboratory 3(start)-,1,d,@,23:55,
cutoff date: Laboratory 3(start)-,1,d,@,23:55"
],
"EOF"
]
Also, error messages are somewhat automatic. For example, leaving off the 3rd date for the H1 line (it requires 3 dates), I get the following error message:
Line 4, column 21: Expected Moodle Homework Cutoff Time but end of input found.
from course-activity-planner.
As for python solutions with PEG, the documentation for https://github.com/erikrose/parsimonious looks good.
from course-activity-planner.
Good reference for PEG is the research paper : http://www.brynosaurus.com/pub/lang/peg.pdf
from course-activity-planner.
Related Issues (20)
- US2 - Create relative planning HOT 1
- US3 - Apply a relative planning to a moodle course
- US4 - Create a relative planning from an old moodle course
- Support both languages in calendar parser
- Support other timezones than 'America/Montreal'
- Let user upload multiple ICS for multiple groups
- Errored plannings are listed
- Saved planning should only save the text of the planning
- Exams should be defined by one date HOT 1
- Simplify GUI for final steps HOT 1
- Multiple digit delta for days incorrectly parsed
- Use icon (favicon)
- Updated MBZ should have course info in file name
- Include the Moodle File activity?
- Délivrer un programme permettant de parser un document XML provenant de Moodle. HOT 1
- Ajouter au programme une fonction pour changer les valeurs des dates des activités Moodle. Créer le nouveau fichier XML. HOT 1
- Première ébauche de l'architecture du logiciel HOT 1
- Syntaxe pour la configuration des délais pour les dates d'ouverture et de fermeture d'une activité HOT 2
- US2 - Upload MBZ file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from course-activity-planner.