Permalink
Browse files

dynamic highlighting should work

Need to see it for real with a coffee script parse tree.
Need to be more serious about serving json parse trees
 but most code is there. Should not be too serious either about it.
 Because this will eventually be done in SFW, but we will need it later
for tests.
Next is the support of multiple viewports.
Then we will work it to be a SFW plugin.

Boy, that was hard due to my lack of knowledge of coffeescript/css/DOM
  • Loading branch information...
1 parent f7bef0a commit e6c6bf1a97b1a7cf87563737bf4cee27115c8192 @cognominal committed Jun 26, 2012
Showing with 163 additions and 40 deletions.
  1. +14 −4 TBD
  2. +5 −1 css/zbrew.css
  3. +1 −0 data/dh.json
  4. +72 −0 js/server.js
  5. +9 −3 p6lib/Match/JSON.pm
  6. +0 −7 server/bin/server
  7. +22 −3 server/bin/server.coffee
  8. +31 −11 server/data/bin/hilite.p6
  9. +9 −11 src/hilite.coffee
View
18 TBD
@@ -6,15 +6,25 @@ remove '+' entries when not needed for context
Easy, urgent, important tasks tends to move up
Recurrent but important ones tend to be in the bottom
-* About to finish one part of DH (hovering over unnamed token) DONE
-* Need to do DH when hovering over a parent node (need delay to avoid firework effects)
+## First some random ideas, that are neither yet thought out or prioritized
+
+zbrew works with a json presentation of the parse tree, we
+need to think the relation with the AST too.
+Just noted --node options in coffeescript. Seem very close to what I need.
+Multi file viewport. Note, that a viewport can be a pedagogical device in slides or in
+a literate documentation; moving between tabbed pane is not a acceptable option here.
+Need folding too.
+
+## TBD
+
* Parse path bar need to be scrollable
* Support many highlighted view ports (use class instead of id to identify relevant HTML elements
-* Support json parse trees for different parse engines (necessary to convince jnthn to help). That would be a bummer if I go public without Perl 6. Also json is not a representative grammar. It is too simple.
+* Support json parse trees for different parse engines (necessary to convince jnthn to help). That would be a bummer if I go public without Perl 6. Also json is not a representative grammar. It is too simple. It seems that with jison we can the lexer could hand out stuff before and after the lexeme proper (necessary for our parse tree). Then a modified jison could serve a parse tree. Jison is used for coffeescript so it is important. I am not too sure about pegjs, but there is a pegjs grammar for js so it counts too.
* Display the rule used to reduce the current text (still need css)
-* (1) Bug jnthn/pmichaud to get parse tree dumping in Perl 6 (no luck so far)
+* (1) Bug jnthn/pmichaud to get parse tree dumping in Perl 6 (no luck so far, previous items to have a demo to convince them)
* Think about the combination of codeview and SFW. Combine them and rename to zbrew. And/or rethink what is a forked-SFW plugin
* Install zbrew on my MBP and open a NAT port
+* json and DOM minimization. In the json, we use an array for the equivalent .caps even with a unique element. Fix that, and css accordingly. Also we can change the logic to minimize the DOM tree. That will be a big saver.
* mythomaniac lexers, like with Perl 5, what to do?
* Setup a github page
* Use express to serve the files (SFW will use express anyway)
View
@@ -20,10 +20,14 @@
box-shadow: 0 3px 5px rgba(0,0,0,0.1);
}
-.a {
+.opr {
color: #ff0000
}
+.opd :not(.opr) {
+ color: #0000ff
+}
+
#offset-content {
height: 100px;
}
View
@@ -0,0 +1 @@
+{"rules":{ "TOP" : "token TOP { <paren> || <addTerm> }\n ", "paren" : "token paren { '(' <TOP> ')' }\n ", "mulTerm" : "token mulTerm { <atom> '*' <atom> | <paren> | <atom> }\n ", "addTerm" : "token addTerm { <mulTerm> '+' <mulTerm> | <paren> | <atom> }\n ", "atom" : "token atom { <int> || <id> }\n ", "int" : "token int { \\d+ }\n ", "id" : "token id { \\w+ }\n}", "infix" : "token infix:sym<*> { <sym> <O('%mulitplicative')> }\n\n\n" }, "parseTree":{"TOP":[{"paren":["(",{"TOP":[{"addTerm":[{"atom":[{"id":["a"]}]}]}]},")"]}]}, "docco":{ "TOP" : "TOP", "string" : "s", "number" : "m" }}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -55,17 +55,23 @@ sub extractRules($_) is export {
sub deepToJSON (Match:D $match, :%rules, :%docco = %docco_,
:$ruleNm = 'TOP') is export {
- sub recurse($match, $rulenNm) {
- my $v = $match.chunks.map: { .value ~~ Str ?? to-json .value !! recurse .value, .key };
+ sub recurse($match, $ruleNm) {
+ my $v = $match.chunks.map: {
+ .value ~~ Str ?? to-json .value !! recurse .value, .key };
'{' ~ $ruleNm.Str.perl ~ ":[" ~ $v.join( ',') ~ ']}';
# previous line preferred to next to avoid extra spaces.
# to-json do { Pair.new: key => $ruleNm.Str.perl, value => $v };
}
- my $parseTree := recurse $match, :$ruleNm;
+ my $parseTree := recurse $match, $ruleNm;
my $jsonRules := to-json %rules;
# I would like de write :$parseTree, need a C<qq :j ||> and $str is JSON;
qq|\{"rules":$jsonRules, "parseTree":$parseTree, "docco":{to-json %docco}\}|;
}
+
+
+
+
+
View
@@ -1,7 +0,0 @@
-express = require 'express'
-app = express()
-
-app.get '/', (req, res) ->
- res.send 'Hello World'
-
-app.listen 8080
View
@@ -23,13 +23,32 @@ html = """
</body>
"""
+errHtml = (req, err, status = 404) ->
+ writeText res,
+ """
+ <body>#{err}</body>
+ """, status
+
+writeText = (res, text, status=200) ->
+ res.writeHead status, {'Content-Type': "text/#{type}"}
+ res.end text
+
app.get '/', (req, res) ->
- res.writeHead 200, {'Content-Type': 'text/html'}
- res.end html
+ writeHTMl res, html
+
+app.get '/bin/:id', (req, res) ->
+ execNm = "./bin/#{req.params.id}"
+ fs.stat execNm, (err, stats) ->
+ return errHtml err if err
+ exec = spawn execNm
+
+ exec.stdout.on 'data', (data) ->
+ res.end writeText json
+
-app.get '/:id', (req, res) ->
+app.get '/:id', execNm ->
res.send req.params.id
app.listen 8080
View
@@ -1,21 +1,41 @@
+## intermediate step
+## Note: Top comment should straddle the array width
+## Note : Notes should be emphasized
+# the goal of this moronic and borked grammar. But it demonstrates how DH
+# shows how code is parsed. Here, it visibly demonstrates the
+# effect of relative operator precedence.
+
use JSON::Tiny;
use lib './p6lib';
use Match::JSON;
-# the goal of this moronic grammar is to demonstrate how DH
-# shows how code is parsed. Here, it visibly demonstrate the
-# effect of relative operator precedence.
grammar G {
- token mul { <term> '*' <term> }
- token TOP { <term> '+' <term> }
- token term { <int> || <id> }
- token int { \d+ }
- token id { \w+ }
+ token TOP { <paren> || <addTerm> }
+ token paren { '(' <TOP> ')' }
+ token mulTerm { <atom> '*' <atom> | <paren> | <atom> }
+ token addTerm { <mulTerm> '+' <mulTerm> | <paren> | <atom> }
+ token atom { <int> || <id> }
+ token int { \d+ }
+ token id { \w+ }
};
-my $match = G.parse: "a+b*c";
+my $match = G.parse: "(a)+b*c";
+$*ERR.say: $match;
die unless $match;
-say $match.perl;
my $fnm = %*ENV<HOME> ~ '/git/codeview/server/data/bin/hilite.p6';
my %rules = extractRules slurp $fnm;
-say deepToJSON $match, :%rules ;
+say deepToJSON $match, :%rules ;
+
+=begin END
+
+
+token infix:sym<+> { <sym> <O('%additive')> }
+token infix:sym<*> { <sym> <O('%mulitplicative')> }
+
+
+INIT {
+ G:O(':prec<u=>, :assoc<left>', '%multiplicative');
+ G.O(':prec<t=>, :assoc<left>', '%additive');
+}
+
+
View
@@ -80,20 +80,18 @@ $ ->
# extract the current rule to add it to the rule vieport
ruleElt = $('#current-rule')
dad = elt.parentNode
+ # DH of operand and operators.
+ # I am not documenting because I will change it.
+ # see TBD about json and html minimization
+ $(dad).addClass 'opd'
showRule rule if rule = ruleNm dad
- unnamedP = (i) ->
- r = !$(this).hasClass 'named'
- console.log "#{r} #{i} #{elt}"
- r
+ unnamedP = (i) -> !$(this).hasClass 'named'
if unnamedP elt
- # using .a > .a in ccss
-# $(dad).addClass 'a'
- console.log elt
- wtf = $(dad).children().filter(unnamedP)
- wtf.addClass 'a'
+ $(dad).children().filter(unnamedP).addClass 'opr'
dehilite = ->
- $('.a').removeClass 'a'
+ $('.opr').removeClass 'opr'
+ $('.opd').removeClass 'opd'
showRule = (ruleNm) ->
@@ -176,5 +174,5 @@ $ ->
$('#current-rule').attr('data', JSON.stringify(data.rules))
- $.getJSON 'data/parsed.json', (data) ->
+ $.getJSON 'data/dh.json', (data) ->
generateView $('.code-top'), data

0 comments on commit e6c6bf1

Please sign in to comment.