├── README ├── peg-0.1.9 ├── examples │ ├── dc.ref │ ├── calc.ref │ ├── dcv.ref │ ├── left.peg │ ├── test.c │ ├── rule.c │ ├── accept.c │ ├── test.ref │ ├── localctx.ref │ ├── bench.bas │ ├── basic.ref │ ├── test.bas │ ├── localctx.c │ ├── username.leg │ ├── accept.ref │ ├── dc.c │ ├── fibonacci.bas │ ├── rule.peg │ ├── rule.ref │ ├── accept.peg │ ├── left.c │ ├── dcv.c │ ├── wc.leg │ ├── test.peg │ ├── wc.ref │ ├── dc.peg │ ├── calc.leg │ ├── dcv.peg │ ├── Makefile │ └── basic.leg ├── version.h ├── Makefile ├── peg.peg ├── tree.h ├── peg.c ├── leg.leg └── tree.c ├── windows_installer ├── mmd.bat ├── install_multimarkdown.bat ├── mmd2odf.bat ├── Installer support files │ └── logotype.png ├── mmd2opml.bat ├── mmd2tex.bat └── multimarkdown.xml ├── update_submodules.sh ├── odf.h ├── MMD-Compat.xcodeproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── fletcher.xcuserdatad │ └── xcschemes │ ├── xcschememanagement.plist │ ├── Peg.xcscheme │ ├── Run Tests.xcscheme │ ├── MakefileBuild.xcscheme │ ├── libMultiMarkdown.xcscheme │ └── MultiMarkdown.xcscheme ├── MarkdownMacPrefix.h ├── glib.h ├── Configuration ├── Release.xcconfig ├── Debug.xcconfig ├── Release10.6+.xcconfig └── Common.xcconfig ├── mac_installer ├── Resources │ ├── Welcome.txt │ └── Support_Welcome.txt ├── README.markdown ├── Make OS X Installer.pmdoc │ ├── 01package.xml │ ├── index.xml │ └── 01package-contents.xml └── Make Support Installer.pmdoc │ ├── 01library.xml │ └── index.xml ├── .gitmodules ├── scripts ├── mmd ├── mmd2opml ├── mmd2tex ├── mmd2odf ├── mmd2all └── mmd2pdf ├── TODO.txt ├── .gitignore ├── parsing_functions.h ├── markdown_lib.h ├── GLibFacade.h ├── LICENSE ├── utility_functions.h ├── markdown_peg.h ├── parsing_functions.c ├── GLibFacade.c ├── Makefile ├── markdown_lib.c ├── odf.c ├── markdown.c ├── README.markdown └── utility_functions.c /README: -------------------------------------------------------------------------------- 1 | README.markdown -------------------------------------------------------------------------------- /peg-0.1.9/examples/dc.ref: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/calc.ref: -------------------------------------------------------------------------------- 1 | 6 2 | 7 3 | 42 4 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/dcv.ref: -------------------------------------------------------------------------------- 1 | 6 2 | 7 3 | 42 4 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/left.peg: -------------------------------------------------------------------------------- 1 | # Grammar 2 | 3 | S <- (S 'a' / 'a') !'a' 4 | -------------------------------------------------------------------------------- /peg-0.1.9/version.h: -------------------------------------------------------------------------------- 1 | #define PEG_MAJOR 0 2 | #define PEG_MINOR 1 3 | #define PEG_LEVEL 9 4 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "test.peg.c" 3 | 4 | int main() 5 | { 6 | while (yyparse()); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /windows_installer/mmd.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | :Loop 3 | IF "%1"=="" GOTO Continue 4 | multimarkdown -b %1 5 | SHIFT 6 | GOTO Loop 7 | :Continue 8 | 9 | -------------------------------------------------------------------------------- /update_submodules.sh: -------------------------------------------------------------------------------- 1 | # Run this script to update the various submodules linked to 2 | # from this project 3 | 4 | git submodule init 5 | git submodule update 6 | -------------------------------------------------------------------------------- /windows_installer/install_multimarkdown.bat: -------------------------------------------------------------------------------- 1 | move *.dll C:\WINDOWS\system32 2 | move mmd*.bat C:\WINDOWS\system32 3 | move multimarkdown.exe C:\WINDOWS\system32 -------------------------------------------------------------------------------- /windows_installer/mmd2odf.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | :Loop 3 | IF "%1"=="" GOTO Continue 4 | multimarkdown -b -t odf %1 5 | SHIFT 6 | GOTO Loop 7 | :Continue 8 | 9 | -------------------------------------------------------------------------------- /windows_installer/Installer support files/logotype.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fletcher/peg-multimarkdown/HEAD/windows_installer/Installer support files/logotype.png -------------------------------------------------------------------------------- /windows_installer/mmd2opml.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | :Loop 3 | IF "%1"=="" GOTO Continue 4 | multimarkdown -b -t opml %1 5 | SHIFT 6 | GOTO Loop 7 | :Continue 8 | 9 | -------------------------------------------------------------------------------- /windows_installer/mmd2tex.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | :Loop 3 | IF "%1"=="" GOTO Continue 4 | multimarkdown -b -t latex %1 5 | SHIFT 6 | GOTO Loop 7 | :Continue 8 | 9 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/rule.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "rule.peg.c" 5 | 6 | int main() 7 | { 8 | while (yyparse()); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/accept.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "accept.peg.c" 5 | 6 | int main() 7 | { 8 | while (yyparse()); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/test.ref: -------------------------------------------------------------------------------- 1 | a1 ab1 . 2 | a2 ac2 . 3 | a3 ad3 . 4 | a3 ae3 . 5 | a4 af4 afg4 . 6 | a4 af5 afh5 . 7 | a4 af4 afg4 . 8 | a4 af5 afh5 . 9 | af6 afi6 a6 . 10 | af6 af7 afj7 a6 . 11 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/localctx.ref: -------------------------------------------------------------------------------- 1 | a1 ab1 . 2 | a2 ac2 . 3 | a3 ad3 . 4 | a3 ae3 . 5 | a4 af4 afg4 . 6 | a4 af5 afh5 . 7 | a4 af4 afg4 . 8 | a4 af5 afh5 . 9 | af6 afi6 a6 . 10 | af6 af7 afj7 a6 . 11 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/bench.bas: -------------------------------------------------------------------------------- 1 | 100 let n=100000 2 | 120 let m=0 3 | 110 let s=0 4 | 130 let m=m+1 5 | 140 let s=s+m 6 | 150 if m 5 | #include 6 | #include 7 | 8 | void print_odf_header(GString *out); 9 | void print_odf_footer(GString *out); 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/basic.ref: -------------------------------------------------------------------------------- 1 | 1 2 | 2 4 3 | 3 6 9 4 | 4 8 12 16 5 | 5 10 15 20 25 6 | 6 12 18 24 30 36 7 | 7 14 21 28 35 42 49 8 | 8 16 24 32 40 48 56 64 9 | 9 18 27 36 45 54 63 72 81 10 | 10 20 30 40 50 60 70 80 90 100 11 | -------------------------------------------------------------------------------- /MMD-Compat.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/test.bas: -------------------------------------------------------------------------------- 1 | 10 let i=1 2 | 20 gosub 100 3 | 30 let i=i+1 4 | 40 if i<=10 then goto 20 5 | 50 end 6 | 7 | 100 let j=1 8 | 110 print " ", i*j, 9 | 120 let j=j+1 10 | 130 if j<=i then goto 110 11 | 140 print 12 | 150 return 13 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/localctx.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define YY_CTX_LOCAL 4 | 5 | #include "test.peg.c" 6 | 7 | int main() 8 | { 9 | yycontext ctx; 10 | memset(&ctx, 0, sizeof(yycontext)); 11 | while (yyparse(&ctx)); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/username.leg: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | %} 4 | 5 | start = "username" { printf("%s", getlogin()); } 6 | | < . > { putchar(yytext[0]); } 7 | 8 | %% 9 | 10 | int main() 11 | { 12 | while (yyparse()); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /MarkdownMacPrefix.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #import "GLibFacade.h" 5 | #import "markdown_lib.h" 6 | 7 | #define link PEG_link 8 | #define STR PEG_STR 9 | #import "markdown_peg.h" 10 | 11 | // peg 12 | #define Class PEG_Class 13 | #import "tree.h" 14 | #undef Class 15 | 16 | -------------------------------------------------------------------------------- /glib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * glib.h 3 | * MultiMarkdown 4 | * 5 | * Created by Daniel Jalkut on 7/26/11. 6 | * Copyright 2011 __MyCompanyName__. All rights reserved. 7 | * 8 | */ 9 | 10 | /* Just a dummy file to keep the glib-dependent sources compiling as we would hope */ 11 | #include "GLibFacade.h" 12 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/accept.ref: -------------------------------------------------------------------------------- 1 | A 3 2 | B 3 3 | C 3 4 | ABC 3 5 | B 3 6 | C 3 7 | D 3 8 | BCD 3 9 | A 3 10 | B 3 11 | C 3 12 | ABC 3 13 | B 3 14 | C 3 15 | D 3 16 | BCD 3 17 | A 3 18 | B 3 19 | C 3 20 | ABC 3 21 | B 3 22 | C 3 23 | D 3 24 | BCD 3 25 | A 3 26 | B 3 27 | C 3 28 | ABC 3 29 | B 3 30 | C 3 31 | D 3 32 | BCD 3 33 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/dc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int stack[1024]; 5 | int stackp= -1; 6 | 7 | int push(int n) { return stack[++stackp]= n; } 8 | int pop(void) { return stack[stackp--]; } 9 | 10 | #include "dc.peg.c" 11 | 12 | int main() 13 | { 14 | while (yyparse()); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Configuration/Release.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Release10.6+.xcconfig 3 | // MultiMarkdown 4 | // 5 | // Created by Daniel Jalkut on 7/29/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #include "Common.xcconfig" 10 | 11 | COPY_PHASE_STRIP = NO 12 | STRIP_INSTALLED_PRODUCT = YES 13 | SEPARATE_STRIP = YES 14 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/fibonacci.bas: -------------------------------------------------------------------------------- 1 | 100 let n=32 2 | 110 gosub 200 3 | 120 print "fibonacci(",n,") = ", m 4 | 130 end 5 | 6 | 200 let c=n 7 | 210 let b=1 8 | 220 if c<2 then goto 400 9 | 230 let c=c-1 10 | 240 let a=1 11 | 300 let c=c-1 12 | 310 let d=a+b 13 | 320 let a=b 14 | 330 let b=d+1 15 | 340 if c<>0 then goto 300 16 | 400 let m=b 17 | 410 return 18 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/rule.peg: -------------------------------------------------------------------------------- 1 | start <- abcd+ 2 | 3 | abcd <- 'a' { printf("A %d\n", yypos); } bc { printf("ABC %d\n", yypos); } 4 | / 'b' { printf("B %d\n", yypos); } cd { printf("BCD %d\n", yypos); } 5 | 6 | bc <- 'b' { printf("B %d\n", yypos); } 'c' { printf("C %d\n", yypos); } 7 | 8 | cd <- 'c' { printf("C %d\n", yypos); } 'd' { printf("D %d\n", yypos); } 9 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/rule.ref: -------------------------------------------------------------------------------- 1 | A 24 2 | B 24 3 | C 24 4 | ABC 24 5 | B 24 6 | C 24 7 | D 24 8 | BCD 24 9 | A 24 10 | B 24 11 | C 24 12 | ABC 24 13 | B 24 14 | C 24 15 | D 24 16 | BCD 24 17 | A 24 18 | B 24 19 | C 24 20 | ABC 24 21 | B 24 22 | C 24 23 | D 24 24 | BCD 24 25 | A 24 26 | B 24 27 | C 24 28 | ABC 24 29 | B 24 30 | C 24 31 | D 24 32 | BCD 24 33 | -------------------------------------------------------------------------------- /Configuration/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Release10.6+.xcconfig 3 | // MultiMarkdown 4 | // 5 | // Created by Daniel Jalkut on 7/29/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #include "Common.xcconfig" 10 | 11 | ARCHS = i386 ppc x86_64 12 | ONLY_ACTIVE_ARCH = YES 13 | GCC_OPTIMIZATION_LEVEL = 0 14 | DEPLOYMENT_POSTPROCESSING = NO 15 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/accept.peg: -------------------------------------------------------------------------------- 1 | start <- abcd+ 2 | 3 | abcd <- 'a' { printf("A %d\n", yypos); } bc { printf("ABC %d\n", yypos); } &{YYACCEPT} 4 | / 'b' { printf("B %d\n", yypos); } cd { printf("BCD %d\n", yypos); } &{YYACCEPT} 5 | 6 | bc <- 'b' { printf("B %d\n", yypos); } 'c' { printf("C %d\n", yypos); } 7 | 8 | cd <- 'c' { printf("C %d\n", yypos); } 'd' { printf("D %d\n", yypos); } 9 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/left.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define YY_INPUT(buf, result, max) \ 4 | { \ 5 | int c= getchar(); \ 6 | result= (EOF == c) ? 0 : (*(buf)= c, 1); \ 7 | if (EOF != c) printf("<%c>\n", c); \ 8 | } 9 | 10 | #include "left.peg.c" 11 | 12 | int main() 13 | { 14 | printf(yyparse() ? "success\n" : "failure\n"); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/dcv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int stack[1024]; 5 | int stackp= -1; 6 | int var= 0; 7 | int vars[26]; 8 | 9 | int push(int n) { return stack[++stackp]= n; } 10 | int pop(void) { return stack[stackp--]; } 11 | int top(void) { return stack[stackp]; } 12 | 13 | #include "dcv.peg.c" 14 | 15 | int main() 16 | { 17 | while (yyparse()); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /mac_installer/Resources/Welcome.txt: -------------------------------------------------------------------------------- 1 | Title: Installer Welcome Message 2 | 3 | This custom installer will install **MultiMarkdown** and several convenience scripts to serve as shortcuts for using MultiMarkdown from the command line. 4 | 5 | 6 | For more information, please check out the MultiMarkdown [web 7 | site](http://fletcherpenney.net/multimarkdown/). 8 | 9 | You will be guided through the steps necessary to install this software. -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "MarkdownTest"] 2 | path = MarkdownTest 3 | url = https://github.com/fletcher/MMD-Test-Suite.git 4 | [submodule "Support"] 5 | path = Support 6 | url = https://github.com/fletcher/MMD-Support.git 7 | [submodule "documentation"] 8 | path = documentation 9 | url = https://github.com/fletcher/peg-multimarkdown.wiki.git 10 | [submodule "samples"] 11 | path = samples 12 | url = https://github.com/fletcher/MultiMarkdown-Gallery.git 13 | -------------------------------------------------------------------------------- /scripts/mmd: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # mmd --- MultiMarkdown convenience script 4 | # 5 | # Fletcher T. Penney 6 | # 7 | # Pass arguments on to the binary to convert text to XHTML 8 | # 9 | 10 | # Be sure to include multimarkdown in our PATH 11 | export PATH="/usr/local/bin:$PATH" 12 | 13 | if [ $# = 0 ] 14 | then 15 | multimarkdown 16 | else 17 | until [ "$*" = "" ] 18 | do 19 | multimarkdown -b "$1" 20 | shift 21 | done 22 | fi 23 | -------------------------------------------------------------------------------- /mac_installer/README.markdown: -------------------------------------------------------------------------------- 1 | 2 | To create an installer for Mac OS X: 3 | 4 | * `make` peg-multimarkdown 5 | 6 | * `make test`, `make mmdtest`, `make latextest` to be sure everything worked 7 | properly 8 | 9 | * `make installer` to copy the binary into the proper folder 10 | 11 | * open the `Make OS X Installer` file and select "Build" 12 | 13 | You can now run the installer or distribute it to others. You can also modify 14 | the other resource files to add to the Readme, etc. -------------------------------------------------------------------------------- /scripts/mmd2opml: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # mmd2opml --- MultiMarkdown convenience script 4 | # 5 | # Fletcher T. Penney 6 | # 7 | # Pass arguments on to the binary to convert text to OPML 8 | # 9 | 10 | # Be sure to include multimarkdown in our PATH 11 | export PATH="/usr/local/bin:$PATH" 12 | 13 | if [ $# = 0 ] 14 | then 15 | multimarkdown -t opml 16 | else 17 | until [ "$*" = "" ] 18 | do 19 | multimarkdown -b -t opml "$1" 20 | shift 21 | done 22 | fi 23 | -------------------------------------------------------------------------------- /scripts/mmd2tex: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # mmd2tex --- MultiMarkdown convenience script 4 | # 5 | # Fletcher T. Penney 6 | # 7 | # Pass arguments on to the binary to convert text to LaTeX 8 | # 9 | 10 | # Be sure to include multimarkdown in our PATH 11 | export PATH="/usr/local/bin:$PATH" 12 | 13 | if [ $# = 0 ] 14 | then 15 | multimarkdown -t latex 16 | else 17 | until [ "$*" = "" ] 18 | do 19 | multimarkdown -b -t latex "$1" 20 | shift 21 | done 22 | fi 23 | -------------------------------------------------------------------------------- /scripts/mmd2odf: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # mmd2odf --- MultiMarkdown convenience script 4 | # 5 | # Fletcher T. Penney 6 | # 7 | # Pass arguments on to the binary to convert text to OpenDocument 8 | # 9 | 10 | # Be sure to include multimarkdown in our PATH 11 | export PATH="/usr/local/bin:$PATH" 12 | 13 | if [ $# = 0 ] 14 | then 15 | multimarkdown -t odf 16 | else 17 | until [ "$*" = "" ] 18 | do 19 | multimarkdown -b -t odf "$1" 20 | shift 21 | done 22 | fi 23 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/wc.leg: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | int lines= 0, words= 0, chars= 0; 4 | %} 5 | 6 | start = (line | word | char) 7 | 8 | line = < (( '\n' '\r'* ) | ( '\r' '\n'* )) > { lines++; chars += yyleng; } 9 | word = < [a-zA-Z]+ > { words++; chars += yyleng; printf("<%s>\n", yytext); } 10 | char = . { chars++; } 11 | 12 | %% 13 | 14 | int main() 15 | { 16 | while (yyparse()) 17 | ; 18 | printf("%d lines\n", lines); 19 | printf("%d chars\n", chars); 20 | printf("%d words\n", words); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /TODO.txt: -------------------------------------------------------------------------------- 1 | Notes for myself while pulling together the remaining lose ends in MultiMarkdown standalone for Mac. 2 | 3 | CURRENT: 4 | 5 | ? 6 | 7 | HISTORY: 8 | 9 | - Fix short options parsing in markdown.c 10 | 11 | - Performance tests - compare with a very large markdown file vs. e.g. multimarkdown based on GLib. 12 | - Performance now seems approximately on par with the GLib version for massive files 13 | - Garbage output e.g. when processing unicode within tags:

