├── doc ├── overview.md ├── book │ ├── preamble.tex │ ├── introduction.tex │ ├── index.tex │ ├── postem_book.tex │ └── grammar.tex ├── syntax_highlighting.md ├── lexer │ └── lexer.py └── getting_started.md ├── .ocamlformat ├── bin ├── postem.ml ├── dune ├── custom_compil.ml └── doc.post ├── man ├── dune └── postem.1 ├── src ├── common │ ├── enumerate │ │ ├── enumerate.ml │ │ ├── dune │ │ ├── enumerate.mli │ │ ├── base.mli │ │ ├── builtins.mli │ │ ├── base.ml │ │ └── builtins.ml │ ├── dune │ ├── common.ml │ ├── common.mli │ ├── stdlib_ext.ml │ ├── err.mli │ ├── stdlib_ext.mli │ ├── ctx.mli │ ├── ctx.ml │ └── err.ml ├── dune ├── expansion │ ├── dune │ ├── known.ml │ └── default.ml ├── core │ ├── dune │ ├── ehandler.ml │ ├── ehandler.mli │ ├── args.mli │ ├── compil_impl.mli │ ├── compil_impl.ml │ └── args.ml ├── ast │ ├── expansion.mli │ ├── dune │ ├── types.ml │ ├── eval.mli │ └── eval.ml ├── checker │ ├── dune │ ├── checker.mli │ └── checker.ml ├── repl.mli ├── compiler.mli ├── postem.ml ├── postem.mli ├── syntax │ ├── lexer.mli │ ├── dune │ ├── syntax.mli │ ├── parsed_ast.mli │ ├── parsed_ast.ml │ ├── syntax.ml │ ├── parser.mly │ └── lexer.ml ├── repl.ml └── compiler.ml ├── .gitignore ├── Makefile ├── dune-project ├── postem.opam ├── README.md └── LICENSE /doc/overview.md: -------------------------------------------------------------------------------- 1 | # An overview of Postem features 2 | -------------------------------------------------------------------------------- /.ocamlformat: -------------------------------------------------------------------------------- 1 | profile = default 2 | version = 0.20.1 3 | -------------------------------------------------------------------------------- /bin/postem.ml: -------------------------------------------------------------------------------- 1 | let () = Postem__Compiler.compile () 2 | -------------------------------------------------------------------------------- /doc/book/preamble.tex: -------------------------------------------------------------------------------- 1 | \usepackage[epsilon, altpo]{backnaur} 2 | -------------------------------------------------------------------------------- /man/dune: -------------------------------------------------------------------------------- 1 | (install 2 | (section man) 3 | (files postem.1)) 4 | -------------------------------------------------------------------------------- /doc/book/introduction.tex: -------------------------------------------------------------------------------- 1 | \part{Introduction}\label{part:intro} 2 | -------------------------------------------------------------------------------- /src/common/enumerate/enumerate.ml: -------------------------------------------------------------------------------- 1 | module Base = Base 2 | module Builtins = Builtins 3 | -------------------------------------------------------------------------------- /src/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name postem) 3 | (public_name postem) 4 | (libraries ast core)) 5 | -------------------------------------------------------------------------------- /src/common/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name common) 3 | (public_name postem.common) 4 | (libraries enumerate)) 5 | -------------------------------------------------------------------------------- /src/common/enumerate/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name enumerate) 3 | (public_name postem.common.enumerate)) 4 | -------------------------------------------------------------------------------- /src/common/common.ml: -------------------------------------------------------------------------------- 1 | include Stdlib_ext 2 | module Ctx = Ctx 3 | module Enumerate = Enumerate 4 | module Err = Err 5 | -------------------------------------------------------------------------------- /src/expansion/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name expansion) 3 | (public_name postem.expansion) 4 | (libraries ast common)) 5 | -------------------------------------------------------------------------------- /src/common/common.mli: -------------------------------------------------------------------------------- 1 | include module type of Stdlib_ext 2 | module Ctx = Ctx 3 | module Enumerate = Enumerate 4 | module Err = Err 5 | -------------------------------------------------------------------------------- /src/core/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name core) 3 | (public_name postem.core) 4 | (libraries ast checker common expansion sedlex syntax)) 5 | -------------------------------------------------------------------------------- /src/common/enumerate/enumerate.mli: -------------------------------------------------------------------------------- 1 | (** High level oriented object numbering library. *) 2 | 3 | module Base = Base 4 | module Builtins = Builtins 5 | -------------------------------------------------------------------------------- /bin/dune: -------------------------------------------------------------------------------- 1 | (executables 2 | (names postem custom_compil) 3 | (libraries postem)) 4 | 5 | (install 6 | (section bin) 7 | (files 8 | (postem.exe as postem))) 9 | -------------------------------------------------------------------------------- /src/ast/expansion.mli: -------------------------------------------------------------------------------- 1 | module type S = sig 2 | val alias : Common.Ctx.AliasCtx.t 3 | val bop : Common.Ctx.BinOpCtx.t 4 | val uop : Common.Ctx.UopCtx.t 5 | end 6 | -------------------------------------------------------------------------------- /src/checker/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name checker) 3 | (public_name postem.checker) 4 | (preprocess 5 | (pps ppx_deriving.show)) 6 | (libraries ast common syntax)) 7 | -------------------------------------------------------------------------------- /src/repl.mli: -------------------------------------------------------------------------------- 1 | module type S = sig 2 | val launch : unit -> unit 3 | end 4 | 5 | module Make : functor (Compiler : Core.Compil_impl.S with type t := string) -> S 6 | -------------------------------------------------------------------------------- /src/compiler.mli: -------------------------------------------------------------------------------- 1 | (** {1 API} *) 2 | 3 | val compile : unit -> unit 4 | (** Compile the document passed at CLI and write result on a file or on stdout 5 | according to CLI argument. *) 6 | -------------------------------------------------------------------------------- /src/ast/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name ast) 3 | (public_name postem.ast) 4 | (modules_without_implementation expansion) 5 | (preprocess 6 | (pps ppx_deriving.show sedlex.ppx)) 7 | (libraries common)) 8 | -------------------------------------------------------------------------------- /src/checker/checker.mli: -------------------------------------------------------------------------------- 1 | module type S = sig 2 | val check : 3 | Syntax.Parsed_ast.t -> (Ast.Types.doc, Common.Err.checker_err) result 4 | end 5 | 6 | module Make : functor (Expsn : Ast.Expansion.S) -> S 7 | -------------------------------------------------------------------------------- /src/expansion/known.ml: -------------------------------------------------------------------------------- 1 | type t = (name * doc * (module Ast.Expansion.S)) list 2 | and name = string 3 | and doc = string 4 | 5 | let expansions : t = [ ("default", "output to plain text.", (module Default)) ] 6 | -------------------------------------------------------------------------------- /doc/book/index.tex: -------------------------------------------------------------------------------- 1 | \clearpage 2 | 3 | \clearpage 4 | 5 | \tableofcontents 6 | 7 | \clearpage 8 | 9 | \input{doc/book/introduction} 10 | 11 | \clearpage 12 | 13 | \input{doc/book/grammar} 14 | 15 | \clearpage 16 | -------------------------------------------------------------------------------- /src/postem.ml: -------------------------------------------------------------------------------- 1 | module Ast = Ast 2 | module Checker = Checker 3 | module Common = Common 4 | module Compiler = Compiler 5 | module Core = Core 6 | module Expansion = Expansion 7 | module Syntax = Syntax 8 | module Repl = Repl 9 | -------------------------------------------------------------------------------- /src/postem.mli: -------------------------------------------------------------------------------- 1 | module Ast = Ast 2 | module Checker = Checker 3 | module Common = Common 4 | module Compiler = Compiler 5 | module Core = Core 6 | module Expansion = Expansion 7 | module Syntax = Syntax 8 | module Repl = Repl 9 | -------------------------------------------------------------------------------- /src/syntax/lexer.mli: -------------------------------------------------------------------------------- 1 | exception IllegalChar of Sedlexing.lexbuf 2 | 3 | val read : Sedlexing.lexbuf -> Parser.token 4 | (** @raise IllegalChar *) 5 | 6 | val read_debug : Sedlexing.lexbuf -> Parser.token 7 | (** @raise IllegalChar *) 8 | -------------------------------------------------------------------------------- /src/syntax/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name syntax) 3 | (public_name postem.syntax) 4 | (libraries ast common menhirLib sedlex) 5 | (preprocess 6 | (pps ppx_deriving.show sedlex.ppx)) 7 | (flags :standard -w +39)) 8 | 9 | (menhir 10 | (modules parser)) 11 | -------------------------------------------------------------------------------- /src/ast/types.ml: -------------------------------------------------------------------------------- 1 | type doc = expr list [@@deriving show] 2 | 3 | and expr = 4 | | Text of string 5 | | White of string 6 | | Unformat of string 7 | | Group of expr list 8 | | UnaryOp of { op : string; group : expr } 9 | | BinOp of { op : string; left : expr; right : expr } 10 | -------------------------------------------------------------------------------- /doc/book/postem_book.tex: -------------------------------------------------------------------------------- 1 | \documentclass[a4paper, 11pt, UTF8, oneside]{article} 2 | 3 | \date{} 4 | 5 | \input{doc/book/preamble} 6 | 7 | \title{\textbf{The Postem book}} 8 | 9 | \author{Timéo Arnouts} 10 | 11 | \begin{document} 12 | 13 | \maketitle 14 | 15 | \input{doc/book/index} 16 | 17 | \end{document} 18 | -------------------------------------------------------------------------------- /src/ast/eval.mli: -------------------------------------------------------------------------------- 1 | (** {1 API} *) 2 | 3 | (** Output signature of the functor [Eval_expsn.MakeWithExpsn]. *) 4 | module type S = sig 5 | type t 6 | 7 | val eval : Types.doc -> t 8 | end 9 | 10 | (** Functor building a string evaluator from an expansion. *) 11 | module MakeWithExpsn : functor (Expsn : Expansion.S) -> S with type t := string 12 | -------------------------------------------------------------------------------- /src/syntax/syntax.mli: -------------------------------------------------------------------------------- 1 | module type S = sig 2 | val parse : Sedlexing.lexbuf -> (Parsed_ast.t, Common.Err.parser_err) result 3 | (** [parse lexbuf] returns [Ok past] if parsing goes smoothly, [Error err] 4 | otherwise. *) 5 | end 6 | 7 | module Parser : S 8 | (** Default implementation of the parser. *) 9 | 10 | module Parsed_ast = Parsed_ast 11 | -------------------------------------------------------------------------------- /src/common/stdlib_ext.ml: -------------------------------------------------------------------------------- 1 | let prerr_with_exit err = 2 | prerr_endline err; 3 | exit 1 4 | 5 | module In_channel = struct 6 | let write filename str = 7 | let oc = open_out filename in 8 | output_string oc str; 9 | close_out oc 10 | end 11 | 12 | module Result = struct 13 | include Result 14 | 15 | let ( let+ ) = Result.bind 16 | end 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.annot 2 | *.cmo 3 | *.cma 4 | *.cmi 5 | *.a 6 | *.out 7 | *.o 8 | *.cmx 9 | *.cmxs 10 | *.cmxa 11 | 12 | # ocamlbuild working directory 13 | _build/ 14 | 15 | # ocamlbuild targets 16 | *.byte 17 | *.native 18 | 19 | # oasis generated files 20 | setup.data 21 | setup.log 22 | 23 | # Merlin configuring file for Vim and Emacs 24 | .merlin 25 | 26 | # Dune generated files 27 | *.install 28 | 29 | # Local OPAM switch 30 | _opam/ 31 | -------------------------------------------------------------------------------- /src/syntax/parsed_ast.mli: -------------------------------------------------------------------------------- 1 | type 'a with_loc = { loc : Lexing.position * Lexing.position; value : 'a } 2 | 3 | type t = expr list 4 | 5 | and expr = 6 | | LText of string 7 | | LWhite of string 8 | | LNewline of string 9 | | LUnformat of string 10 | | LGroup of expr list 11 | | LUnaryOp of { op : string with_loc; group : expr; newline : string } 12 | | LBinOp of { op : string with_loc; left : expr; right : expr } 13 | 14 | val show : t -> string 15 | -------------------------------------------------------------------------------- /src/core/ehandler.ml: -------------------------------------------------------------------------------- 1 | module KnownExpansions = struct 2 | type t = Expansion.Known.t 3 | 4 | let to_string t = 5 | List.map (fun (name, doc, _) -> Printf.sprintf "%s: %s" name doc) t 6 | |> String.concat "\n" 7 | end 8 | 9 | let load t name = 10 | let found_expsn = List.filter (fun (n, _, _) -> n = name) t in 11 | match found_expsn with 12 | | [] -> Error (`UnknownExpsn name) 13 | | [ (_, _, expsn) ] -> Ok expsn 14 | | _ -> Error (`ExpsnAmbiguity name) 15 | -------------------------------------------------------------------------------- /src/syntax/parsed_ast.ml: -------------------------------------------------------------------------------- 1 | module Lexing = struct 2 | include Lexing 3 | 4 | let pp_position fmt _t = Format.fprintf fmt "loc" 5 | end 6 | 7 | type 'a with_loc = { loc : Lexing.position * Lexing.position; value : 'a } 8 | [@@deriving show] 9 | 10 | type t = expr list [@@deriving show] 11 | 12 | and expr = 13 | | LText of string 14 | | LWhite of string 15 | | LNewline of string 16 | | LUnformat of string 17 | | LGroup of expr list 18 | | LUnaryOp of { op : string with_loc; group : expr; newline : string } 19 | | LBinOp of { op : string with_loc; left : expr; right : expr } 20 | -------------------------------------------------------------------------------- /bin/custom_compil.ml: -------------------------------------------------------------------------------- 1 | module IntEval = struct 2 | type t = int 3 | 4 | let rec eval doc = List.fold_left eval_expr 0 doc 5 | 6 | and eval_expr acc expr = 7 | match expr with 8 | | Ast.Types.Text t -> ( acc + try int_of_string t with Failure _ -> 0) 9 | | _ -> acc 10 | end 11 | 12 | module MyCompiler = 13 | Core.Compil_impl.Make (Syntax.Parser) (Checker.Make (Expansion.Default)) 14 | (IntEval) 15 | 16 | let () = 17 | match MyCompiler.from_string "hello 10 world" with 18 | | Ok n -> Printf.printf "%d\n" n 19 | | Error err -> prerr_endline @@ Common.Err.to_string err 20 | -------------------------------------------------------------------------------- /src/common/err.mli: -------------------------------------------------------------------------------- 1 | (** Containing utilities for error message formatting. *) 2 | 3 | (** {1 Types} *) 4 | 5 | type loc = Lexing.position * Lexing.position 6 | type checker_err = [ `UndefinedUop of loc ] 7 | type expsn_err = [ `ExpsnAmbiguity of string | `UnknownExpsn of string ] 8 | type parser_err = [ `IllegalCharacter of loc | `SyntaxError of loc ] 9 | type t = [ checker_err | expsn_err | parser_err | `NoSuchFile of string ] 10 | 11 | (** {2 API} *) 12 | 13 | val to_string : t -> string 14 | 15 | val pp_string : ?hint:string -> string -> string 16 | (** [pp_string msg] prettifies and returns it as string. *) 17 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all build clean doc repl fmt deps 2 | 3 | all: build doc 4 | 5 | build: 6 | dune build 7 | 8 | doc: 9 | dune build @doc-private 10 | pdflatex doc/book/postem_book.tex 11 | rm postem_book.aux 12 | rm postem_book.log 13 | rm postem_book.toc 14 | mkdir doc/build 15 | mv postem_book.pdf doc/build 16 | 17 | clean: 18 | dune clean 19 | rm -rf doc/build 20 | 21 | repl: 22 | dune utop 23 | 24 | fmt: 25 | -dune build @fmt --auto-promote 26 | 27 | deps: 28 | dune external-lib-deps --missing @@default 29 | 30 | install: 31 | dune build @install 32 | dune install 33 | 34 | uninstall: 35 | dune uninstall 36 | -------------------------------------------------------------------------------- /src/common/stdlib_ext.mli: -------------------------------------------------------------------------------- 1 | (** Some extension to OCaml stdlib. *) 2 | 3 | val prerr_with_exit : string -> 'a 4 | (** Print on stderr given string and exit with code 1. *) 5 | 6 | (** Extension to the [Result] module of the OCaml stdlib. *) 7 | module Result : sig 8 | include module type of Result 9 | 10 | val ( let+ ) : ('a, 'b) t -> ('a -> ('c, 'b) t) -> ('c, 'b) t 11 | end 12 | 13 | (** Containing utilities for in_channel io. *) 14 | module In_channel : sig 15 | val write : string -> string -> unit 16 | (** [write filename str] writes [str] in file [filename]. 17 | Create file [filename] if it does not exist. *) 18 | end 19 | -------------------------------------------------------------------------------- /src/core/ehandler.mli: -------------------------------------------------------------------------------- 1 | (** Utilities to load expansion. 2 | 3 | Expansions must be placed in [src/expansion/] folder and be registered in 4 | [src/expansion/known.ml]. *) 5 | 6 | (** {1 API} *) 7 | 8 | module KnownExpansions : sig 9 | type t = Expansion.Known.t 10 | 11 | val to_string : t -> string 12 | (** Prettify given known expansions and returns it as a string. *) 13 | end 14 | 15 | val load : 16 | KnownExpansions.t -> 17 | string -> 18 | ((module Ast.Expansion.S), Common.Err.expsn_err) result 19 | (** [load_res known_expsn name] returns [Ok e] where [e] is expansions module 20 | associated to [name], [Error err] otherwise. *) 21 | -------------------------------------------------------------------------------- /src/syntax/syntax.ml: -------------------------------------------------------------------------------- 1 | module type S = sig 2 | val parse : Sedlexing.lexbuf -> (Parsed_ast.t, Common.Err.parser_err) result 3 | end 4 | 5 | module Parser : S = struct 6 | let parse lexbuf = 7 | let lexer = Sedlexing.with_tokenizer Lexer.read lexbuf in 8 | let parser = 9 | MenhirLib.Convert.Simplified.traditional2revised Parser.document 10 | in 11 | let open Result in 12 | try ok @@ parser lexer with 13 | | Lexer.IllegalChar lexbuf -> 14 | error @@ `IllegalCharacter (Sedlexing.lexing_positions lexbuf) 15 | | Parser.Error -> error @@ `SyntaxError (Sedlexing.lexing_positions lexbuf) 16 | end 17 | 18 | module Parsed_ast = Parsed_ast 19 | -------------------------------------------------------------------------------- /src/repl.ml: -------------------------------------------------------------------------------- 1 | module type S = sig 2 | val launch : unit -> unit 3 | end 4 | 5 | module Make (Compiler : Core.Compil_impl.S with type t := string) = struct 6 | let prompt () = print_string "> " 7 | let print = Printf.printf "- : %s\n" 8 | 9 | let rec launch () = 10 | prompt (); 11 | let input = ref [] in 12 | try 13 | while true do 14 | input := read_line () :: !input 15 | done 16 | with End_of_file -> ( 17 | match 18 | List.rev !input |> String.concat "\n" 19 | |> Compiler.from_string ~filename:"REPL" 20 | with 21 | | Ok output -> 22 | print output; 23 | launch () 24 | | Error err -> Common.(prerr_with_exit @@ Err.to_string err)) 25 | end 26 | -------------------------------------------------------------------------------- /bin/doc.post: -------------------------------------------------------------------------------- 1 | & Postem 2 | 3 | && Philosophy 4 | 5 | P aims to be a lightweight markup language designed for note taking. 6 | It is also intended to be easily extensible by allowing extension writing in OCaml. 7 | 8 | && Features 9 | 10 | P supports alias definition and custom operator definition. 11 | 12 | && Builtins marks 13 | 14 | There are six builtins title tags: 15 | {{& for a level one title, && for a level two title, and this up to 6.}} 16 | 17 | By the way, the line above is unformated because it is put between two curly brackets. 18 | This avoids the need to individually escape each operator. 19 | 20 | > There are also quotes 21 | 22 | > On one or on 23 | > several lines 24 | 25 | -- The \-\- mark allows you to formulate a conclusion. 26 | -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 2.9) 2 | 3 | (using menhir 2.1) 4 | 5 | (version 0.0.1) 6 | 7 | (name postem) 8 | 9 | (license "GPL-3.0") 10 | 11 | (authors "The postem programmers") 12 | 13 | (maintainers "tim.arnouts@protonmail.com") 14 | 15 | (source 16 | (github Tim-ats-d/Postem-markup)) 17 | 18 | (bug_reports "https://github.com/Tim-ats-d/Postem-markup/issues") 19 | 20 | (homepage "https://github.com/Tim-ats-d/Postem-markup") 21 | 22 | (documentation "https://github.com/Tim-ats-d/Postem-markup/tree/master/doc") 23 | 24 | (generate_opam_files true) 25 | 26 | (package 27 | (name postem) 28 | (synopsis "A lightweight markup language designed for quick note taking") 29 | (depends 30 | dune 31 | (ocaml 32 | (>= 4.11)) 33 | (odoc :with-doc) 34 | (menhir 35 | (>= 20210419)))) 36 | -------------------------------------------------------------------------------- /src/core/args.mli: -------------------------------------------------------------------------------- 1 | (** {1 Type} *) 2 | 3 | type t = 4 | < direct_input : string 5 | ; inputf : string 6 | ; outputf : string 7 | ; expsn : string 8 | ; output_on_stdout : bool > 9 | (** Type representing CLI argument passed by user. *) 10 | 11 | (** {2 API} *) 12 | 13 | class args : 14 | object 15 | method direct_input : string 16 | method inputf : string 17 | method outputf : string 18 | method expsn : string 19 | method output_on_stdout : bool 20 | method set_direct_input : string -> unit 21 | method set_inputf : string -> unit 22 | method set_outputf : string -> unit 23 | method set_expsn : string -> unit 24 | method set_output_on_stdout : bool -> unit 25 | end 26 | 27 | val parse : unit -> t 28 | (** Returns CLI arguments passed as type [t]. *) 29 | -------------------------------------------------------------------------------- /src/common/ctx.mli: -------------------------------------------------------------------------------- 1 | (** {1 API} *) 2 | 3 | (** Output signature of the functor [Ctx.Make]. *) 4 | module type S = sig 5 | type t 6 | type key 7 | type value 8 | 9 | val empty : t 10 | val add : key -> value -> t -> t 11 | val find : t -> key -> value 12 | val find_opt : t -> key -> value option 13 | val merge : t -> t -> t 14 | end 15 | 16 | module type VALUE = sig 17 | type t 18 | end 19 | 20 | (** Functor building a context given a totally ordered type and a value. *) 21 | module Make : functor (Ord : Map.OrderedType) (Value : VALUE) -> 22 | S with type key := Ord.t and type value := Value.t 23 | 24 | module AliasCtx : S with type key := string and type value := string 25 | module BinOpCtx : S with type key := string and type value := string -> string -> string 26 | module UopCtx : S with type key := string and type value := string -> string 27 | -------------------------------------------------------------------------------- /doc/syntax_highlighting.md: -------------------------------------------------------------------------------- 1 | # Syntaxic color for Postem 2 | 3 | **Postem** provides a [custom lexer pygments](https://pygments.org/docs/lexerdevelopment/) ready to use located in `doc/lexer/lexer.py`. 4 | 5 | Here is an example of **Python** code using it: 6 | ```py 7 | import pygments 8 | from pygments.formatters import HtmlFormatter 9 | from pygments.lexers import load_lexer_from_file 10 | 11 | postem_input = """ 12 | & Title 13 | 14 | > A quotation 15 | """ 16 | 17 | formatter = HtmlFormatter() 18 | 19 | with open("styles.css", "w") as f: 20 | f.write(formatter.get_style_defs()) 21 | 22 | with open("output.html", "w") as f: 23 | lexer = load_lexer_from_file("lexer.py", "PostemLexer") 24 | output = pygments.highlight(postem_input, lexer, formatter) 25 | 26 | f.write('') 27 | f.write(output) 28 | 29 | ``` 30 | 31 | See the [related Pygments documentation](https://pygments.org/docs/) for more information 32 | -------------------------------------------------------------------------------- /postem.opam: -------------------------------------------------------------------------------- 1 | # This file is generated by dune, edit dune-project instead 2 | opam-version: "2.0" 3 | version: "0.0.1" 4 | synopsis: "A lightweight markup language designed for quick note taking" 5 | maintainer: ["tim.arnouts@protonmail.com"] 6 | authors: ["The postem programmers"] 7 | license: "GPL-3.0" 8 | homepage: "https://github.com/Tim-ats-d/Postem-markup" 9 | doc: "https://github.com/Tim-ats-d/Postem-markup/tree/master/doc" 10 | bug-reports: "https://github.com/Tim-ats-d/Postem-markup/issues" 11 | depends: [ 12 | "dune" {>= "2.9"} 13 | "ocaml" {>= "4.11"} 14 | "odoc" {with-doc} 15 | "menhir" {>= "20210419"} 16 | ] 17 | build: [ 18 | ["dune" "subst"] {dev} 19 | [ 20 | "dune" 21 | "build" 22 | "-p" 23 | name 24 | "-j" 25 | jobs 26 | "--promote-install-files=false" 27 | "@install" 28 | "@runtest" {with-test} 29 | "@doc" {with-doc} 30 | ] 31 | ["dune" "install" "-p" name "--create-install-files" name] 32 | ] 33 | dev-repo: "git+https://github.com/Tim-ats-d/Postem-markup.git" 34 | -------------------------------------------------------------------------------- /src/core/compil_impl.mli: -------------------------------------------------------------------------------- 1 | (** Output signature of the functor [Compil_impl.Make]. *) 2 | module type S = sig 3 | type t 4 | (** The outputed type. *) 5 | 6 | val from_lexbuf : 7 | ?filename:string -> Sedlexing.lexbuf -> (t, Common.Err.t) result 8 | (** [from_lexbuf lexbuf] returns [Ok output] if compilation goes smoothly, 9 | [Error msg] otherwise. Optional argument [filename] is used to indicate 10 | in the file name in error messages in case of an error *) 11 | 12 | val from_string : ?filename:string -> string -> (t, Common.Err.t) result 13 | (** [from_string str] does the same as [from_lexbuf] execept it compiles [str]. *) 14 | 15 | val from_channel : ?filename:string -> in_channel -> (t, Common.Err.t) result 16 | (** [from_file chan] does the same as [from_lexbuf] execept it compiles the 17 | content of file [chan]. *) 18 | end 19 | 20 | (** Build a compiler from several units. *) 21 | module Make : functor 22 | (Parser : Syntax.S) 23 | (Checker : Checker.S) 24 | (Eval : Ast.Eval.S) 25 | -> S with type t := Eval.t 26 | -------------------------------------------------------------------------------- /src/common/ctx.ml: -------------------------------------------------------------------------------- 1 | module type S = sig 2 | type t 3 | type key 4 | type value 5 | 6 | val empty : t 7 | val add : key -> value -> t -> t 8 | val find : t -> key -> value 9 | val find_opt : t -> key -> value option 10 | val merge : t -> t -> t 11 | end 12 | 13 | module type VALUE = sig 14 | type t 15 | end 16 | 17 | module Make (Ord : Map.OrderedType) (Value : VALUE) : 18 | S with type key := Ord.t and type value := Value.t = struct 19 | module Map = Map.Make (Ord) 20 | 21 | type t = Value.t Map.t 22 | 23 | let empty = Map.empty 24 | let add = Map.add 25 | let find t x = Map.find x t 26 | let find_opt t x = Map.find_opt x t 27 | 28 | let merge a b = 29 | Map.merge (fun _ s s' -> match s with None -> s' | Some _ -> s) a b 30 | end 31 | 32 | module AliasCtx = Make (String) (String) 33 | 34 | module BinOpCtx = 35 | Make 36 | (String) 37 | (struct 38 | type t = string -> string -> string 39 | end) 40 | 41 | module UopCtx = 42 | Make 43 | (String) 44 | (struct 45 | type t = string -> string 46 | end) 47 | -------------------------------------------------------------------------------- /src/core/compil_impl.ml: -------------------------------------------------------------------------------- 1 | module type S = sig 2 | type t 3 | 4 | val from_lexbuf : 5 | ?filename:string -> Sedlexing.lexbuf -> (t, Common.Err.t) result 6 | 7 | val from_string : ?filename:string -> string -> (t, Common.Err.t) result 8 | val from_channel : ?filename:string -> in_channel -> (t, Common.Err.t) result 9 | end 10 | 11 | module Make (Parser : Syntax.S) (Checker : Checker.S) (Eval : Ast.Eval.S) : 12 | S with type t := Eval.t = struct 13 | let from_lexbuf ?(filename = "") lexbuf = 14 | Sedlexing.set_filename lexbuf filename; 15 | let open Common.Result in 16 | match Parser.parse lexbuf with 17 | | Ok parsed_ast -> ( 18 | match Checker.check parsed_ast with 19 | | Ok ast -> ok @@ Eval.eval ast 20 | | Error err -> Error (err :> Common.Err.t)) 21 | | Error err -> Error (err :> Common.Err.t) 22 | 23 | let from_string ?(filename = "") str = 24 | let lexbuf = Sedlexing.Utf8.from_string str in 25 | from_lexbuf lexbuf ~filename 26 | 27 | let from_channel ?(filename = "") chan = 28 | let lexbuf = Sedlexing.Utf8.from_channel chan in 29 | from_lexbuf lexbuf ~filename 30 | end 31 | -------------------------------------------------------------------------------- /src/common/enumerate/base.mli: -------------------------------------------------------------------------------- 1 | (** Containing utility classes to build the [Builtins] module. *) 2 | 3 | (** {1 API} *) 4 | 5 | (** A virtual class used to structure inheritance. *) 6 | class virtual numerotation : 7 | object 8 | method virtual get : string 9 | (** Returns current letter as a string. *) 10 | 11 | method virtual next : unit 12 | (** Advances in the unfolding of the alphabet. *) 13 | end 14 | 15 | (** [alphabet] takes a string array representing the letters of an alphabet. 16 | 17 | When the last letter is reached, start again at the first and so on. *) 18 | class virtual alphabet : 19 | string array 20 | -> object 21 | method get : string 22 | method next : unit 23 | end 24 | 25 | (** [roman] takes representing the different letters of the roman alphabet. 26 | 27 | When the last letter is reached, start again at the first and so on. *) 28 | class virtual roman : 29 | [< `I of string ] 30 | -> [< `V of string ] 31 | -> [< `X of string ] 32 | -> [< `L of string ] 33 | -> [< `C of string ] 34 | -> [< `D of string ] 35 | -> [< `M of string ] 36 | -> object 37 | method get : string 38 | method next : unit 39 | end 40 | -------------------------------------------------------------------------------- /src/ast/eval.ml: -------------------------------------------------------------------------------- 1 | open Common 2 | 3 | module type S = sig 4 | type t 5 | 6 | val eval : Types.doc -> t 7 | end 8 | 9 | module EvalCtx = struct 10 | type t = { alias : Ctx.AliasCtx.t; bop : Ctx.BinOpCtx.t; uop : Ctx.UopCtx.t } 11 | 12 | let create ~alias ~bop ~uop = { alias; bop; uop } 13 | end 14 | 15 | module MakeWithExpsn (Expsn : Expansion.S) : S with type t := string = struct 16 | let rec eval doc = 17 | let ctx = Expsn.(EvalCtx.create ~alias ~bop ~uop) in 18 | List.map (eval_expr ctx) doc |> String.concat "" 19 | 20 | and eval_expr ctx expr = 21 | let open Types in 22 | match expr with 23 | | Text s | White s | Unformat s -> s 24 | | Group grp -> eval_group ctx grp 25 | | UnaryOp { op; group } -> eval_uop ctx op group 26 | | BinOp { op; left; right } -> eval_bin_op ctx op ~left ~right 27 | 28 | and eval_group ctx grp = List.map (eval_expr ctx) grp |> String.concat "" 29 | 30 | and eval_uop ctx op group = 31 | let f = Ctx.UopCtx.find ctx.EvalCtx.uop op in 32 | f @@ eval_expr ctx group 33 | 34 | and eval_bin_op ctx op ~left ~right = 35 | let f = Ctx.BinOpCtx.find ctx.EvalCtx.bop op in 36 | f (eval_expr ctx left) (eval_expr ctx right) 37 | end 38 | -------------------------------------------------------------------------------- /src/compiler.ml: -------------------------------------------------------------------------------- 1 | open Common 2 | open Core 3 | 4 | let load_unit name = 5 | match Ehandler.load Expansion.Known.expansions name with 6 | | Ok expsn -> expsn 7 | | Error err -> prerr_with_exit @@ Err.to_string (err :> Err.t) 8 | 9 | let compile () = 10 | let args = Args.parse () in 11 | let module Expsn = (val load_unit args#expsn) in 12 | let module Eval = struct 13 | type t = string 14 | 15 | include Ast.Eval.MakeWithExpsn (Expsn) 16 | end in 17 | let module Compiler = 18 | Compil_impl.Make (Syntax.Parser) (Checker.Make (Expsn)) (Eval) 19 | in 20 | if args#direct_input = "" && args#inputf = "" then 21 | let module Repl = Repl.Make (Compiler) in 22 | Repl.launch () 23 | else 24 | let from_src = 25 | if args#direct_input = "" then 26 | if Sys.file_exists args#inputf then 27 | Compiler.from_channel ~filename:args#inputf @@ open_in args#inputf 28 | else prerr_with_exit @@ Err.to_string (`NoSuchFile args#inputf) 29 | else Compiler.from_string ~filename:args#inputf args#inputf 30 | in 31 | match from_src with 32 | | Ok r -> 33 | if args#output_on_stdout then print_endline r 34 | else In_channel.write args#outputf r 35 | | Error err -> prerr_with_exit @@ Err.to_string err 36 | -------------------------------------------------------------------------------- /src/common/enumerate/builtins.mli: -------------------------------------------------------------------------------- 1 | (** {1 API} *) 2 | 3 | (** The null numbering. *) 4 | class null : 5 | object 6 | method get : string 7 | 8 | method next : unit 9 | (** Returns always an empty string. *) 10 | end 11 | 12 | class numeric_arab : 13 | object 14 | method get : string 15 | method next : unit 16 | end 17 | 18 | class lower_case_numeric_roman : 19 | object 20 | method get : string 21 | method next : unit 22 | end 23 | 24 | class upper_case_numeric_roman : 25 | object 26 | method get : string 27 | method next : unit 28 | end 29 | 30 | class lower_case_latin : 31 | object 32 | method get : string 33 | method next : unit 34 | end 35 | 36 | class upper_case_latin : 37 | object 38 | method get : string 39 | method next : unit 40 | end 41 | 42 | class lower_case_greek : 43 | object 44 | method get : string 45 | method next : unit 46 | end 47 | 48 | class upper_case_greek : 49 | object 50 | method get : string 51 | method next : unit 52 | end 53 | 54 | class lower_case_cyrillic : 55 | object 56 | method get : string 57 | method next : unit 58 | end 59 | 60 | class upper_case_cyrillc : 61 | object 62 | method get : string 63 | method next : unit 64 | end 65 | -------------------------------------------------------------------------------- /src/syntax/parser.mly: -------------------------------------------------------------------------------- 1 | %{ 2 | open Parsed_ast 3 | 4 | let mk_loc loc value = { loc; value } 5 | %} 6 | 7 | %token OP 8 | %token NEWLINE 9 | %token TEXT 10 | %token WHITE 11 | %token UNFORMAT 12 | 13 | %token LBRACKET RBRACKET 14 | %token EOF 15 | 16 | %type document 17 | %start document 18 | 19 | %% 20 | 21 | let document := 22 | | lines=line*; EOF; { lines } 23 | 24 | let line := 25 | | expr 26 | | uop_line 27 | | n=NEWLINE; { LNewline n } 28 | 29 | let expr := 30 | | group 31 | | terminal 32 | | op_app 33 | 34 | let terminal == 35 | | t=TEXT; { LText t } 36 | | w=WHITE; { LWhite w } 37 | | u=UNFORMAT; { LUnformat u } 38 | 39 | let group == 40 | | LBRACKET; grp=group_aux*; RBRACKET; { LGroup grp } 41 | 42 | let group_aux == 43 | | expr 44 | | n=NEWLINE; { LNewline n } 45 | 46 | let op_app == 47 | | unary_op 48 | 49 | let unary_op == 50 | | op=OP; t=TEXT; 51 | { LUnaryOp { op = mk_loc $loc(op) op; group = LGroup [ LText t ]; newline = "" } } 52 | | op=OP; group=group; 53 | { LUnaryOp { op = mk_loc $loc(op) op; group; newline = "" } } 54 | 55 | let uop_line == 56 | | op=OP; WHITE; grp=expr+; newline=NEWLINE; 57 | { LUnaryOp { op = mk_loc $loc(op) op; group = LGroup grp; newline } } 58 | -------------------------------------------------------------------------------- /src/common/enumerate/base.ml: -------------------------------------------------------------------------------- 1 | class virtual numerotation = 2 | object 3 | method virtual next : unit 4 | 5 | method virtual get : string 6 | end 7 | 8 | class virtual alphabet letters = 9 | object 10 | inherit numerotation 11 | 12 | val mutable n = 0 13 | 14 | method next = if n < Array.length letters then n <- n + 1 else n <- 1 15 | (* Start again. *) 16 | 17 | method get = letters.(n - 1) 18 | end 19 | 20 | class virtual roman (`I i) (`V v) (`X x) (`L l) (`C c) (`D d) (`M m) = 21 | object (self) 22 | inherit numerotation 23 | 24 | val mutable n = 0 25 | 26 | method private digit x y z = function 27 | | 1 -> [ x ] 28 | | 2 -> [ x; x ] 29 | | 3 -> [ x; x; x ] 30 | | 4 -> [ x; y ] 31 | | 5 -> [ y ] 32 | | 6 -> [ y; x ] 33 | | 7 -> [ y; x; x ] 34 | | 8 -> [ y; x; x; x ] 35 | | 9 -> [ x; z ] 36 | | _ -> assert false 37 | 38 | method private to_roman n = 39 | if n = 0 then [] 40 | else if n < 0 then assert false 41 | else if n >= 1000 then m :: self#to_roman (n - 1000) 42 | else if n >= 100 then self#digit c d m (n / 100) @ self#to_roman (n mod 100) 43 | else if n >= 10 then self#digit x l c (n / 10) @ self#to_roman (n mod 10) 44 | else self#digit i v x n 45 | 46 | method next = n <- n + 1 47 | 48 | method get = String.concat "" @@ self#to_roman n 49 | end 50 | -------------------------------------------------------------------------------- /src/expansion/default.ml: -------------------------------------------------------------------------------- 1 | let alias = Common.Ctx.AliasCtx.(empty |> add "P" "Postem") 2 | 3 | let fmt_title ~nbring ~fmt ~chr text = 4 | nbring#next; 5 | let ftext = fmt nbring#get text in 6 | Printf.sprintf "%s\n%s" ftext @@ String.(make (length ftext)) chr 7 | 8 | let underline ~char text = 9 | Printf.sprintf "%s\n%s" text @@ String.(make (length text)) char 10 | 11 | let quote = Printf.sprintf " █ %s" 12 | let conclusion = Printf.sprintf "-> %s" 13 | 14 | let bop = 15 | let open Common.Ctx.BinOpCtx in 16 | empty 17 | |> add ">>" @@ fun qtation author -> 18 | Printf.sprintf "%s\n %s" (quote qtation) author 19 | 20 | let uop = 21 | let module Enum = Enumerate.Builtins in 22 | let open Common.Ctx.UopCtx in 23 | empty 24 | |> add "&" 25 | @@ fmt_title 26 | ~nbring:(new Enum.upper_case_numeric_roman) 27 | ~fmt:(Printf.sprintf "%s - %s") ~chr:'#' 28 | |> add "&&" 29 | @@ fmt_title 30 | ~nbring:(new Enum.upper_case_latin) 31 | ~fmt:(Printf.sprintf "%s) %s") ~chr:'*' 32 | |> add "&&&" 33 | @@ fmt_title 34 | ~nbring:(new Enum.lower_case_greek) 35 | ~fmt:(Printf.sprintf "%s. %s") ~chr:'=' 36 | |> add "&&&&" @@ underline ~char:'-' 37 | |> add "&&&&&" @@ underline ~char:'^' 38 | |> add "&&&&&&" @@ underline ~char:'"' 39 | |> add ">" quote |> add "%%" Fun.id |> add "--" conclusion 40 | (* |> add ">" quote 41 | |> add "--" conclusion *) 42 | -------------------------------------------------------------------------------- /doc/lexer/lexer.py: -------------------------------------------------------------------------------- 1 | 2 | from pygments.lexer import RegexLexer, bygroups 3 | from pygments.token import Generic, Keyword, Name, Number, String, Text 4 | 5 | 6 | class PostemLexer(RegexLexer): 7 | name = 'Postem' 8 | aliases = ['postem'] 9 | 10 | tokens = { 11 | 'root': [ 12 | # Integer 13 | (r'\d+', Number.Integer), 14 | # Whitespace 15 | (r'( |\t|\r)', Text), 16 | # Alias 17 | (r'(.+)( |\t|\r)*(==)( |\t|\r)*(".*")', 18 | bygroups(Name.Variable, Text, Keyword, Text, String.Double)), 19 | # Metamark with args 20 | (r'(\.\.)(.+)( |\t|\n)([^\.\.]*)(\.\.)', bygroups(Keyword, 21 | Name.Attributes, Text, Name.Attributes, Keyword)), 22 | # Metamark without args 23 | (r'@(.+)', Name.Attributes), 24 | # Unformat 25 | (r'(\{\{)(.*)(\}\})', bygroups(Keyword, Text, Keyword)), 26 | # Conclusion 27 | (r'(--)( |\t|\n)*(.*)', bygroups(Keyword, Text, Generic.Strong)), 28 | # Definition 29 | (r'(.*)( |\t|\n)*(%%)( |\t|\n)*(.*)', 30 | bygroups(Generic.Strong, Text, Keyword, Text, Generic.Emph)), 31 | # Heading 32 | (r'&.*\n', Generic.Heading), 33 | # Subheading 34 | (r'&+.*\n', Generic.Subheading), 35 | # Quotation 36 | (r'(>)(.*)', bygroups(Keyword, Generic.Emph)), 37 | # Text 38 | (r'.', Text), 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /src/syntax/lexer.ml: -------------------------------------------------------------------------------- 1 | exception IllegalChar of Sedlexing.lexbuf 2 | 3 | let escape = [%sedlex.regexp? '\\', any] 4 | let op_char = [%sedlex.regexp? Chars "!#$%&'*+-<=>'@^_|~"] 5 | let op = [%sedlex.regexp? Plus op_char] 6 | let unformat = [%sedlex.regexp? "{{", Star any, "}}"] 7 | let white_char = [%sedlex.regexp? zs] 8 | let white = [%sedlex.regexp? Plus white_char] 9 | 10 | let text = 11 | [%sedlex.regexp? Plus (Compl (op_char | '\n' | white_char | '[' | ']'))] 12 | (* TODO: Windows newline support (\r\n) *) 13 | 14 | let newline = [%sedlex.regexp? '\n' | "\r\n"] 15 | let lexeme = Sedlexing.Utf8.lexeme 16 | 17 | let cut ?(right = 0) ~left str = 18 | String.(sub str left (length str - right - left)) 19 | 20 | let read buf = 21 | let open Parser in 22 | match%sedlex buf with 23 | | escape -> TEXT (cut ~left:1 @@ lexeme buf) 24 | | '[' -> LBRACKET 25 | | ']' -> RBRACKET 26 | | op -> OP (lexeme buf) 27 | | unformat -> UNFORMAT (cut ~left:2 ~right:2 @@ lexeme buf) 28 | | white -> WHITE (lexeme buf) 29 | | text -> TEXT (lexeme buf) 30 | | newline -> NEWLINE (lexeme buf) 31 | | eof -> EOF 32 | | _ -> raise @@ IllegalChar buf 33 | 34 | let read_debug lexbuf = 35 | let token = read lexbuf in 36 | print_endline 37 | @@ Parser.( 38 | function 39 | | NEWLINE n -> Printf.sprintf "NEWLINE:%s" n 40 | | TEXT t -> Printf.sprintf "TEXT:%s" t 41 | | WHITE w -> Printf.sprintf "WHITE:%s" w 42 | | UNFORMAT u -> Printf.sprintf "UNFORMAT:%s" u 43 | | OP o -> Printf.sprintf "OP:%s" o 44 | | LBRACKET -> "LBRACKET" 45 | | RBRACKET -> "RBRACKET" 46 | | EOF -> "EOF") 47 | token; 48 | token 49 | -------------------------------------------------------------------------------- /doc/getting_started.md: -------------------------------------------------------------------------------- 1 | # Getting started 2 | 3 | ## Command line usage 4 | 5 | ### Basics 6 | 7 | To simply print the result on stdout: 8 | ```bash 9 | $ postem -i file 10 | ``` 11 | 12 | To print the result of a direct input on stdout: 13 | ```bash 14 | $ postem -c "input" 15 | ``` 16 | 17 | To compile a text marked in **Postem** from a file and write result ``: 18 | ```bash 19 | $ postem -i file -o output 20 | ``` 21 | 22 | ### Expansions 23 | 24 | **Postem** supports a rendering customization mechanism called expansions. 25 | 26 | For a more detailed description of this feature, see the [dedicated readme](overview.md) 27 | 28 | To set the expansion used for rendering: 29 | 30 | ```bash 31 | $ postem -i file -o output -e expansion_name 32 | ``` 33 | by default, the `default` extension is used. 34 | 35 | To display on stdout the list of installed expansions and their description, pass the flag `-l`: 36 | 37 | ``` 38 | $ postem -l 39 | ``` 40 | 41 | ### References 42 | 43 | For a more precise description of command line usage, please refer to the manual page of **Postem**: 44 | 45 | ```bash 46 | $ man postem 47 | ``` 48 | 49 | or do: 50 | 51 | ```bash 52 | $ postem --help 53 | ``` 54 | 55 | ## Use Postem as an OCaml library 56 | 57 | Install **Postem** as a library: 58 | 59 | ```bash 60 | $ cd Postem-markup 61 | $ opam install . 62 | ``` 63 | 64 | Here is an example of how to get the rendering of a document from a text marked in **Postem**: 65 | ```ocaml 66 | let input = "& Hello from Postem!" 67 | 68 | let () = 69 | let result = Core.Compiler.from_str input (module Expansion.Default) in 70 | match result with 71 | | Ok output -> print_endline output 72 | | Error err -> prerr_endline err 73 | ``` 74 | 75 | Don't forget to add `postem` to the list of libraries used in your **Dune** stanza. 76 | 77 | Many other functions to interact with **Postem** are documented [here](../src/core/compiler.mli). 78 | 79 | 80 | ## Syntaxic color for Postem 81 | 82 | See the [dedicated readme](syntax_highlighting.md). 83 | -------------------------------------------------------------------------------- /man/postem.1: -------------------------------------------------------------------------------- 1 | .TH POSTEM 1 "October 2021" 2 | 3 | .SH NAME 4 | postem \- A fast and easy notes taking oriented markup language 5 | 6 | .SH SYNOPSIS 7 | .B postem 8 | [ 9 | .I 10 | OPTIONS 11 | ]... 12 | 13 | .SH DESCRIPTION 14 | 15 | The 16 | .BR postem (1) 17 | program is the toplevel system for Postem, that permits interactive use of 18 | the Postem system through a read-eval-print loop. In this mode, the system repeatedly 19 | reads Postem phrases from the input, then compiles and evaluates them, then 20 | prints the result value. 21 | 22 | A toplevel phrase can span several lines. It is terminated by pressing 23 | .B 24 | . 25 | 26 | The toplevel system is started by the program 27 | .BR postem (1). 28 | Phrases are read on standard input, results are printed on standard 29 | output, errors on standard error. 30 | 31 | By default, 32 | .BR postem (1) 33 | prints result on stdout and exit. 34 | q 35 | .SH OPTIONS 36 | 37 | The following command-line options are recognized by 38 | .BR postem (1). 39 | 40 | .TP 41 | .BI \-c \ input 42 | Postem string to parse directly. 43 | 44 | .TP 45 | .BI \-e \ expansion 46 | Set the expansion used to render input. It must be registered in 47 | .B src/expansion/know.ml 48 | . 49 | 50 | .TP 51 | .BI \-i \ file 52 | Name of the file to be evaluated. 53 | 54 | .TP 55 | .B \-l 56 | Display the list of expansion registered. 57 | 58 | .TP 59 | .BI \-o \ output 60 | Set output file name. If it does not exist, it is created. 61 | 62 | .TP 63 | .B \-version 64 | Print version string and exit. 65 | 66 | .TP 67 | .BR \-help \ or \ \-\-help 68 | Display a short usage summary and exit. 69 | 70 | .SH EXIT STATUS 71 | 72 | The following exit values are returned by 73 | .BR postem (1). 74 | 75 | .TP 76 | .B 0 77 | Successful operation. 78 | 79 | .TP 80 | .B 1 81 | An error occurred. 82 | 83 | 84 | 85 | .SH AUTHOR 86 | Timéo Arnouts 87 | 88 | .SH "SEE ALSO" 89 | 90 | The 91 | .B 92 | Postem 93 | repository 94 | . 95 | 96 | -------------------------------------------------------------------------------- /src/checker/checker.ml: -------------------------------------------------------------------------------- 1 | open Common 2 | 3 | module type S = sig 4 | val check : Syntax.Parsed_ast.t -> (Ast.Types.doc, Err.checker_err) result 5 | end 6 | 7 | module Make (Expsn : Ast.Expansion.S) : S = struct 8 | open Result 9 | 10 | type state = 11 | | Expr of Ast.Types.expr 12 | | Expand of Ast.Types.expr * Ast.Types.expr 13 | 14 | let rec check parsed_ast = 15 | List.fold_left 16 | (fun acc expr -> 17 | let+ grp = acc in 18 | let+ expr' = pexpr expr in 19 | match expr' with 20 | | Expr e -> Ok (e :: grp) 21 | | Expand (e, e') -> Ok (e :: e' :: grp)) 22 | (Ok []) 23 | @@ List.rev parsed_ast 24 | 25 | and pexpr = 26 | let open Ast.Types in 27 | let open Syntax.Parsed_ast in 28 | function 29 | | LNewline n -> ok @@ Expr (White n) 30 | | LText t -> 31 | let text = 32 | Option.value ~default:t @@ Ctx.AliasCtx.find_opt Expsn.alias t 33 | in 34 | ok @@ Expr (Text text) 35 | | LWhite w -> ok @@ Expr (White w) 36 | | LUnformat u -> ok @@ Expr (Unformat u) 37 | | LGroup g -> 38 | let+ grp = 39 | List.fold_left 40 | (fun acc expr -> 41 | let+ grp' = acc in 42 | let+ expr' = pexpr expr in 43 | match expr' with 44 | | Expr e -> Ok (e :: grp') 45 | | Expand (e, e') -> Ok (e :: e' :: grp')) 46 | (Ok []) g 47 | in 48 | ok @@ Expr (Group (List.rev grp)) 49 | | LUnaryOp { op; group; newline } -> ( 50 | match Ctx.UopCtx.find_opt Expsn.uop op.value with 51 | | None -> error @@ `UndefinedUop op.loc 52 | | Some _ -> ( 53 | let+ group = pexpr group in 54 | match group with 55 | | Expr e when newline = "" -> 56 | ok @@ Expr (UnaryOp { op = op.value; group = e }) 57 | | Expr e -> 58 | ok 59 | @@ Expand (UnaryOp { op = op.value; group = e }, White newline) 60 | | Expand (e, e') when newline = "" -> 61 | ok @@ Expr (UnaryOp { op = op.value; group = Group [ e; e' ] }) 62 | | Expand (e, e') -> 63 | ok 64 | @@ Expand 65 | ( UnaryOp { op = op.value; group = Group [ e; e' ] }, 66 | White newline ))) 67 | | LBinOp _ -> assert false(* TODO *) 68 | end 69 | -------------------------------------------------------------------------------- /src/core/args.ml: -------------------------------------------------------------------------------- 1 | type t = 2 | < direct_input : string 3 | ; inputf : string 4 | ; outputf : string 5 | ; expsn : string 6 | ; output_on_stdout : bool > 7 | 8 | class args = 9 | object 10 | val mutable direct_input = "" 11 | val mutable inputf = "" 12 | val mutable outputf = "" 13 | val mutable expsn = "default" 14 | val mutable output_on_stdout = true 15 | method direct_input = direct_input 16 | method inputf = inputf 17 | method outputf = outputf 18 | method expsn = expsn 19 | method output_on_stdout = output_on_stdout 20 | method set_direct_input i = direct_input <- i 21 | method set_inputf f = inputf <- f 22 | method set_outputf f = outputf <- f 23 | method set_expsn e = expsn <- e 24 | method set_output_on_stdout b = output_on_stdout <- b 25 | end 26 | 27 | class arg_parser ~usage_msg = 28 | object 29 | val args = new args 30 | method args = args 31 | val mutable speclist = [] 32 | 33 | method add_spec ?long short spec descr = 34 | let sshort = ("-" ^ short, spec, descr) in 35 | match long with 36 | | None -> speclist <- sshort :: speclist 37 | | Some l -> 38 | let slong = ("--" ^ l, spec, descr) in 39 | speclist <- slong :: sshort :: speclist 40 | 41 | method parse = 42 | Arg.parse speclist (fun _ -> ()) usage_msg; 43 | (args :> t) 44 | end 45 | 46 | let parse () = 47 | let p = new arg_parser ~usage_msg:"postem [OPTIONS]..." in 48 | (let open Arg in 49 | p#add_spec "c" (String p#args#set_direct_input) 50 | "Postem string to parse directly"; 51 | p#add_spec "e" ~long:"expansion" (String p#args#set_expsn) 52 | "Set the expansion used to render input"; 53 | p#add_spec "i" (String p#args#set_inputf)) 54 | "Name of the file to be evaluated."; 55 | p#add_spec "l" ~long:"list" 56 | (Unit 57 | (fun () -> 58 | print_endline 59 | @@ Ehandler.KnownExpansions.to_string Expansion.Known.expansions; 60 | exit 0)) 61 | "Display the list of known expansions and exit."; 62 | p#add_spec "o" ~long:"output" 63 | (String 64 | (fun f -> 65 | p#args#set_output_on_stdout false; 66 | p#args#set_outputf f)) 67 | "Set output file name"; 68 | p#add_spec "v" ~long:"version" 69 | (Unit 70 | (fun () -> 71 | print_endline "%%VERSION%%"; 72 | exit 0)) 73 | "Display the version number and exit"; 74 | p#parse 75 | -------------------------------------------------------------------------------- /src/common/err.ml: -------------------------------------------------------------------------------- 1 | type loc = Lexing.position * Lexing.position 2 | type checker_err = [ `UndefinedUop of loc ] 3 | type expsn_err = [ `ExpsnAmbiguity of string | `UnknownExpsn of string ] 4 | type parser_err = [ `IllegalCharacter of loc | `SyntaxError of loc ] 5 | type t = [ checker_err | expsn_err | parser_err | `NoSuchFile of string ] 6 | 7 | let get_line ic n = 8 | try 9 | let i = ref 1 in 10 | while !i < n do 11 | let _ = input_line ic in 12 | incr i 13 | done; 14 | input_line ic 15 | with End_of_file -> assert false 16 | 17 | (* TODO: Fix Sys_error exception in REPL error. *) 18 | let rec pp_loc ?hint ~msg (spos, epos) = 19 | let schar = Lexing.(spos.pos_cnum - spos.pos_bol) in 20 | let echar = Lexing.(epos.pos_cnum - epos.pos_bol) in 21 | let char_pos = 22 | if echar = 0 then Int.to_string schar 23 | else Printf.sprintf "%d-%d" schar echar 24 | in 25 | let carret = 26 | Printf.sprintf {|File "%s", line %i, characters %s:|} epos.Lexing.pos_fname 27 | spos.Lexing.pos_lnum char_pos 28 | in 29 | let overview = 30 | let line = get_line (open_in epos.Lexing.pos_fname) spos.Lexing.pos_lnum in 31 | let margin = 32 | String.make 33 | (schar + (spos.Lexing.pos_lnum |> string_of_int |> String.length)) 34 | ' ' 35 | in 36 | let cursor = if echar <= 0 then "^" else String.make (echar - schar) '^' in 37 | Printf.sprintf "%d | %s\n %s%s" spos.Lexing.pos_lnum line margin cursor 38 | in 39 | let descr = 40 | match hint with None -> pp_string msg | Some hint -> pp_string msg ~hint 41 | in 42 | Printf.sprintf "%s\n%s\n%s" carret overview descr 43 | 44 | and pp_string ?hint msg = 45 | let err = Printf.sprintf "Error: %s" msg in 46 | Option.fold ~none:err 47 | ~some:(fun h -> Printf.sprintf "%s\nHint: %s" err h) 48 | hint 49 | 50 | let to_string = function 51 | | `UndefinedUop loc -> pp_loc loc ~msg:"Undefined op" 52 | | `ExpsnAmbiguity name -> 53 | pp_string 54 | ~hint:"Did you register your extension in src/expansion/known.ml?" 55 | @@ Printf.sprintf {|No extension found as "%s"|} name 56 | | `UnknownExpsn name -> 57 | pp_string 58 | @@ Printf.sprintf 59 | {|Ambiguity found: several extensions are known as "%s"|} name 60 | | `IllegalCharacter loc -> 61 | pp_loc loc ~msg:"Character not allowed in source text" 62 | ~hint:"try to escape this character" 63 | | `SyntaxError loc -> pp_loc loc ~msg:"Syntax error" 64 | | `NoSuchFile filename -> 65 | pp_string @@ Printf.sprintf "%s: no such file" filename 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Postem 2 | 3 | A lightweight WIP **markup** language designed for quick note taking. 4 | 5 | ## Abstracts 6 | 7 | **Markdown** is pretty simple and powerful, but not suitable for note taking. **LaTeX** has a very heavy syntax that makes it complicated to write although very complete. **Postem** offers an in-between to quickly structure a text and compile it to other more conventional formats. 8 | 9 | ## Key Features 10 | 11 | * **Lightweight:** a light syntax. 12 | * **Flexible:** it compiles to other famous markup languages such as **AsciiDoc** and **Markdown**. 13 | * **Extensible:** it is very easy to create an expansion to customize the rendering or extend available tags set using **OCaml**. 14 | 15 | #### Not yet implemented 16 | 17 | * Compilation to [**Pandoc**](https://github.com/jgm/pandoc) format 18 | 19 | ## Examples 20 | 21 | This text marked in Postem: 22 | ```text 23 | & Postem 24 | 25 | && Philosophy 26 | 27 | P aims to be a lightweight markup language designed for note taking. 28 | It is also intended to be easily extensible by allowing extension writing in OCaml. 29 | 30 | && Features 31 | 32 | P supports alias definition and custom operator definition. 33 | 34 | && Builtins marks 35 | 36 | There are six builtins title tags: 37 | {{& for a level one title, && for a level two title, and this up to 6.}} 38 | 39 | By the way, the line above is unformated because it is put between two curly brackets. 40 | This avoids the need to individually escape each operator. 41 | 42 | > There are also quotes 43 | 44 | > On one or on 45 | > several lines 46 | 47 | -- The \-\- mark allows you to formulate a conclusion. 48 | ``` 49 | will be rendered in this (with default expansion enabled): 50 |
51 | Output 52 | 53 | ```text 54 | I - Postem 55 | ########## 56 | 57 | A) Philosophy 58 | ************* 59 | 60 | Postem aims to be a lightweight markup language designed for note taking. 61 | It is also intended to be easily extensible by allowing extension writing in OCaml. 62 | 63 | B) Features 64 | *********** 65 | 66 | Postem supports alias definition and custom operator definition. 67 | 68 | C) Builtins marks 69 | ***************** 70 | 71 | There are six builtins title tags: 72 | & for a level one title, && for a level two title, and this up to 6. 73 | 74 | By the way, the line above is unformated because it is put between two curly brackets. 75 | This avoids the need to individually escape each operator. 76 | 77 | █ There are also quotes 78 | 79 | █ On one or on 80 | █ several lines 81 | 82 | -> The -- mark allows you to formulate a conclusion. 83 | ``` 84 | 85 |
86 | 87 | ## Getting started with Postem 88 | 89 | See the [dedicated readme](doc/getting_started.md). 90 | 91 | ## Installing 92 | 93 | Check for missing dependencies: 94 | ``` 95 | $ make deps 96 | ``` 97 | 98 | Then install Postem: 99 | ``` 100 | $ make install 101 | ``` 102 | 103 | This will install **Postem** (make it runnable) and man pages in the dedicated folders. 104 | 105 | ## Contributing 106 | 107 | Pull requests, bug reports, and feature requests are welcome. 108 | 109 | ## License 110 | 111 | - **GPL 3.0** or later. See [license](LICENSE) for more information. 112 | -------------------------------------------------------------------------------- /src/common/enumerate/builtins.ml: -------------------------------------------------------------------------------- 1 | class null = 2 | object 3 | inherit Base.numerotation 4 | method next = () 5 | method get = "" 6 | end 7 | 8 | class numeric_arab = 9 | object 10 | inherit Base.numerotation 11 | val mutable current = 0 12 | method next = current <- current + 1 13 | method get = Int.to_string current 14 | end 15 | 16 | class lower_case_numeric_roman = 17 | object 18 | inherit 19 | Base.roman (`I "i") (`V "v") (`X "x") (`L "l") (`C "c") (`D "d") (`M "m") 20 | end 21 | 22 | class upper_case_numeric_roman = 23 | object 24 | inherit 25 | Base.roman (`I "I") (`V "V") (`X "X") (`L "L") (`C "C") (`D "D") (`M "M") 26 | end 27 | 28 | class lower_case_latin = 29 | object 30 | inherit 31 | Base.alphabet 32 | (Array.init 26 (fun i -> String.make 1 @@ Char.chr @@ (i + 97))) 33 | end 34 | 35 | class upper_case_latin = 36 | object 37 | inherit 38 | Base.alphabet 39 | (Array.init 26 (fun i -> String.make 1 @@ Char.chr @@ (i + 65))) 40 | end 41 | 42 | class lower_case_greek = 43 | object 44 | inherit 45 | Base.alphabet 46 | [| 47 | "α"; 48 | "β"; 49 | "γ"; 50 | "δ"; 51 | "ε"; 52 | "ζ"; 53 | "η"; 54 | "θ"; 55 | "ι"; 56 | "κ"; 57 | "λ"; 58 | "μ"; 59 | "ν"; 60 | "ξ"; 61 | "ο"; 62 | "π"; 63 | "ρ"; 64 | "σ"; 65 | "τ"; 66 | "υ"; 67 | "φ"; 68 | "χ"; 69 | "ψ"; 70 | "ω"; 71 | |] 72 | end 73 | 74 | class upper_case_greek = 75 | object 76 | inherit 77 | Base.alphabet 78 | [| 79 | "Α"; 80 | "Β"; 81 | "Γ"; 82 | "Δ"; 83 | "Ε"; 84 | "Ζ"; 85 | "Η"; 86 | "Θ"; 87 | "Ι"; 88 | "Κ"; 89 | "Λ"; 90 | "Μ"; 91 | "Ν"; 92 | "Ξ"; 93 | "Ο"; 94 | "Π"; 95 | "Ρ"; 96 | "Σ"; 97 | "Τ"; 98 | "Υ"; 99 | "Φ"; 100 | "Χ"; 101 | "Ψ"; 102 | "Ω"; 103 | |] 104 | end 105 | 106 | class lower_case_cyrillic = 107 | object 108 | inherit 109 | Base.alphabet 110 | [| 111 | "а"; 112 | "б"; 113 | "в"; 114 | "г"; 115 | "д"; 116 | "е"; 117 | "ё"; 118 | "ж"; 119 | "з"; 120 | "и"; 121 | "й"; 122 | "і"; 123 | "к"; 124 | "л"; 125 | "м"; 126 | "н"; 127 | "о"; 128 | "п"; 129 | "р"; 130 | "с"; 131 | "т"; 132 | "у"; 133 | "ф"; 134 | "х"; 135 | "ц"; 136 | "ч"; 137 | "ш"; 138 | "щ"; 139 | "ъ"; 140 | "ы"; 141 | "ь"; 142 | "ѣ"; 143 | "э"; 144 | "ю"; 145 | "я"; 146 | "ѳ"; 147 | "ѵ"; 148 | |] 149 | end 150 | 151 | class upper_case_cyrillc = 152 | object 153 | inherit 154 | Base.alphabet 155 | [| 156 | "А"; 157 | "Б"; 158 | "В"; 159 | "Г"; 160 | "Д"; 161 | "Е"; 162 | "Ё"; 163 | "Ж"; 164 | "З"; 165 | "И"; 166 | "Й"; 167 | "и"; 168 | "І"; 169 | "К"; 170 | "Л"; 171 | "М"; 172 | "Н"; 173 | "О"; 174 | "П"; 175 | "Р"; 176 | "С"; 177 | "Т"; 178 | "У"; 179 | "Ф"; 180 | "Х"; 181 | "Ц"; 182 | "Ч"; 183 | "Ш"; 184 | "Щ"; 185 | "Ъ"; 186 | "Ы"; 187 | "Ь"; 188 | "Ѣ"; 189 | "Э"; 190 | "Ю"; 191 | "Я"; 192 | "Ѳ"; 193 | "Ѵ"; 194 | |] 195 | end 196 | -------------------------------------------------------------------------------- /doc/book/grammar.tex: -------------------------------------------------------------------------------- 1 | \part{Grammar}\label{part:grammar} 2 | 3 | \section{Literals} 4 | 5 | \subsection{Text} 6 | 7 | \begin{bnf*} 8 | \bnfprod{char} 9 | {\bnfts{A} \bnfsk \bnfts{Z} \bnfor 10 | \bnfts{a} \bnfsk\bnfts{z} \bnfor 11 | \bnfts{0} \bnfsk \bnfts{9} \bnfor}\\ 12 | \bnfmore{\bnfts{!} \bnfor \bnfts{"} \bnfor \bnfts{\#} \bnfor \bnfts{\$} \bnfor \bnfts{\%} \bnfor \bnfts{\&} \bnfor}\\ 13 | \bnfmore{\bnfts{\textquotesingle} \bnfor \bnfts{)} \bnfor \bnfts{(} \bnfor \bnfts{*} \bnfor \bnfts{+} \bnfor \bnfts{,} \bnfor}\\ 14 | \bnfmore{\bnfts{-} \bnfor \bnfts{.} \bnfor \bnfts{/} \bnfor \bnfts{:} \bnfor \bnfts{;} \bnfor \bnfts{<} \bnfor}\\ 15 | \bnfmore{\bnfts{=} \bnfor \bnfts{>} \bnfor \bnfts{?} \bnfor \bnfts{`} \bnfor \bnfts{\textasciitilde} \bnfor \bnfts{]} \bnfor}\\ 16 | \bnfmore{\bnfts{[} \bnfor \bnfts{\textasciicircum} \bnfor \bnfts{\_} \bnfor \bnfts{\{} \bnfor \bnfts{|} \bnfor \bnfts{\}}}\\ 17 | \bnfprod{alpha} 18 | {\bnfts{A} \bnfsk \bnfts{Z} \bnfor 19 | \bnfts{a} \bnfsk\bnfts{z}}\\ 20 | \bnfprod{text-literal} 21 | {\bnfpn{alpha} \bnfpn{char} \bnfts{*}} 22 | \end{bnf*} 23 | 24 | \subsection{Whitespace} 25 | 26 | \begin{bnf*} 27 | \bnfprod{whitespace-literal} 28 | {\bnfts{‘\hspace{1em}’} \bnfor} 29 | \bnfts{\textbackslash t} \bnfor \bnfts{\textbackslash r} 30 | \end{bnf*} 31 | 32 | \section{Statment} 33 | 34 | \subsection{Alias} 35 | 36 | \begin{bnf*} 37 | \bnfprod{alias-equality} 38 | {\bnfts{==}}\\ 39 | \bnfprod{alias-value} 40 | {\bnfts{"} \bnfpn{any-char} \bnfts{"}}\\ 41 | \bnfprod{alias-statment} 42 | {\bnfpn{text} \bnfts{[} \bnfpn{whitespace-literal} \bnfts{]} \bnfpn{alias-equality}}\\ 43 | \bnfmore{\bnfts{[} \bnfpn{whitespace-literal} \bnfts{]} \bnfpn{alias-value}} 44 | \end{bnf*} 45 | 46 | \subsection{Metamark with arguments} 47 | 48 | \begin{bnf*} 49 | \bnfprod{newline} 50 | {\bnfts{\textbackslash n} \bnfor \bnfts{\textbackslash r \textbackslash n} \bnfor \bnfpn{whitespace-literal}}\\ 51 | \bnfprod{meta-name} 52 | {\bnfpn{char} \bnfts{+}}\\ 53 | \bnfprod{meta-content} 54 | {\bnfpn{char} \bnfts{+}}\\ 55 | \bnfprod{metamark-args-statment} 56 | {\bnfts{..} \bnfpn{meta-name} \bnfpn{whitespace-literal} \bnfpn{char} \bnfts{..}} 57 | \end{bnf*} 58 | 59 | \subsection{Metamark without arguments} 60 | 61 | \begin{bnf*} 62 | \bnfprod{newline} 63 | {\bnfts{\textbackslash n} \bnfor \bnfts{\textbackslash r \textbackslash n} \bnfor \bnfpn{whitespace-literal}}\\ 64 | \bnfprod{meta-name} 65 | {\bnfpn{char} \bnfts{+}}\\ 66 | \bnfprod{metamark-single-statment} 67 | {\bnfts{@} \bnfpn{meta-name}} 68 | \end{bnf*} 69 | 70 | \subsection{Unformat} 71 | 72 | \begin{bnf*} 73 | \bnfprod{unformat-statment} 74 | {\bnfts{\{\{} \bnfpn{any-char} \bnfts{\}\}}} 75 | \end{bnf*} 76 | 77 | \subsection{Sequence} 78 | 79 | \begin{bnf*} 80 | \bnfprod{expression} 81 | {\bnfpn{text} \bnfor \bnfpn{whitespace} \bnfor \bnfpn{alias-statment} \bnfor}\\ 82 | \bnfmore{\bnfpn{metamark-single-statment} \bnfor \bnfpn{metamark-args-statment} \bnfor}\\ 83 | \bnfmore{ \bnfpn{unformat-statment}}\\ 84 | \bnfprod{sequence-statment} 85 | {\bnfpn{expression} \bnfts{+}} 86 | \end{bnf*} 87 | 88 | \section{Block} 89 | 90 | \subsection{Conclusion} 91 | 92 | \begin{bnf*} 93 | \bnfprod{conclusion-begin} 94 | {\bnfts{--} \bnfts{[} \bnfpn{whitespace-literal} \bnfts{]}}\\ 95 | \bnfprod{conclusion-block} 96 | {\bnfpn{conclusion-begin} \bnfpn{sequence-statment}} 97 | \end{bnf*} 98 | 99 | \subsection{Definition} 100 | 101 | \begin{bnf*} 102 | \bnfprod{definition-equality} 103 | {\bnfts{\%\%}}\\ 104 | \bnfprod{definition-block} 105 | {\bnfpn{sequence-statment} \bnfts{[} \bnfpn{whitespace-literal} \bnfts{]}}\\ 106 | \bnfmore{\bnfpn{definition-equality} \bnfts{[} \bnfpn{whitespace-literal} \bnfts{]}}\\ 107 | \bnfmore{\bnfpn{sequence-statment}} 108 | \end{bnf*} 109 | 110 | \subsection{Heading} 111 | 112 | \begin{bnf*} 113 | \bnfprod{heading-mark} 114 | {\bnfts{\&}}\\ 115 | \bnfprod{heading-block} 116 | {\bnfpn{heading-mark} \bnfts{+} \bnfts{[} \bnfpn{whitespace-literal} \bnfts{]} \bnfpn{sequence-statment}} 117 | \end{bnf*} 118 | 119 | \subsection{Quotation} 120 | 121 | \begin{bnf*} 122 | \bnfprod{quotation-begin} 123 | {\bnfts{>} \bnfts{[} \bnfpn{whitespace-literal} \bnfts{]}}\\ 124 | \bnfprod{conclusion-block} 125 | {\bnfpn{quotation-begin} \bnfpn{sequence-statment}} 126 | \end{bnf*} 127 | 128 | \section{Document} 129 | 130 | \begin{bnf*} 131 | \bnfprod{paragraph} 132 | {\bnfpn{conclusion-block} \bnfor \bnfpn{definition-block} \bnfor}\\ 133 | \bnfmore{ \bnfpn{heading-block} \bnfor \bnfpn{quotation-block} \bnfor}\\ 134 | \bnfmore{\bnfpn{sequence-statment}}\\ 135 | \bnfprod{newline} 136 | {\bnfts{\textbackslash n} \bnfor \bnfts{\textbackslash r \textbackslash n}}\\ 137 | \bnfprod{separator} 138 | {\bnfpn{newline} \bnfpn{newline} \bnfts{+}}\\ 139 | \bnfprod{document} 140 | {\bnfpn{paragraph} \bnfts{(} \bnfpn{separator} \bnfpn{paragraph} \bnfts{)*}} 141 | \end{bnf*} 142 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------