alexwarth / ometa-js Goto Github PK
View Code? Open in Web Editor NEWOMeta for JavaScript
Home Page: http://tinlizzie.org/ometa-js/
License: MIT License
OMeta for JavaScript
Home Page: http://tinlizzie.org/ometa-js/
License: MIT License
does not work: http://vpri.org/pipermail/ometa/
I read your research work "Experimenting with PL" / "ometa parsing.pdf" which was interesting and easy. I do not understand
http://www.tinlizzie.org/ometa-js
however. Whenever I press "do it" or "print it" after selecting "important info" and "go to project", I see errors in the changed source code.
I am maintaining a fork of ometa/js, https://github.com/keeyip/nodemeta, which aims to make tweaking ometa/js easier.
I want to use Ometa as a common language for creating syntax highlighters for the CodeMirror text editor, but because a highlighter in CodeMirror is fed input line by line, I was hoping there would be a straightforward way of altering the Ometa/JS implementation to allow for pausing/continuing a parse. The best I can think of is to wrap all the rules with a call/cc, do you think this is a reasonable approach?
Example of CodeMirror's syntax highlighting api:
function parseIt(code) {
return OmetaParser.matchAll(code, 'start')
}
// Note: The real api names are not important
CodeMirror.registerSyntaxHighlighter('mylang', function myHighlighter(singleLineOfCode) {
// CodeMirror asynchronously dispatches to myHighlighter
parseIt(singleLineOfCode)
})
Here is my patch (but I think you can write better ;-)):
number = ``0x'' hexLit:n -> [#number, n]
+ | <digit+ (('e' | 'E') ('-' | '+')? digit+)?>:f -> [#number, parseFloat(f)]
| <digit+ ('.' digit+)?>:f -> [#number, parseFloat(f)],
Currently, failing during parsing just leads to something like:
Error: match failed
at .../node_modules/ometa-js/lib/ometajs/core.js:64:15
at fail (.../node_modules/ometa-js/lib/ometajs/core.js:11:20)
at Object.<anonymous> (.../node_modules/ometa-js/lib/ometajs/core.js:16:2)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
And if you look in ometajs/core.js
, those lines are nothing of interest, those are just the definitions of the fail()
function, basically. They don't even have access to the token that we were at when we failed.
At the end of the file,
// now we'll make sure that our translator actually worked by replacing
// the original OMeta parser and compiler with the ones defined here
BSOMetaParser = OMetaParser
BSOMetaTranslator = OMetaTranslator
suggests that from then on it will use the presented parser+translator, but it seems that BSJSOMetaParser , not BSOMetaParser is used (same for Translator). If I leave the code as it is, and change the translator source code, the changes have no effect.
Update: For future reference, I got this impression by slightly changing the translator (like disabling the "trans" rule), which didn't have effect on the given "Duh" example).
I am writing a parser for the smalltalk language and am having an problem with the following equivalent rules. One works (unaryExpr2) and the other (unaryExpr) parses short. Thanks!
ometa STParser {
tokRule = ...,
primary = ...,
unarySel = ...,
...
// does not work
unaryObjExpr = unaryExpr | primary,
unaryExpr = unaryObjExpr:mexpr tokRule('unarySel'):sel -> [`send, mexpr, sel],
// works
unaryExpr2 = (unaryExpr2 | primary):mexpr tokRule('unarySel'):sel -> [`send, mexpr, sel],
...
}
STParser.matchAll('56 double factorial', 'unaryExpr') =
[send, [number, 56], [selector, double]]
STParser.matchAll('56 double factorial', 'unaryExpr2') =
[send, [send, [number, 56], [selector, double]], [selector, factorial]]
ometa L {
p = 'a' p:x 'a' -> (x+1) | 'a' -> 0
}
alert(L.matchAll("aaa", 'p')) // 1 - ok
alert(L.matchAll("aaaaa", 'p')) // 1 - wrong!
alert(L.matchAll("aaaaaaa", 'p')) // 3 - ok
alert(L.matchAll("aaaaaaaaa", 'p')) // 1 - wrong!
alert(L.matchAll("aaaaaaaaaaa", 'p')) // 3 - wrong!
alert(L.matchAll("aaaaaaaaaaaaa", 'p')) // 5 - wrong!
alert(L.matchAll("aaaaaaaaaaaaaaa", 'p')) // 7 - ok
Are all the files that are included in ometa-rhino.js needed for runtime executing of code that is generated?
new
keyword can be used not only in form "new" "name":n "(" listOf(#asgnExpr, ','):as ")"
. Other right use cases:
var n1 = new Bla,
n2 = Bla.bla(),
n2 = new ({a: {b: function() { console.log(arguments) }}}).a.b;
http://www.tinlizzie.org/ometa-js/#JavaScript_Compiler
tree = JSParser.matchAll("var bla = /bla/", "topLevel")
-- failed to match
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.