14 | - This went away with removal of NSString from the GString printf-append function. 15 | 16 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/test.peg: -------------------------------------------------------------------------------- 1 | start <- body '.' { printf(".\n"); } 2 | 3 | body <- 'a' { printf("a1 "); } 'b' { printf("ab1 "); } 4 | 5 | / 'a' { printf("a2 "); } 'c' { printf("ac2 "); } 6 | 7 | / 'a' { printf("a3 "); } ( 'd' { printf("ad3 "); } / 'e' { printf("ae3 "); } ) 8 | 9 | / 'a' { printf("a4 "); } ( 'f' { printf("af4 "); } 'g' { printf("afg4 "); } 10 | / 'f' { printf("af5 "); } 'h' { printf("afh5 "); } ) 11 | 12 | / 'a' { printf("a6 "); } ( 'f' &{ printf("af6 ") } 'i' &{ printf("afi6 ") } 13 | / 'f' &{ printf("af7 ") } 'j' &{ printf("afj7 ") } ) 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | project.xcworkspace 3 | xcuserdata 4 | 5 | build/* 6 | speed/* 7 | 8 | test.* 9 | testing/* 10 | 11 | *.o 12 | markdown_parser.c 13 | /markdown 14 | /multimarkdown 15 | /multimarkdown.exe 16 | 17 | peg-0.1.4/peg 18 | peg-0.1.4/leg 19 | 20 | /mac_installer/Resources/*.html 21 | /mac_installer/Package_Root/usr/local/bin/multimarkdown 22 | 23 | /windows_installer/README.txt 24 | /windows_installer/*.zip 25 | /windows_installer/*.exe 26 | /windows_installer/*.xml.backup 27 | /windows_installer/License.html 28 | 29 | /old_zips/ 30 | 31 | /drag/ 32 | 33 | /manual/ 34 | 35 | *.pbxuser 36 | *.perspectivev3 37 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/wc.ref: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 |
35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 22 lines 54 | 425 chars 55 | 52 words 56 | -------------------------------------------------------------------------------- /Configuration/Release10.6+.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Release10.6+.xcconfig 3 | // MultiMarkdown 4 | // 5 | // Created by Daniel Jalkut on 7/29/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #include "Release.xcconfig" 10 | 11 | ARCHS = i386 x86_64 12 | GCC_VERSION = 13 | GCC_VERSION[arch=x86_64] = com.apple.compilers.llvm.clang.1_0 14 | DEPLOYMENT_POSTPROCESSING = YES 15 | MACOSX_DEPLOYMENT_TARGET = 10.6 16 | COPY_PHASE_STRIP = NO 17 | STRIP_INSTALLED_PRODUCT = YES 18 | SEPARATE_STRIP = YES 19 | GCC_MODEL_TUNING = G5 20 | OTHER_CFLAGS = -DSTANDALONE_MAC_VERSION=1 21 | GCC_PREFIX_HEADER = MarkdownMacPrefix.h 22 | GCC_PRECOMPILE_PREFIX_HEADER = YES 23 | -------------------------------------------------------------------------------- /parsing_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSING_FUNCTIONS_H 2 | #define PARSING_FUNCTIONS_H 3 | /* parsing_functions.c - Functions for parsing markdown and 4 | * freeing element lists. */ 5 | 6 | #include "markdown_peg.h" 7 | 8 | /* free_element_list - free list of elements recursively */ 9 | void free_element_list(element * elt); 10 | /* free_element - free element and contents */ 11 | void free_element(element *elt); 12 | 13 | element * parse_references(char *string, int extensions); 14 | element * parse_notes(char *string, int extensions, element *reference_list); 15 | element * parse_markdown(char *string, int extensions, element *reference_list, element *note_list, element *label_list); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /mac_installer/Make OS X Installer.pmdoc/01package.xml: -------------------------------------------------------------------------------- 1 | net.fletcherpenney.multimarkdown.pkg3.0b8Package_Root/installFrom.isRelativeTypeidentifierparentinstallToversion01package-contents.xml/CVS$/\.svn$/\.cvsignore$/\.cvspass$/\.DS_Store$ -------------------------------------------------------------------------------- /peg-0.1.9/examples/dc.peg: -------------------------------------------------------------------------------- 1 | # Grammar 2 | 3 | Expr <- SPACE Sum EOL { printf("%d\n", pop()); } 4 | / (!EOL .)* EOL { printf("error\n"); } 5 | 6 | Sum <- Product ( PLUS Product { int r= pop(), l= pop(); push(l + r); } 7 | / MINUS Product { int r= pop(), l= pop(); push(l - r); } 8 | )* 9 | 10 | Product <- Value ( TIMES Value { int r= pop(), l= pop(); push(l * r); } 11 | / DIVIDE Value { int r= pop(), l= pop(); push(l / r); } 12 | )* 13 | 14 | Value <- NUMBER { push(atoi(yytext)); } 15 | / OPEN Sum CLOSE 16 | 17 | # Lexemes 18 | 19 | NUMBER <- < [0-9]+ > SPACE 20 | PLUS <- '+' SPACE 21 | MINUS <- '-' SPACE 22 | TIMES <- '*' SPACE 23 | DIVIDE <- '/' SPACE 24 | OPEN <- '(' SPACE 25 | CLOSE <- ')' SPACE 26 | SPACE <- [ \t]* 27 | EOL <- '\n' / '\r\n' / '\r' 28 | -------------------------------------------------------------------------------- /mac_installer/Make Support Installer.pmdoc/01library.xml: -------------------------------------------------------------------------------- 1 | net.fletcherpenney.mmdsupport3.0b3Support_Root/Library/installTorequireAuthorizationparentversionidentifierinstallFrom.isRelativeTypeincludeRoot01library-contents.xml/CVS$/\.svn$/\.cvsignore$/\.cvspass$/\.DS_Store$ -------------------------------------------------------------------------------- /scripts/mmd2all: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # multimmd --- MultiMarkdown convenience script 4 | # 5 | # Fletcher T. Penney 6 | # 7 | # Pass arguments on to the binary to convert text to multiple 8 | # formats and open them 9 | # 10 | 11 | # Be sure to include multimarkdown in our PATH 12 | export PATH="/usr/local/bin:$PATH" 13 | 14 | if [ $# = 0 ] 15 | then 16 | echo "Can't work on stdin" 17 | else 18 | until [ "$*" = "" ] 19 | do 20 | file_name=`echo $1| sed 's/\.[^.]*$//'` 21 | 22 | multimarkdown -b "$1" 23 | open "$file_name.html" 24 | 25 | multimarkdown -b -t latex "$1" 26 | mate "$file_name.tex" 27 | 28 | multimarkdown -b -t odf "$1" 29 | open "$file_name.fodt" 30 | 31 | multimarkdown -b -t opml "$1" 32 | open "$file_name.opml" 33 | 34 | shift 35 | done 36 | fi 37 | -------------------------------------------------------------------------------- /Configuration/Common.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Release10.6+.xcconfig 3 | // MultiMarkdown 4 | // 5 | // Created by Daniel Jalkut on 7/29/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator 10 | ARCHS[sdk=macosx*] = i386 x86_64 11 | ARCHS[sdk=iphoneos*] = armv6 armv7 12 | ARCHS[sdk=iphonesimulator*] = i386 13 | VALID_ARCHS[sdk=iphoneos*] = armv6 armv7 14 | VALID_ARCHS[sdk=iphonesimulator*] = i386 15 | DEBUG_INFORMATION_FORMAT = dwarf-with-dsym 16 | GCC_VERSION = 17 | GCC_VERSION[arch=x86_64] = com.apple.compilers.llvm.clang.1_0 18 | DEPLOYMENT_POSTPROCESSING = YES 19 | MACOSX_DEPLOYMENT_TARGET = 10.4 20 | MACOSX_DEPLOYMENT_TARGET[arch=x86_64] = 10.6 21 | GCC_MODEL_TUNING = G5 22 | OTHER_CFLAGS = -DSTANDALONE_MAC_VERSION=1 23 | GCC_PREFIX_HEADER = MarkdownMacPrefix.h 24 | GCC_PRECOMPILE_PREFIX_HEADER = YES 25 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/calc.leg: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | int vars[26]; 4 | %} 5 | 6 | Stmt = - e:Expr EOL { printf("%d\n", e); } 7 | | ( !EOL . )* EOL { printf("error\n"); } 8 | 9 | Expr = i:ID ASSIGN s:Sum { $$= vars[i]= s; } 10 | | s:Sum { $$= s; } 11 | 12 | Sum = l:Product 13 | ( PLUS r:Product { l += r; } 14 | | MINUS r:Product { l -= r; } 15 | )* { $$= l; } 16 | 17 | Product = l:Value 18 | ( TIMES r:Value { l *= r; } 19 | | DIVIDE r:Value { l /= r; } 20 | )* { $$= l; } 21 | 22 | Value = i:NUMBER { $$= atoi(yytext); } 23 | | i:ID !ASSIGN { $$= vars[i]; } 24 | | OPEN i:Expr CLOSE { $$= i; } 25 | 26 | NUMBER = < [0-9]+ > - { $$= atoi(yytext); } 27 | ID = < [a-z] > - { $$= yytext[0] - 'a'; } 28 | ASSIGN = '=' - 29 | PLUS = '+' - 30 | MINUS = '-' - 31 | TIMES = '*' - 32 | DIVIDE = '/' - 33 | OPEN = '(' - 34 | CLOSE = ')' - 35 | 36 | - = [ \t]* 37 | EOL = '\n' | '\r\n' | '\r' | ';' 38 | 39 | %% 40 | 41 | int main() 42 | { 43 | while (yyparse()); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/dcv.peg: -------------------------------------------------------------------------------- 1 | # Grammar 2 | 3 | Stmt <- SPACE Expr EOL { printf("%d\n", pop()); } 4 | / (!EOL .)* EOL { printf("error\n"); } 5 | 6 | Expr <- ID { var= yytext[0] } ASSIGN Sum { vars[var - 'a']= top(); } 7 | / Sum 8 | 9 | Sum <- Product ( PLUS Product { int r= pop(), l= pop(); push(l + r); } 10 | / MINUS Product { int r= pop(), l= pop(); push(l - r); } 11 | )* 12 | 13 | Product <- Value ( TIMES Value { int r= pop(), l= pop(); push(l * r); } 14 | / DIVIDE Value { int r= pop(), l= pop(); push(l / r); } 15 | )* 16 | 17 | Value <- NUMBER { push(atoi(yytext)); } 18 | / < ID > !ASSIGN { push(vars[yytext[0] - 'a']); } 19 | / OPEN Expr CLOSE 20 | 21 | # Lexemes 22 | 23 | NUMBER <- < [0-9]+ > SPACE 24 | ID <- < [a-z] > SPACE 25 | ASSIGN <- '=' SPACE 26 | PLUS <- '+' SPACE 27 | MINUS <- '-' SPACE 28 | TIMES <- '*' SPACE 29 | DIVIDE <- '/' SPACE 30 | OPEN <- '(' SPACE 31 | CLOSE <- ')' SPACE 32 | 33 | SPACE <- [ \t]* 34 | EOL <- '\n' / '\r\n' / '\r' / ';' 35 | -------------------------------------------------------------------------------- /mac_installer/Make Support Installer.pmdoc/index.xml: -------------------------------------------------------------------------------- 1 | MultiMarkdown-Mac-Support-3.0b2/Users/fletcher/MultiMarkdown-Mac-Support-3.0b3.mpkgnet.fletcherpenneyResources/License.htmlResources/Support_Welcome.html01library.xmlproperties.titleproperties.customizeOptionproperties.userDomainproperties.anywhereDomainproperties.systemDomain -------------------------------------------------------------------------------- /markdown_lib.h: -------------------------------------------------------------------------------- 1 | #ifndef MARKDOWN_LIB_H 2 | #define MARKDOWN_LIB_H 3 | 4 | #include 5 | #include 6 | #include "glib.h" 7 | 8 | enum markdown_extensions { 9 | EXT_SMART = 1 << 0, 10 | EXT_NOTES = 1 << 1, 11 | EXT_FILTER_HTML = 1 << 2, 12 | EXT_FILTER_STYLES = 1 << 3, 13 | EXT_COMPATIBILITY = 1 << 4, 14 | EXT_PROCESS_HTML = 1 << 5, 15 | EXT_NO_LABELS = 1 << 6, 16 | }; 17 | 18 | enum markdown_formats { 19 | HTML_FORMAT, 20 | LATEX_FORMAT, 21 | MEMOIR_FORMAT, 22 | BEAMER_FORMAT, 23 | OPML_FORMAT, 24 | GROFF_MM_FORMAT, 25 | ODF_FORMAT, 26 | ODF_BODY_FORMAT, 27 | ORIGINAL_FORMAT 28 | }; 29 | 30 | GString * markdown_to_g_string(char *text, int extensions, int output_format); 31 | char * markdown_to_string(char *text, int extensions, int output_format); 32 | char * extract_metadata_value(char *text, int extensions, char *key); 33 | gboolean has_metadata(char *text, int extensions); 34 | char * mmd_version(); 35 | 36 | /* vim: set ts=4 sw=4 : */ 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /mac_installer/Make OS X Installer.pmdoc/index.xml: -------------------------------------------------------------------------------- 1 | MultiMarkdown/Users/fletcher/MultiMarkdown-Mac-3.0b3.pkgnet.fletcherpenney.multimarkdownInstalls the multimarkdown binary, as well as the glib2 library (libglib2.0.0) and libintl filesResources/License.htmlResources/README.htmlResources/Welcome.html01package.xmlproperties.titledescriptionproperties.anywhereDomainproperties.systemDomain -------------------------------------------------------------------------------- /mac_installer/Resources/Support_Welcome.txt: -------------------------------------------------------------------------------- 1 | Title: Installer Welcome Message 2 | 3 | This custom installer will install the **MultiMarkdown** directory into 4 | `~/Library/Application Support/MultiMarkdown`. This directory contains a few 5 | utility scripts and XSLT files that enable use of MultiMarkdown with 6 | [Scrivener] and adds some additional features when using the [TextMate][] 7 | [bundle]. 8 | 9 | **NOTE**: This package will overwrite certain files if you have previously 10 | installed MultiMarkdown 2.0 in your `Application Support` folder. It will 11 | leave most of the files untouched, but will overwrite some of the core XSLT 12 | files and the core convenience scripts in `/bin`. You may wish to back that 13 | folder up just in case (or better yet, move it to another location and start 14 | fresh) 15 | 16 | This package does **not** include the actual MultiMarkdown binary --- that 17 | requires a separate installer. 18 | 19 | For more information, please check out the MultiMarkdown [web 20 | site](http://fletcherpenney.net/multimarkdown/). 21 | 22 | You will be guided through the steps necessary to install this software. 23 | 24 | [Scrivener]: http://www.literatureandlatte.com/ 25 | 26 | [TextMate]: http://macromates.com/ 27 | 28 | [bundle]: https://github.com/fletcher/markdown.tmbundle -------------------------------------------------------------------------------- /peg-0.1.9/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -g -Wall $(OFLAGS) $(XFLAGS) 2 | OFLAGS = -O3 -DNDEBUG 3 | #OFLAGS = -pg 4 | 5 | OBJS = tree.o compile.o 6 | 7 | all : peg leg 8 | 9 | peg : peg.o $(OBJS) 10 | $(CC) $(CFLAGS) -o $@-new peg.o $(OBJS) 11 | mv $@-new $@ 12 | 13 | leg : leg.o $(OBJS) 14 | $(CC) $(CFLAGS) -o $@-new leg.o $(OBJS) 15 | mv $@-new $@ 16 | 17 | ROOT = 18 | PREFIX = /usr/local 19 | BINDIR = $(ROOT)$(PREFIX)/bin 20 | 21 | install : $(BINDIR)/peg $(BINDIR)/leg 22 | 23 | $(BINDIR)/% : % 24 | cp -p $< $@ 25 | strip $@ 26 | 27 | uninstall : .FORCE 28 | rm -f $(BINDIR)/peg 29 | rm -f $(BINDIR)/leg 30 | 31 | peg.o : peg.c peg.peg-c 32 | 33 | %.peg-c : %.peg compile.c 34 | ./peg -o $@ $< 35 | 36 | leg.o : leg.c 37 | 38 | leg.c : leg.leg compile.c 39 | ./leg -o $@ $< 40 | 41 | check : check-peg check-leg 42 | 43 | check-peg : peg .FORCE 44 | ./peg < peg.peg > peg.out 45 | diff peg.peg-c peg.out 46 | rm peg.out 47 | 48 | check-leg : leg .FORCE 49 | ./leg < leg.leg > leg.out 50 | diff leg.c leg.out 51 | rm leg.out 52 | 53 | test examples : .FORCE 54 | $(SHELL) -ec '(cd examples; $(MAKE))' 55 | 56 | clean : .FORCE 57 | rm -f *~ *.o *.peg.[cd] *.leg.[cd] 58 | $(SHELL) -ec '(cd examples; $(MAKE) $@)' 59 | 60 | spotless : clean .FORCE 61 | rm -f peg 62 | rm -f leg 63 | $(SHELL) -ec '(cd examples; $(MAKE) $@)' 64 | 65 | .FORCE : 66 | -------------------------------------------------------------------------------- /mac_installer/Make OS X Installer.pmdoc/01package-contents.xml: -------------------------------------------------------------------------------- 1 | ownermodegroupownermodegroupownermodegroupownermodegroupownermodegroupownermodegroupgroupownergroupownergroupownergroupownergroupownergroupownergroupownergroupownergroupowner -------------------------------------------------------------------------------- /MMD-Compat.xcodeproj/xcuserdata/fletcher.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | MakefileBuild.xcscheme 8 | 9 | orderHint 10 | 4 11 | 12 | MultiMarkdown.xcscheme 13 | 14 | orderHint 15 | 0 16 | 17 | Peg.xcscheme 18 | 19 | orderHint 20 | 2 21 | 22 | Run Tests.xcscheme 23 | 24 | orderHint 25 | 1 26 | 27 | libMultiMarkdown.xcscheme 28 | 29 | orderHint 30 | 3 31 | 32 | 33 | SuppressBuildableAutocreation 34 | 35 | 4AFA466113E3624F00CFA132 36 | 37 | primary 38 | 39 | 40 | 65BDF4D813E6D0A100E8C5B3 41 | 42 | primary 43 | 44 | 45 | 65F0B88813DF6C0D00D0980C 46 | 47 | primary 48 | 49 | 50 | 65F0B8EA13DF714E00D0980C 51 | 52 | primary 53 | 54 | 55 | 8DD76FA90486AB0100D96B5E 56 | 57 | primary 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /scripts/mmd2pdf: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # mmd2pdf --- MultiMarkdown convenience script 4 | # 5 | # Fletcher T. Penney 6 | # 7 | # Pass arguments on to the binary to convert text to LaTeX 8 | # Then use latexmk to process into PDF. 9 | # Requires a few extra passes of pdflatex to be sure all autorefs 10 | # are managed. 11 | # Then call latexmk with -c option to try and clean up some extra files. 12 | # 13 | # NOTE: This file is included as a convenience for users - it's not 14 | # likely to fail gracefully if there are any issues in your 15 | # LaTeX file. 16 | 17 | # Be sure to include multimarkdown and latex in our PATH 18 | export PATH="/usr/local/bin:/usr/texbin:$PATH" 19 | 20 | if [ $# = 0 ] 21 | then 22 | multimarkdown -t latex 23 | else 24 | until [ "$*" = "" ] 25 | do 26 | multimarkdown -b -t latex "$1" 27 | 28 | file_name=`echo $1| sed 's/\.[^.]*$//'` 29 | 30 | # Check for XeLaTeX mode 31 | 32 | xelatex=`multimarkdown -e usexelatex "$1"` 33 | 34 | if [ "$xelatex" != "" ] 35 | then 36 | # Use XeLaTeX 37 | 38 | xelatex "$file_name.tex" 39 | 40 | if [ "$?" == "127" ] 41 | then 42 | echo "It doesn't appear that xelatex is installed properly." 1>&2 43 | echo "Be sure you have a working LaTeX installation." 1>&2 44 | exit 1 45 | fi 46 | 47 | xelatex "$file_name.tex" 48 | xelatex "$file_name.tex" 49 | xelatex "$file_name.tex" 50 | latexmk -c "$file_name.tex" 51 | 52 | else 53 | # Use LaTeX 54 | latexmk "$file_name.tex" 55 | 56 | if [ "$?" == "127" ] 57 | then 58 | echo "It doesn't appear that latexmk is installed properly." 1>&2 59 | echo "Be sure you have a working LaTeX installation." 1>&2 60 | exit 1 61 | fi 62 | 63 | makeglossaries "$file_name" 64 | pdflatex "$file_name.tex" 65 | pdflatex "$file_name.tex" 66 | latexmk -c "$file_name.tex" 67 | 68 | fi 69 | 70 | shift 71 | done 72 | fi 73 | -------------------------------------------------------------------------------- /GLibFacade.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GLibFacade.h 3 | * MultiMarkdown 4 | * 5 | * Created by Daniel Jalkut on 7/26/11. 6 | * Copyright 2011 __MyCompanyName__. All rights reserved. 7 | */ 8 | 9 | #ifndef __MARKDOWN_GLIB_FACADE__ 10 | #define __MARKDOWN_GLIB_FACADE__ 11 | 12 | /* peg_markdown uses the link symbol for its own purposes */ 13 | #define link MARKDOWN_LINK_IGNORED 14 | #include 15 | #undef link 16 | 17 | #include 18 | #include 19 | 20 | typedef int gboolean; 21 | typedef char gchar; 22 | 23 | /* This style of bool is used in shared source code */ 24 | #define FALSE false 25 | #define TRUE true 26 | 27 | /* WE implement minimal mirror implementations of GLib's GString and GSList 28 | * sufficient to cover the functionality required by MultiMarkdown. 29 | * 30 | * NOTE: THese are 100% clean, from-scratch implementations using only the 31 | * GLib function prototype as guide for behavior. 32 | */ 33 | 34 | typedef struct 35 | { 36 | /* Current UTF8 byte stream this string represents */ 37 | char* str; 38 | 39 | /* Where in the str buffer will we add new characters */ 40 | /* or append new strings? */ 41 | int currentStringBufferSize; 42 | int currentStringLength; 43 | } GString; 44 | 45 | GString* g_string_new(char *startingString); 46 | char* g_string_free(GString* ripString, bool freeCharacterData); 47 | 48 | void g_string_append_c(GString* baseString, char appendedCharacter); 49 | void g_string_append(GString* baseString, char *appendedString); 50 | 51 | void g_string_prepend(GString* baseString, char* prependedString); 52 | 53 | void g_string_append_printf(GString* baseString, char* format, ...); 54 | 55 | /* Just implement a very simple singly linked list. */ 56 | 57 | typedef struct _GSList 58 | { 59 | void* data; 60 | struct _GSList* next; 61 | } GSList; 62 | 63 | void g_slist_free(GSList* ripList); 64 | GSList* g_slist_prepend(GSList* targetElement, void* newElementData); 65 | GSList* g_slist_reverse(GSList* theList); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /peg-0.1.9/examples/Makefile: -------------------------------------------------------------------------------- 1 | EXAMPLES = test rule accept wc dc dcv calc basic localctx 2 | 3 | CFLAGS = -g -O3 4 | 5 | DIFF = diff 6 | TEE = cat > 7 | 8 | all : $(EXAMPLES) 9 | 10 | test : .FORCE 11 | ../peg -o test.peg.c test.peg 12 | $(CC) $(CFLAGS) -o test test.c 13 | echo 'ab.ac.ad.ae.afg.afh.afg.afh.afi.afj.' | ./$@ | $(TEE) $@.out 14 | $(DIFF) $@.ref $@.out 15 | rm -f $@.out 16 | @echo 17 | 18 | rule : .FORCE 19 | ../peg -o rule.peg.c rule.peg 20 | $(CC) $(CFLAGS) -o rule rule.c 21 | echo 'abcbcdabcbcdabcbcdabcbcd' | ./$@ | $(TEE) $@.out 22 | $(DIFF) $@.ref $@.out 23 | rm -f $@.out 24 | @echo 25 | 26 | accept : .FORCE 27 | ../peg -o accept.peg.c accept.peg 28 | $(CC) $(CFLAGS) -o accept accept.c 29 | echo 'abcbcdabcbcdabcbcdabcbcd' | ./$@ | $(TEE) $@.out 30 | $(DIFF) $@.ref $@.out 31 | rm -f $@.out 32 | @echo 33 | 34 | wc : .FORCE 35 | ../leg -o wc.leg.c wc.leg 36 | $(CC) $(CFLAGS) -o wc wc.leg.c 37 | cat wc.leg | ./$@ | $(TEE) $@.out 38 | $(DIFF) $@.ref $@.out 39 | rm -f $@.out 40 | @echo 41 | 42 | dc : .FORCE 43 | ../peg -o dc.peg.c dc.peg 44 | $(CC) $(CFLAGS) -o dc dc.c 45 | echo ' 2 *3 *(3+ 4) ' | ./dc | $(TEE) $@.out 46 | $(DIFF) $@.ref $@.out 47 | rm -f $@.out 48 | @echo 49 | 50 | dcv : .FORCE 51 | ../peg -o dcv.peg.c dcv.peg 52 | $(CC) $(CFLAGS) -o dcv dcv.c 53 | echo 'a = 6; b = 7; a * b' | ./dcv | $(TEE) $@.out 54 | $(DIFF) $@.ref $@.out 55 | rm -f $@.out 56 | @echo 57 | 58 | calc : .FORCE 59 | ../leg -o calc.leg.c calc.leg 60 | $(CC) $(CFLAGS) -o calc calc.leg.c 61 | echo 'a = 6; b = 7; a * b' | ./calc | $(TEE) $@.out 62 | $(DIFF) $@.ref $@.out 63 | rm -f $@.out 64 | @echo 65 | 66 | basic : .FORCE 67 | ../leg -o basic.leg.c basic.leg 68 | $(CC) $(CFLAGS) -o basic basic.leg.c 69 | ( echo 'load "test"'; echo "run" ) | ./basic | $(TEE) $@.out 70 | $(DIFF) $@.ref $@.out 71 | rm -f $@.out 72 | @echo 73 | 74 | localctx : .FORCE 75 | ../peg -o test.peg.c test.peg 76 | $(CC) $(CFLAGS) -o localctx localctx.c 77 | echo 'ab.ac.ad.ae.afg.afh.afg.afh.afi.afj.' | ./$@ | $(TEE) $@.out 78 | $(DIFF) $@.ref $@.out 79 | rm -f $@.out 80 | @echo 81 | 82 | clean : .FORCE 83 | rm -f *~ *.o *.[pl]eg.[cd] $(EXAMPLES) 84 | rm -rf *.dSYM 85 | 86 | spotless : clean 87 | 88 | .FORCE : 89 | -------------------------------------------------------------------------------- /MMD-Compat.xcodeproj/xcuserdata/fletcher.xcuserdatad/xcschemes/Peg.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 40 | 41 | 42 | 43 | 50 | 51 | 53 | 54 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /MMD-Compat.xcodeproj/xcuserdata/fletcher.xcuserdatad/xcschemes/Run Tests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 40 | 41 | 42 | 43 | 50 | 51 | 53 | 54 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /MMD-Compat.xcodeproj/xcuserdata/fletcher.xcuserdatad/xcschemes/MakefileBuild.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 40 | 41 | 42 | 43 | 50 | 51 | 53 | 54 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /MMD-Compat.xcodeproj/xcuserdata/fletcher.xcuserdatad/xcschemes/libMultiMarkdown.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 40 | 41 | 42 | 43 | 50 | 51 | 53 | 54 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /MMD-Compat.xcodeproj/xcuserdata/fletcher.xcuserdatad/xcschemes/MultiMarkdown.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 40 | 41 | 47 | 48 | 49 | 50 | 51 | 52 | 59 | 60 | 66 | 67 | 68 | 69 | 71 | 72 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /peg-0.1.9/peg.peg: -------------------------------------------------------------------------------- 1 | # PE Grammar for PE Grammars 2 | # 3 | # Adapted from [1] by Ian Piumarta . 4 | # 5 | # Local modifications (marked '#ikp') to support: 6 | # C text in '{ ... }' copied verbatim to output as 'semantic action' 7 | # input consumed between '<' and '>' is 'char yytext[]' in semantic actions 8 | # 9 | # Best viewed using 140 columns monospaced with tabs every 8. 10 | # 11 | # [1] Bryan Ford. "Parsing Expression Grammars: A Recognition-Based Syntactic 12 | # Foundation." Symposium on Principles of Programming Languages, 13 | # January 14--16, 2004, Venice, Italy. 14 | # 15 | # Last edited: 2007-05-15 10:32:44 by piumarta on emilia 16 | 17 | # Hierarchical syntax 18 | 19 | Grammar <- Spacing Definition+ EndOfFile 20 | 21 | Definition <- Identifier { if (push(beginRule(findRule(yytext)))->rule.expression) fprintf(stderr, "rule '%s' redefined\n", yytext); } 22 | LEFTARROW Expression { Node *e= pop(); Rule_setExpression(pop(), e); } &{ YYACCEPT } 23 | Expression <- Sequence (SLASH Sequence { Node *f= pop(); push(Alternate_append(pop(), f)); } 24 | )* 25 | Sequence <- Prefix (Prefix { Node *f= pop(); push(Sequence_append(pop(), f)); } #ikp expanded from 'Seq <- Prefix*' 26 | )* 27 | / { push(makePredicate("1")); } #ikp added 28 | Prefix <- AND Action { push(makePredicate(yytext)); } #ikp added 29 | / AND Suffix { push(makePeekFor(pop())); } #ikp expanded from 'Prefix <- (AND/NOT)? Suffix' 30 | / NOT Suffix { push(makePeekNot(pop())); } 31 | / Suffix 32 | Suffix <- Primary (QUESTION { push(makeQuery(pop())); } 33 | / STAR { push(makeStar (pop())); } 34 | / PLUS { push(makePlus (pop())); } 35 | )? 36 | Primary <- Identifier !LEFTARROW { push(makeName(findRule(yytext))); } 37 | / OPEN Expression CLOSE 38 | / Literal { push(makeString(yytext)); } 39 | / Class { push(makeClass(yytext)); } 40 | / DOT { push(makeDot()); } 41 | / Action { push(makeAction(yytext)); } #ikp added 42 | / BEGIN { push(makePredicate("YY_BEGIN")); } #ikp added 43 | / END { push(makePredicate("YY_END")); } #ikp added 44 | 45 | # Lexical syntax 46 | 47 | Identifier <- < IdentStart IdentCont* > Spacing #ikp inserted < ... > 48 | IdentStart <- [a-zA-Z_] 49 | IdentCont <- IdentStart / [0-9] 50 | Literal <- ['] < (!['] Char )* > ['] Spacing #ikp inserted < ... > 51 | / ["] < (!["] Char )* > ["] Spacing #ikp inserted < ... > 52 | Class <- '[' < (!']' Range)* > ']' Spacing #ikp inserted < ... > 53 | Range <- Char '-' Char / Char 54 | Char <- '\\' [abefnrtv'"\[\]\\] #ikp added missing ANSI escapes: abefv 55 | / '\\' [0-3][0-7][0-7] 56 | / '\\' [0-7][0-7]? 57 | / '\\' '-' #ikp added 58 | / !'\\' . 59 | LEFTARROW <- '<-' Spacing 60 | SLASH <- '/' Spacing 61 | AND <- '&' Spacing 62 | NOT <- '!' Spacing 63 | QUESTION <- '?' Spacing 64 | STAR <- '*' Spacing 65 | PLUS <- '+' Spacing 66 | OPEN <- '(' Spacing 67 | CLOSE <- ')' Spacing 68 | DOT <- '.' Spacing 69 | Spacing <- (Space / Comment)* 70 | Comment <- '#' (!EndOfLine .)* EndOfLine 71 | Space <- ' ' / '\t' / EndOfLine 72 | EndOfLine <- '\r\n' / '\n' / '\r' 73 | EndOfFile <- !. 74 | 75 | Action <- '{' < [^}]* > '}' Spacing #ikp added 76 | BEGIN <- '<' Spacing #ikp added 77 | END <- '>' Spacing #ikp added 78 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Title: License Agreement 2 | 3 | peg-multimarkdown 4 | portions Copyright (c) 2010-2013 Fletcher T. Penney 5 | 6 | based on: 7 | markdown in c, implemented using PEG grammar 8 | Copyright (c) 2008-2011 John MacFarlane 9 | ODF output code (c) 2011-2013 Fletcher T. Penney 10 | 11 | peg-markdown is released under both the GPL and MIT licenses. 12 | You may pick the license that best fits your needs. 13 | 14 | Additional MultiMarkdown files 15 | Copyright (c) 2005-2013 Fletcher T. Penney 16 | Copyright (c) 2011 Daniel Jalkut, licensed explicitly MIT. 17 | 18 | Modifications to remove reliance on Glib2 19 | Copyright (c) 2011 Daniel Jalkut, licensed explicitly MIT. 20 | 21 | 22 | The GPL 23 | 24 | This program is free software; you can redistribute it and/or modify 25 | it under the terms of the GNU General Public License as published by 26 | the Free Software Foundation; either version 2 of the License, or 27 | (at your option) any later version. 28 | 29 | This program is distributed in the hope that it will be useful, 30 | but WITHOUT ANY WARRANTY; without even the implied warranty of 31 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 32 | GNU General Public License for more details. 33 | 34 | You should have received a copy of the GNU General Public License 35 | along with this program; if not, write to the Free Software 36 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 37 | 38 | The MIT License 39 | 40 | Permission is hereby granted, free of charge, to any person obtaining a copy 41 | of this software and associated documentation files (the "Software"), to deal 42 | in the Software without restriction, including without limitation the rights 43 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | copies of the Software, and to permit persons to whom the Software is 45 | furnished to do so, subject to the following conditions: 46 | 47 | The above copyright notice and this permission notice shall be included in 48 | all copies or substantial portions of the Software. 49 | 50 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 56 | THE SOFTWARE. 57 | 58 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 59 | 60 | peg-0.1.4 (included for convenience - http://piumarta.com/software/peg/) 61 | 62 | Copyright (c) 2007 by Ian Piumarta 63 | All rights reserved. 64 | 65 | Permission is hereby granted, free of charge, to any person obtaining a 66 | copy of this software and associated documentation files (the 'Software'), 67 | to deal in the Software without restriction, including without limitation 68 | the rights to use, copy, modify, merge, publish, distribute, and/or sell 69 | copies of the Software, and to permit persons to whom the Software is 70 | furnished to do so, provided that the above copyright notice(s) and this 71 | permission notice appear in all copies of the Software. Acknowledgement 72 | of the use of this Software in supporting documentation would be 73 | appreciated but is not required. 74 | 75 | THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. 76 | -------------------------------------------------------------------------------- /utility_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITY_FUNCTIONS_H 2 | #define UTILITY_FUNCTIONS_H 3 | 4 | #include 5 | #include 6 | 7 | #include "markdown_peg.h" 8 | 9 | #include 10 | 11 | /* utility_functions.h - List manipulation functions, element 12 | * constructors, and macro definitions for leg markdown parser. */ 13 | 14 | 15 | /* cons - cons an element onto a list, returning pointer to new head */ 16 | element * cons(element *new, element *list); 17 | 18 | /* reverse - reverse a list, returning pointer to new list */ 19 | element *reverse(element *list); 20 | /* concat_string_list - concatenates string contents of list of STR elements. 21 | * Frees STR elements as they are added to the concatenation. */ 22 | GString *concat_string_list(element *list); 23 | /********************************************************************** 24 | 25 | Global variables used in parsing 26 | 27 | ***********************************************************************/ 28 | 29 | extern char *charbuf; /* Buffer of characters to be parsed. */ 30 | extern element *references; /* List of link references found. */ 31 | extern element *notes; /* List of footnotes found. */ 32 | extern element *parse_result; /* Results of parse. */ 33 | extern int syntax_extensions; /* Syntax extensions selected. */ 34 | 35 | 36 | extern element *labels; /* List of labels found in document. */ 37 | extern clock_t start_time; /* Used for ensuring we're not stuck in a loop */ 38 | extern bool parse_aborted; /* flag indicating we ran out of time */ 39 | 40 | /********************************************************************** 41 | 42 | Auxiliary functions for parsing actions. 43 | These make it easier to build up data structures (including lists) 44 | in the parsing actions. 45 | 46 | ***********************************************************************/ 47 | 48 | /* mk_element - generic constructor for element */ 49 | element * mk_element(int key); 50 | 51 | /* mk_str - constructor for STR element */ 52 | element * mk_str(char *string); 53 | 54 | /* mk_str_from_list - makes STR element by concatenating a 55 | * reversed list of strings, adding optional extra newline */ 56 | element * mk_str_from_list(element *list, bool extra_newline); 57 | 58 | /* mk_list - makes new list with key 'key' and children the reverse of 'lst'. 59 | * This is designed to be used with cons to build lists in a parser action. 60 | * The reversing is necessary because cons adds to the head of a list. */ 61 | element * mk_list(int key, element *lst); 62 | 63 | /* mk_link - constructor for LINK element */ 64 | element * mk_link(element *label, char *url, char *title, element *attr, char *id); 65 | /* extension = returns true if extension is selected */ 66 | bool extension(int ext); 67 | 68 | /* match_inlines - returns true if inline lists match (case-insensitive...) */ 69 | bool match_inlines(element *l1, element *l2); 70 | 71 | /* find_reference - return true if link found in references matching label. 72 | * 'link' is modified with the matching url and title. */ 73 | bool find_reference(link *result, element *label); 74 | 75 | /* find_note - return true if note found in notes matching label. 76 | if found, 'result' is set to point to matched note. */ 77 | 78 | bool find_note(element **result, char *label); 79 | 80 | 81 | char *label_from_string(char *str, bool obfuscate); 82 | void localize_typography(GString *out, int character, int language, int output); 83 | void print_raw_element_list(GString *out, element *list); 84 | void append_list(element *new, element *list); 85 | bool find_label(link *result, element *label); 86 | bool check_timeout(); 87 | void trim_trailing_whitespace(char *str); 88 | char *label_from_element_list(element *list, bool obfuscate); 89 | void print_raw_element_list(GString *out, element *list); 90 | void print_raw_element(GString *out, element *elt); 91 | 92 | #endif 93 | 94 | -------------------------------------------------------------------------------- /markdown_peg.h: -------------------------------------------------------------------------------- 1 | /* markdown_peg.h */ 2 | #ifndef MARKDOWN_PEG_H 3 | #define MARKDOWN_PEG_H 4 | 5 | #include "markdown_lib.h" 6 | #include "glib.h" 7 | 8 | /* Information (label, URL and title) for a link. */ 9 | struct Link { 10 | struct Element *label; 11 | char *url; 12 | char *title; 13 | struct Element *attr; 14 | char *identifier; 15 | }; 16 | 17 | typedef struct Link link; 18 | 19 | /* Union for contents of an Element (string, list, or link). */ 20 | union Contents { 21 | char *str; 22 | struct Link *link; 23 | }; 24 | 25 | /* Types of semantic values returned by parsers. */ 26 | enum keys { LIST, /* A generic list of values. For ordered and bullet lists, see below. */ 27 | RAW, /* Raw markdown to be processed further */ 28 | SPACE, 29 | LINEBREAK, 30 | ELLIPSIS, 31 | EMDASH, 32 | ENDASH, 33 | APOSTROPHE, 34 | SINGLEQUOTED, 35 | DOUBLEQUOTED, 36 | STR, 37 | LINK, 38 | IMAGE, 39 | IMAGEBLOCK, 40 | CODE, 41 | HTML, 42 | EMPH, 43 | STRONG, 44 | PLAIN, 45 | PARA, 46 | LISTITEM, 47 | BULLETLIST, 48 | ORDEREDLIST, 49 | H1, H2, H3, H4, H5, H6, H7, /* Code assumes that these are in order. */ 50 | BLOCKQUOTE, 51 | VERBATIM, 52 | HTMLBLOCK, 53 | HRULE, 54 | REFERENCE, 55 | NOTE, 56 | CITATION, 57 | NOCITATION, 58 | LOCATOR, 59 | NOTELABEL, 60 | DEFLIST, 61 | TERM, 62 | DEFINITION, 63 | METAKEY, 64 | METAVALUE, 65 | METADATA, 66 | FOOTER, 67 | LABEL, 68 | HEADINGSECTION, 69 | ENDHTML, 70 | TABLE, 71 | TABLEHEAD, 72 | TABLEBODY, 73 | TABLEROW, 74 | TABLECELL, 75 | CELLSPAN, 76 | TABLECAPTION, 77 | TABLELABEL, 78 | TABLESEPARATOR, 79 | AUTOLABEL, 80 | ATTRIBUTE, 81 | ATTRKEY, 82 | ATTRVALUE, 83 | GLOSSARY, 84 | GLOSSARYTERM, 85 | GLOSSARYSORTKEY, 86 | MATHSPAN 87 | }; 88 | 89 | /* constants for managing Smart Typography */ 90 | enum smartelements { 91 | LSQUOTE, 92 | RSQUOTE, 93 | LDQUOTE, 94 | RDQUOTE, 95 | NDASH, 96 | MDASH, 97 | ELLIP, 98 | APOS, 99 | }; 100 | 101 | enum smartoutput { 102 | HTMLOUT, 103 | LATEXOUT, 104 | }; 105 | 106 | enum language { 107 | DUTCH, 108 | ENGLISH, 109 | FRENCH, 110 | GERMAN, 111 | SWEDISH, 112 | GERMANGUILL, 113 | }; 114 | 115 | /* Semantic value of a parsing action. */ 116 | struct Element { 117 | int key; 118 | union Contents contents; 119 | struct Element *children; 120 | struct Element *next; 121 | }; 122 | 123 | 124 | 125 | typedef struct Element element; 126 | 127 | element * parse_references(char *string, int extensions); 128 | element * parse_notes(char *string, int extensions, element *reference_list); 129 | element * parse_labels(char *string, int extensions, element *reference_list, element *note_list); 130 | 131 | element * parse_markdown(char *string, int extensions, element *reference_list, element *note_list, element *label_list); 132 | element * parse_markdown_with_metadata(char *string, int extensions, element *reference_list, element *note_list, element *label_list); 133 | void free_element_list(element * elt); 134 | void free_element(element *elt); 135 | void print_element_list(GString *out, element *elt, int format, int exts); 136 | 137 | element * parse_metadata_only(char *string, int extensions); 138 | char * extract_metadata_value(char *text, int extensions, char *key); 139 | 140 | char * metavalue_for_key(char *key, element *list); 141 | 142 | element * parse_markdown_for_opml(char *string, int extensions); 143 | #endif 144 | -------------------------------------------------------------------------------- /peg-0.1.9/tree.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007 by Ian Piumarta 2 | * All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the 'Software'), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, provided that the above copyright notice(s) and this 10 | * permission notice appear in all copies of the Software. Acknowledgement 11 | * of the use of this Software in supporting documentation would be 12 | * appreciated but is not required. 13 | * 14 | * THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. 15 | * 16 | * Last edited: 2007-05-15 10:32:05 by piumarta on emilia 17 | */ 18 | 19 | #include 20 | 21 | enum { Unknown= 0, Rule, Variable, Name, Dot, Character, String, Class, Action, Predicate, Alternate, Sequence, PeekFor, PeekNot, Query, Star, Plus }; 22 | 23 | enum { 24 | RuleUsed = 1<<0, 25 | RuleReached = 1<<1, 26 | }; 27 | 28 | typedef union Node Node; 29 | 30 | struct Rule { int type; Node *next; char *name; Node *variables; Node *expression; int id; int flags; }; 31 | struct Variable { int type; Node *next; char *name; Node *value; int offset; }; 32 | struct Name { int type; Node *next; Node *rule; Node *variable; }; 33 | struct Dot { int type; Node *next; }; 34 | struct Character { int type; Node *next; char *value; }; 35 | struct String { int type; Node *next; char *value; }; 36 | struct Class { int type; Node *next; unsigned char *value; }; 37 | struct Action { int type; Node *next; char *text; Node *list; char *name; Node *rule; }; 38 | struct Predicate { int type; Node *next; char *text; }; 39 | struct Alternate { int type; Node *next; Node *first; Node *last; }; 40 | struct Sequence { int type; Node *next; Node *first; Node *last; }; 41 | struct PeekFor { int type; Node *next; Node *element; }; 42 | struct PeekNot { int type; Node *next; Node *element; }; 43 | struct Query { int type; Node *next; Node *element; }; 44 | struct Star { int type; Node *next; Node *element; }; 45 | struct Plus { int type; Node *next; Node *element; }; 46 | struct Any { int type; Node *next; }; 47 | 48 | union Node 49 | { 50 | int type; 51 | struct Rule rule; 52 | struct Variable variable; 53 | struct Name name; 54 | struct Dot dot; 55 | struct Character character; 56 | struct String string; 57 | struct Class cclass; 58 | struct Action action; 59 | struct Predicate predicate; 60 | struct Alternate alternate; 61 | struct Sequence sequence; 62 | struct PeekFor peekFor; 63 | struct PeekNot peekNot; 64 | struct Query query; 65 | struct Star star; 66 | struct Plus plus; 67 | struct Any any; 68 | }; 69 | 70 | extern Node *actions; 71 | extern Node *rules; 72 | extern Node *start; 73 | 74 | extern int ruleCount; 75 | 76 | extern FILE *output; 77 | 78 | extern Node *makeRule(char *name); 79 | extern Node *findRule(char *name); 80 | extern Node *beginRule(Node *rule); 81 | extern void Rule_setExpression(Node *rule, Node *expression); 82 | extern Node *Rule_beToken(Node *rule); 83 | extern Node *makeVariable(char *name); 84 | extern Node *makeName(Node *rule); 85 | extern Node *makeDot(void); 86 | extern Node *makeCharacter(char *text); 87 | extern Node *makeString(char *text); 88 | extern Node *makeClass(char *text); 89 | extern Node *makeAction(char *text); 90 | extern Node *makePredicate(char *text); 91 | extern Node *makeAlternate(Node *e); 92 | extern Node *Alternate_append(Node *e, Node *f); 93 | extern Node *makeSequence(Node *e); 94 | extern Node *Sequence_append(Node *e, Node *f); 95 | extern Node *makePeekFor(Node *e); 96 | extern Node *makePeekNot(Node *e); 97 | extern Node *makeQuery(Node *e); 98 | extern Node *makeStar(Node *e); 99 | extern Node *makePlus(Node *e); 100 | extern Node *push(Node *node); 101 | extern Node *top(void); 102 | extern Node *pop(void); 103 | 104 | extern void Rule_compile_c_header(void); 105 | extern void Rule_compile_c(Node *node); 106 | 107 | extern void Node_print(Node *node); 108 | extern void Rule_print(Node *node); 109 | -------------------------------------------------------------------------------- /peg-0.1.9/peg.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007 by Ian Piumarta 2 | * All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the 'Software'), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, provided that the above copyright notice(s) and this 10 | * permission notice appear in all copies of the Software. Acknowledgement 11 | * of the use of this Software in supporting documentation would be 12 | * appreciated but is not required. 13 | * 14 | * THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. 15 | * 16 | * Last edited: 2012-04-29 15:49:09 by piumarta on emilia 17 | */ 18 | 19 | #include "tree.h" 20 | #include "version.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | FILE *input= 0; 30 | 31 | int verboseFlag= 0; 32 | 33 | static int lineNumber= 0; 34 | static char *fileName= 0; 35 | 36 | void yyerror(char *message); 37 | 38 | #define YY_INPUT(buf, result, max) \ 39 | { \ 40 | int c= getc(input); \ 41 | if ('\n' == c || '\r' == c) ++lineNumber; \ 42 | result= (EOF == c) ? 0 : (*(buf)= c, 1); \ 43 | } 44 | 45 | #define YY_LOCAL(T) static T 46 | #define YY_RULE(T) static T 47 | 48 | #include "peg.peg-c" 49 | 50 | void yyerror(char *message) 51 | { 52 | fprintf(stderr, "%s:%d: %s", fileName, lineNumber, message); 53 | if (yyctx->text[0]) fprintf(stderr, " near token '%s'", yyctx->text); 54 | if (yyctx->pos < yyctx->limit || !feof(input)) 55 | { 56 | yyctx->buf[yyctx->limit]= '\0'; 57 | fprintf(stderr, " before text \""); 58 | while (yyctx->pos < yyctx->limit) 59 | { 60 | if ('\n' == yyctx->buf[yyctx->pos] || '\r' == yyctx->buf[yyctx->pos]) break; 61 | fputc(yyctx->buf[yyctx->pos++], stderr); 62 | } 63 | if (yyctx->pos == yyctx->limit) 64 | { 65 | int c; 66 | while (EOF != (c= fgetc(input)) && '\n' != c && '\r' != c) 67 | fputc(c, stderr); 68 | } 69 | fputc('\"', stderr); 70 | } 71 | fprintf(stderr, "\n"); 72 | exit(1); 73 | } 74 | 75 | static void version(char *name) 76 | { 77 | printf("%s version %d.%d.%d\n", name, PEG_MAJOR, PEG_MINOR, PEG_LEVEL); 78 | } 79 | 80 | static void usage(char *name) 81 | { 82 | version(name); 83 | fprintf(stderr, "usage: %s [