![]() ![]() ||=| ]/, Operator rule %r/(NOT|AND|OR|LIKE|BETWEEN|IN)( \s )/im do groups Operator, Text end rule %r/(IS)( \s +)(?:(NOT)( \s +))?(NULL \b )/im do groups Operator, Text, Operator, Text, Operator end rule %r/. I do not know the rules for other sql engines #rule %r/`/, Name::Variable, :backtick rule %r/?(?:(?: \.\d +(?:? \d +)?)| \d + \. We are not parsing into tokens, so this is as close as we can get cheaply RETURN REGEXP_REPLACE ( REGEXP_REPLACE ( REGEXP_REPLACE ( REGEXP_REPLACE ( REGEXP_REPLACE ( p_re, c_strip_comments_regexp, NULL, 1, 0, ' m ' ) - strip comments, ' \s + ', NULL, 1, 0 - strip spaces and newlines too like 'x' modifier ), q')\\t ]', ' \1 '|| CHR ( 9 ), 1, 0 - replace \t with tab character value so it works like in perl ), q' '/, Operator, :pop! end end rule %r/'/, Operator, :single_string # A double-quoted string refers to a database object in our default SQL rule %r/"/, Operator, :double_string # we do not use backticks in Oracle. , use \\ \n since the space will be removed. employee_id %type $End BEGIN - note that \n, \r and \t will be replaced if not preceded by a \. ) +' $IF $$is_dummy_needed $then c_dummy CONSTANT VARCHAR2 ( 30 ) := ' newline> */ - quoted string with embedded newline c_strip_comments_regexp CONSTANT VARCHAR2 ( 32767 ) := q'+ ](-|#).*($| '-' or '#', then everything to end of line or string Strip comment blocks that start with at least one blank, then department_name CREATE OR REPLACE PACKAGE sample_pkg PROCEDURE transform_perl_regexp ( p_re VARCHAR2 ) RETURN VARCHAR2 DETERMINISTIC END sample_pkg / CREATE OR REPLACE PACKAGE BODY sample_pkg FUNCTION transform_perl_regexp ( p_re VARCHAR2 ) RETURN VARCHAR2 DETERMINISTIC IS /* There are quite a few in their queue, so I have no idea whether it will fly any time soon, but I followed the guidelines they provided, so we will see. ![]() ![]() I submitted a Pull Request to the Rouge team. The q-quote operator was a nice challenge that consumed several hours. The regular expressions for breaking it into tokens is where I think I did a decent job based on my own understanding of how Oracle parses it and similar work I’ve done before. I did a lot of grunt work looking through the manuals and v$ tables gathering all of the Oracle keywords, reserved words, types and built-in functions which become part of the lexer. Long story long enough already, I faked it and wound up making what I believe is a decent lexer for Oracle PL/SQL. Even though I had never looked at the language before, it was fairly easy to read and understand what it was doing. ![]() The code is a state machine that walks through the text using regular expressions and classifying the parsed tokens with names that correspond to the CSS file we use for syntax highlighting it. I looked at the existing SQL lexer and also the ones for Perl and Ruby. I can’t tell you how I wound up here, but the documentation for Rouge is very good. Nevertheless I dug into it a bit, got Ruby, Jekyll and Rouge installed locally on a Linux image (apparently it is harder to do on Windows), and started trying to figure out how it fit together. I got a little discouraged at first because I had not picked up Ruby before and wasn’t really interested in learning a new language. The SQL lexer for Rouge is not as robust as I wanted, and when I started looking closer, I realize the existing one for Github wasn’t great either. Unfortunately, it uses a different process than Github Pages via Rouge. It renders my repository README.md files fairly well. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |