Advertisement
Guest User

Firefish5000 CronParserGrammar

a guest
Sep 4th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 2.00 KB | None | 0 0
  1. #!/usr/bin/perl6
  2. use v6;
  3.  
  4. my $CronFile = q:to/HERECRON/;
  5. # &  -  classic cron syntax
  6. # @  -  frequency or timespan (every 30 minutes; with options: best moment within every 30 minutes)
  7. !bootrun(false)
  8.  
  9. # Get Up
  10. #&mail(no) 00 14 * * 0,2,4-6  export DISPLAY=:0 && bash "/home/beck/Scripts/Justin.sh" 'Wake Up From 12:00 Nap (2:00)'
  11. #&mail(no) 00 10 * * 0-6  export DISPLAY=:0 && bash "/home/beck/Scripts/Justin.sh" 'Asa Dai Yo (6:00)'
  12. &mail(no) 58 4 25-31 8 2,4  export DISPLAY=:0 && amixer sset Master '50%'
  13. &mail(no) 58 4 * 9-12 2,4  export DISPLAY=:0 && amixer sset Master '50%'
  14. &mail(no) 00 5 25-31 8 2,4  export DISPLAY=:0 && bash "/home/beck/Scripts/Justin.sh" 'School At 6:00  (Leave by 5:45) (5:00)'
  15. &mail(no) 00 5 * 9-12 2,4  export DISPLAY=:0 && bash "/home/beck/Scripts/Justin.sh" 'School At 6:00  (Leave by 5:45) (5:00)'
  16. HERECRON
  17.  
  18. grammar Cron::Gram {
  19.     token Min { <TimeA> }
  20.     token Hr { <TimeA> }
  21.     token Dow { <TimeA> }
  22.     token Day { <TimeA> }
  23.     token Month { <TimeA> }
  24.     token Yr { <TimeA> }
  25.     token Unparse { # FIXME This should only be used durring testing, Never published.
  26.         (\N+) {say "FAILED TO PARSE--<<$0>>"}
  27.     }
  28.     token CronVar {
  29.         ( <[ \! \% ]> <Word>)
  30.     }
  31.     token CronArg {
  32.         (  \&  <Word>?)
  33.     }
  34.     token Cmd {
  35.         <Word> [\h+<Word>]+
  36.     }
  37.     token Word {
  38.         [  <Literal>
  39.         || <Quote>
  40.         || <-[#]> & \S]+
  41.     }
  42.     token Literal {
  43.         \\ \N
  44.     }
  45.     token Quote {
  46.           \' <-[\']>* \'
  47.         | \" <-[\"]>* \"
  48.     }
  49.     token Comment {
  50.         '#' (\N*)
  51.     }
  52.     token User { ... }
  53.    
  54.     token TimeA {
  55.         [<Tnum> ',']* <Tnum>
  56.     }
  57.     token Tnum {
  58.         '*' | [\d+ '-' \d+] | \d+
  59.     }
  60.     token CronJob {
  61.          <CronArg> \s+ <Min> \s+ <Hr> \s+  <Dow> \s+ <Day> \s+ <Month> \s+  <Cmd>
  62.     }
  63.     rule TOP {
  64.         #TODO [ <Comment> || [ <CronJob>||<CronVar> ] \h* \n? || <Unparse> ]+ #Needs to be tested first, Im tired so test with-geld. Note .perl isn't working as expectd.
  65.         [[  <Comment>
  66.         || <CronJob> <Comment>?
  67.         || <CronVar>
  68.         || <Unparse>
  69.         ] \h* \n? ]+
  70.     }
  71. }
  72.  
  73. my $Parsed = Cron::Gram.parse($CronFile);
  74. say $Parsed;
  75. say $Parsed.perl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement