playfair

Playfair Script Formatter
git clone https://git.stjo.hn/playfair
Log | Files | Refs | README | LICENSE

script.pl (3338B)


      1 % Parse a Playfair-style script into its components parts.
      2 script(parsed_script(Type, Variables, Scenes)) -->
      3 	script_head(Variables),
      4 	newline, newline,
      5 	script_play(Type, Scenes),
      6 	newline.
      7 
      8 
      9 script_play(Type, Scenes) -->
     10 	script_scene_repeater(Type, Scenes),
     11 	script_end.
     12 
     13 
     14 script_scene_repeater(_, []) --> [].
     15 	
     16 script_scene_repeater(Type, [Scene|Scenes]) -->
     17 	script_scene(Type, Scene),
     18 	script_scene_repeater(Type, Scenes).
     19 
     20 
     21 % Scene definition for stage plays
     22 script_scene(stage, scene(Act, SceneDirections, Island)) -->
     23 	script_act(Act),
     24 	newline, newline,
     25 	script_scene_directions(SceneDirections),
     26 	newline, newline,
     27 	script_island_repeater(Island).
     28 
     29 % Scene definition for screenplays
     30 script_scene(screen, scene(Slug, null, Island)) -->
     31 	script_slug(Slug),
     32 	newline, newline,
     33 	script_island_repeater(Island).
     34 
     35 
     36 script_island_repeater([]) --> [].
     37 
     38 script_island_repeater([Island|Rest]) -->
     39 	script_island(Island),
     40 	newline,
     41 	script_island_repeater(Rest).
     42 
     43 
     44 script_island(stage_directions(StageDirections)) -->
     45 	script_stage_directions(StageDirections),
     46 	newline.
     47 
     48 script_island(character_dialogue(Character, Dialogue)) -->
     49 	script_character(Character),
     50 	newline,
     51 	script_dialogue_combo(Dialogue).
     52 
     53 
     54 script_scene_directions([Text]) --> text("\n<", Text).
     55 
     56 script_scene_directions([Text|SceneDirections]) -->
     57 	text("\n<", Text),
     58 	script_line_breaks(_),
     59 	scene_directions(SceneDirections).
     60 
     61 
     62 script_stage_directions(Text) --> text("\n", Text).
     63 
     64 
     65 script_character(Text) --> text("\n", Text).
     66 
     67 
     68 script_dialogue_combo([]) --> [].
     69 
     70 script_dialogue_combo([character_stage_directions(Directions)|Rest]) -->
     71 	script_character_stage_directions(Directions),
     72 	newline,
     73 	script_dialogue_combo(Rest).
     74 
     75 script_dialogue_combo([dialogue(Dialogue)|Rest]) -->
     76 	script_dialogue(Dialogue),
     77 	newline,
     78 	script_dialogue_combo(Rest).
     79 
     80 
     81 script_dialogue([]) --> [].
     82 
     83 script_dialogue([Unit|Rest]) -->
     84 	script_dialogue_unit(Unit),
     85 	script_dialogue(Rest).
     86 
     87 
     88 script_dialogue_unit(emphatic(Emphatic)) --> script_emphatic(Emphatic).
     89 
     90 script_dialogue_unit(break(Break)) --> script_line_breaks(Break).
     91 
     92 script_dialogue_unit(neutral(Text)) --> text("\n", Text).
     93 
     94 
     95 script_character_stage_directions(Text) --> "(", text("\n<>)", Text), ")".
     96 
     97 
     98 script_emphatic(Text) --> "<em>", text("\n<>()", Text), "</em>".
     99 
    100 script_emphatic(Text) --> "<i>", text("\n<>()", Text), "</i>".
    101 
    102 script_emphatic(Text) --> "*", text("\n*", Text), "*".
    103 
    104 
    105 script_head([Title, Author, Personae, Time, Setting]) -->
    106 	tag("title", Title),
    107 	newline,
    108 	tag("author", Author),
    109 	newline,
    110 	tags("persona", Personae),
    111 	newline,
    112 	tag("time", Time),
    113 	newline,
    114 	tag("setting", Setting).
    115 
    116 script_head([Title, Author]) -->
    117 	tag("title", Title),
    118 	newline,
    119 	tag("author", Author).
    120 
    121 
    122 tag(Key, Value) --> "@", Key, ": ", text("\n", Value).
    123 
    124 
    125 tags(Key, [Value]) --> tag(Key, Value).
    126 
    127 tags(Key, [Value|Values]) -->
    128 	tag(Key, Value),
    129 	newline,
    130 	tags(Key, Values).
    131 
    132 
    133 script_line_break --> "<br/>".
    134 
    135 script_line_break --> "<br />".
    136 
    137 
    138 script_line_breaks([br]) --> script_line_break.
    139 
    140 script_line_breaks([br|Break]) -->
    141 	script_line_break,
    142 	script_line_breaks(Break).
    143 
    144 
    145 script_act(Text) --> "ACT ", text("\n", Text).
    146 
    147 script_act(Text) --> "Act ", text("\n", Text).
    148 
    149 
    150 script_slug(slug(int, Text)) --> "INT. ", text("\n", Text).
    151 
    152 script_slug(slug(ext, Text)) --> "EXT. ", text("\n", Text).  
    153 
    154 
    155 script_end --> "The End.".