mattfenwick / clojarse-js Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
more informative than, for instance, 'oops'
example:
#java.lang.String["abc"]
that is valid syntax for a call to a java constructor, or something defined with deftype or defrecord
instead of leaving them in the tree, why not:
rationale: won't have to traverse the tree to find the errors. Can just look in the dictionary
currently, just tracking the start position (line/column)
must be <= 255
should this be done here, in the parser? or can it be left for later tree-checkers?
motivation: I'm using this syntax definition in multiple places (normal modules as well as test modules), might as well factor it out
description: somewhere between the CST -- b/c tree is "cleaned" -- and AST
the position passed in is of the 1st " in "abc"
but, the token parsing starts at the a in "abc"
this is because the delimiters "
are assumed to already be correct by the time token parsing is started
what is and isn't checked? when are checks performed? what happens if there's an error?
was:
var symbol_pattern = /^([:]?)([^\d\/].*\/)?(\/|[^\d\/][^\/]*)$/;
// a translation of either of these two, which should be equivalent (from Java):
// - [:]?([\\D&&[^/]].*/)?(/|[\\D&&[^/]][^/]*)
// - [:]? ([^0-9/].*/)? (/|[^0-9/][^/]*)
// check for special error cases (maybe match against regex as in Clojure implementation)
// TODO this could go in Clolint instead
_checks = bind(get, function(chars) {
console.log('chars -- ' + JSON.stringify(chars));
if ( cs[cs.length - 1] === ':' ) {
return cut('identifier may not end with a :', zero);
}
if ( cs.slice(1).indexOf('::') > -1 ) {
return cut(':: is illegal in identifiers (except at beginning)', zero);
}
var match = cs.match(symbol_pattern);
if ( match === null ) {
return cut('invalid identifier for mysterious reasons', zero);
} else if ( match[2] !== void 0 ) {
var m = match[2];
if ( m.slice(m.length - 2) === ':/' ) {
return cut(':/ is sometimes illegal in identifiers', zero);
}
}
return pure(null);
}),
examples:
$ echo '1.2e+31 "\u1234 \n \12"' | node main.js
clojure at 1,1
float at 1,1
{"sign":null,"int":"1","decimal":"2","exponent":{"sign":"+","power":"31"},"suffix":null}
string at 1,9
{"value":[{"pos":[1,11],"kind":"unicode","value":"1234"}," ",{"pos":[1,18],"kind":"simple","value":"n"}," ",{"pos":[1,21],"kind":"octal","value":"12"}]}
the exponents in floats and the escapes in strings
unicode escape: value can not be between u+D800 and u+DFFF
\uDFFF ; -> error
(first "\uDFFF") ; -> not an error -- it's okay in strings
should this be done here, in the parser?
based on java.util.regex.Pattern.compile
-- source
parseAst
should really be parseAST
(in index.js); same goes for parseCst
some escapes are disallowed (which ones?)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.