Skip to content
This repository
Browse code

use block parser in compiler

  • Loading branch information...
commit 901f5beef1556dc8d5968cedf399258c424221c5 1 parent 2cd8fec
Hannes Riechert authored

Showing 2 changed files with 27 additions and 22 deletions. Show diff stats Hide diff stats

  1. +11 11 compiler.co
  2. +16 11 compiler.js
22 compiler.co
@@ -48,15 +48,6 @@ BLOCK_PARSER = stackparser.createAutomaton {
48 48 finalOutput: '"}]'
49 49 }
50 50
51   -res = BLOCK_PARSER.work 'enf```n"e\tke"n```ekeml'
52   -stackparser.StackParser.print res
53   -console.log JSON.parse res.output
54   -
55   -BLOCK_PARSER.render \png , \automatons/blockparser.png , (code, out, err) ->
56   - console.log code
57   - console.log out
58   - console.log err
59   -
60 51 ##################################################
61 52 ##################################################
62 53
@@ -121,11 +112,20 @@ compile = (doc_id, newMarkup, onFinish) ->
121 112 parse = (input) ->
122 113 tree = []
123 114
  115 + ### parse blocks
124 116 config = BLOCK_PARSER.work input
  117 + if config.inconsistent
  118 + return error: "while parsing blocks:\n\n#{stackparser.StackParser.stringify config}", tree: tree
  119 +
  120 + try
  121 + tree = JSON.parse config.output
  122 + catch error
  123 + return error: "JSON could not parse block parser output.\n\n#{stackparser.StackParser.stringify config}"
125 124
126   - #if config.fail
127   - return error: "while parsing blocks:\n#{JSON.stringify config}", tree: tree
  125 + console.log tree
  126 + return error: JSON.stringify tree, 2
128 127
  128 + ### parse one-liners
129 129 /*
130 130
131 131 extractOneLiners tree # extract commands, headlines and defines
27 compiler.js
... ... @@ -1,5 +1,5 @@
1 1 (function(){
2   - var request, stackparser, BLOCK_PARSER, res, config, couchdb, compile, parse, extractOneLiners, deleteEmptyBlocks, parseLists, parseParagraphs, generateBlocks, generateList, generateSubList, generateMath, generateQuote, _parseList, _parseParagraph, __closeAllElements, __getParam, _delChars, _peek;
  2 + var request, stackparser, BLOCK_PARSER, config, couchdb, compile, parse, extractOneLiners, deleteEmptyBlocks, parseLists, parseParagraphs, generateBlocks, generateList, generateSubList, generateMath, generateQuote, _parseList, _parseParagraph, __closeAllElements, __getParam, _delChars, _peek;
3 3 request = require('request');
4 4 stackparser = require('./stackparser');
5 5 BLOCK_PARSER = stackparser.createAutomaton({
@@ -11,14 +11,6 @@
11 11 finalStates: ['q0'],
12 12 finalOutput: '"}]'
13 13 });
14   - res = BLOCK_PARSER.work('enf```n"e\tke"n```ekeml');
15   - stackparser.StackParser.print(res);
16   - console.log(JSON.parse(res.output));
17   - BLOCK_PARSER.render('png', 'automatons/blockparser.png', function(code, out, err){
18   - console.log(code);
19   - console.log(out);
20   - return console.log(err);
21   - });
22 14 config = null;
23 15 couchdb = null;
24 16 compile = function(doc_id, newMarkup, onFinish){
@@ -82,9 +74,22 @@
82 74 var tree, config;
83 75 tree = [];
84 76 config = BLOCK_PARSER.work(input);
  77 + if (config.inconsistent) {
  78 + return {
  79 + error: "while parsing blocks:\n\n" + stackparser.StackParser.stringify(config),
  80 + tree: tree
  81 + };
  82 + }
  83 + try {
  84 + tree = JSON.parse(config.output);
  85 + } catch (error) {
  86 + return {
  87 + error: "JSON could not parse block parser output.\n\n" + stackparser.StackParser.stringify(config)
  88 + };
  89 + }
  90 + console.log(tree);
85 91 return {
86   - error: "while parsing blocks:\n" + JSON.stringify(config),
87   - tree: tree
  92 + ok: JSON.stringify(tree, 2)
88 93 };
89 94 };
90 95 extractOneLiners = function(tree){

0 comments on commit 901f5be

Please sign in to comment.
Something went wrong with that request. Please try again.