Skip to content

Commit

Permalink
Added a new prototype file to MetaCode
Browse files Browse the repository at this point in the history
  • Loading branch information
szabototo89 committed Feb 5, 2014
1 parent 3434e97 commit e308b58
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 15 deletions.
9 changes: 6 additions & 3 deletions grammar/MetaCode.g4
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ grammar MetaCode;
init : (NUMBER NEWLINE?)+
;

WHITESPACE : [ \t]+ -> skip;
NEWLINE : '\r'? '\n' -> skip;
WHITESPACE : [ \t]+ -> skip
;
NEWLINE : '\r'? '\n' -> skip
;

NUMBER : INT
| FLOAT;
| FLOAT
;

fragment
INT : DIGIT+
Expand Down
23 changes: 23 additions & 0 deletions grammar/MetaCodeLexer.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
lexer grammar MetaCodeLexer;

WHITESPACE : [ \t]+ -> skip
;
NEWLINE : [\r]? [\n] -> skip
;

NUMBER : INT
| FLOAT
;

fragment
INT : DIGIT+
;

fragment
FLOAT : DIGIT+ [.] DIGIT*
| [.] DIGIT+
;

fragment
DIGIT : [0-9]
;
4 changes: 3 additions & 1 deletion grammar/example.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
545
18.
18.
.8
3.14
22 changes: 11 additions & 11 deletions grammar/run.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
example = if ARGV[0].nil?
File.open("example.txt", "w") if not File.exist?("example.txt")
"example.txt"
else
ARGV[0].to_s
end
puts "Running MetaCode parser ..."
Dir.mkdir("src") if not Dir.exists? "src"
Dir.chdir("src")
system('call antlr4 "../MetaCode.g4" -visitor')
system('call grun MetaCode init -gui ..\\' + example)
example = if ARGV[0].nil?
File.open("example.txt", "w") if not File.exist?("example.txt")
"example.txt"
else
ARGV[0].to_s
end
puts "Running MetaCode parser ..."
Dir.mkdir("src") if not Dir.exists? "src"
Dir.chdir("src")
system('call antlr4 "../MetaCode.g4" -visitor')
system('call grun MetaCode init -gui ..\\' + example)
25 changes: 25 additions & 0 deletions prototype/macro.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
selector class-methods = class > method
selector if-conditions = if > condition
selector class-by-name[className] = class[name=className]

macro printMethods(methods: class > method[name="func*"]) : * do
foreach (method in methods) do
Console.WriteLine(method.text)
end
methods
end

//default return 'type' : *
macro negateConditionsOfIf(condition : if-conditions) do

end

macro negateConditionsOfIf(condition : if > condition) : if do

end

macro generateToStringMethod(c : class) : class do
(c > method).addMethod({
public function toString() : String = c.name
})
end

0 comments on commit e308b58

Please sign in to comment.