3 require 'escape_helper'
5 # So that monoglot and polyglot source files can easily require eachother
6 $LOAD_PATH << File.join(File.dirname(__FILE__), 'glots')
8 # Load all monoglots and polyglots
9 Dir.glob(File.join(File.dirname(__FILE__), 'glots/*.rb')).each {|f| require f }
15 # This script loads all of the Monoglot and Polyglot files found in
16 # <tt>ext/ohcount_native/glots</tt>.
18 # These glots are used to generate the C file polyglots.c, which will define
19 # all of the languages parsers used by ohcount. Do not edit polyglots.c directly.
22 # Defines all of the monoglots and polyglots known to the parser.
23 actionscript = CMonoglot.new("actionscript", '//', [e('/*'), e('*/')], true, true)
24 ada = CMonoglot.new("ada", '--', nil, true, false)
25 assembler = CMonoglot.new("assembler", [';', '!', '//'], [e('/*'), e('*/')], false, false)
26 autoconf = LineCommentMonoglot.new("autoconf", 'dnl')
27 automake = LineCommentMonoglot.new("automake", '#')
28 awk = CMonoglot.new("awk", '#', nil, true, false, {:no_escape_dquote => true})
29 bat = LineCommentMonoglot.new("bat", '^\\\\s*(?i)REM(?-i)')
30 boo = PythonMonoglot.new("boo")
31 clearsilver = CMonoglot.new("clearsilver", '#', nil, true, true)
32 c = CMonoglot.new("c", '//', [e('/*'), e('*/')], true, true)
33 cpp = CMonoglot.new("cpp", '//', [e('/*'), e('*/')], true, true)
34 csharp = CMonoglot.new("csharp", '//', [e('/*'), e('*/')], true, false)
35 css = CMonoglot.new("css", nil, [e('/*'), e('*/')], false, false)
36 dcl = DclMonoglot.new("dcl")
37 dylan = CMonoglot.new("dylan", '//', nil, true, false)
38 ebuild = CMonoglot.new("ebuild", '#', nil, false, false)
39 erlang = CMonoglot.new("erlang", '%%', nil, true, true)
40 java = CMonoglot.new("java", '//', [e('/*'), e('*/')], true, false)
41 javascript = CMonoglot.new("javascript", '//', [e('/*'), e('*/')], true, true)
42 emacslisp = LineCommentMonoglot.new("emacslisp", ";")
43 fortranfixed = CMonoglot.new("fortranfixed", '^[^ \n]', nil, true, true, {:no_escape_dquote => true, :no_escape_squote => true})
44 fortranfree = CMonoglot.new("fortranfree", '!', nil, true, true, {:no_escape_dquote => true, :no_escape_squote => true})
45 haskell = CMonoglot.new("haskell", '--', [e('{-'), e('-}')], true, false)
46 lisp = LineCommentMonoglot.new("lisp", ";")
47 lua = CMonoglot.new("lua", '--', nil, true, true)
48 make = LineCommentMonoglot.new("make", '#')
49 matlab = CMonoglot.new("matlab", '#|%', ['{%', '%}'], false,true)
50 metafont = LineCommentMonoglot.new("metafont", "%");
51 metapost = LineCommentMonoglot.new("metapost", "%");
52 objective_c = CMonoglot.new("objective_c", '//', [e('/*'), e('*/')], true, false)
53 pascal = CMonoglot.new("pascal", '//', ['{','}'], true, true, {:no_escape_dquote => true, :no_escape_squote => true})
54 perl = CMonoglot.new("perl", '#', ['^=\\\\w+', '^=cut[ \t]*\\\\n'], true, true)
55 phplanguage = CMonoglot.new("php", ['//', '#'], [e('/*'), e('*/')], true, true, {:polyglot_name => 'phplanguage'})
56 pike = CMonoglot.new("pike", '//', [e('/*'), e('*/')], true, false)
57 python = PythonMonoglot.new("python")
58 ruby = CMonoglot.new("ruby", '#', nil, true, true)
59 rexx = CMonoglot.new("rexx", nil, [e('/*'), e('*/')], true, true)
60 scheme = LineCommentMonoglot.new("scheme", ";")
61 shell = CMonoglot.new("shell", '#', nil, false, false)
62 smalltalk = CMonoglot.new("smalltalk", nil, [e('"'), e('"')], false, true, options = {:no_escape_squote => true})
63 sql = CMonoglot.new("sql", ['--','//', '#'], [['{','}'], [e('/*'), e('*/')]], true, true)
64 tcl = CMonoglot.new("tcl", '#', nil, true, false)
65 vala = CMonoglot.new("vala", '//', [e('/*'), e('*/')], true, false)
66 vim = CMonoglot.new("vim", '\"', nil, false, false)
67 visualbasic = CMonoglot.new("visualbasic", '\'', nil, true, false)
68 xml = XmlMonoglot.new("xml")
69 xslt = XmlMonoglot.new("xslt")
70 xmlschema = XmlMonoglot.new("xmlschema")
71 mxml = MxmlPolyglot.new("mxml", actionscript, css)
72 html = HtmlPolyglot.new("html", javascript, css)
73 php = HtmlWithPhpPolyglot.new("php", html, phplanguage)
74 rhtml = RhtmlPolyglot.new("rhtml", html, ruby)
75 jsp = JspPolyglot.new("jsp", html, java)
76 groovy = CMonoglot.new("groovy", '//', [e('/*'), e('*/')], true, false)
77 clearsilver_template = ClearsilverTemplate.new("clearsilver_template", html, clearsilver)
78 dmd = DMonoglot.new('dmd')
79 tex = CMonoglot.new("tex", '%', nil, false, false)
80 metapost_with_tex = Biglot.new('metapost_with_tex', metapost, tex, [], [
81 ["verbatimtex", :metapost_code, :tex_code, :from, false, 'verbatim'],
82 ["btex", :metapost_code, :tex_code, :from, false, 'btex'],
83 ["etex", :tex_code, :return, :to, false, 'etex']
85 scala = CMonoglot.new("scala", '//', [e('/*'), e('*/')], true, false)
145 clearsilver_template,
150 File.open("polyglots.c", "w") do |io|
152 # spit out the preamble to our source code
158 * GENERATED FILE **DO NOT EDIT**
162 #define __polyglots_c__
165 #define RETURN (State *)NULL
168 # spits out the actual POLYGLOTS array, which contains a reference to all the polyglots we define in our library
169 polyglots.each do |p|
173 Monoglot::print_banner(io, "POLYGLOTS")
174 io.puts "Polyglot *POLYGLOTS[] = {"
175 polyglots.each do |p|
176 io.puts " &#{ p.definition },"
184 Ohcount::Generator.new.generate