Skip to content

Commit

Permalink
Merge branch 'rouge-ruby:master' into feat.bicepLexer
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviermignot authored Apr 3, 2023
2 parents db54907 + be4d825 commit 450356d
Show file tree
Hide file tree
Showing 11 changed files with 809 additions and 422 deletions.
7 changes: 7 additions & 0 deletions lib/rouge/guessers/disambiguation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def match?(filename)

disambiguate '*.cls' do
next TeX if matches?(/\A\s*(?:\\|%)/)
next OpenEdge if matches?(/(no\-undo|BLOCK\-LEVEL|ROUTINE\-LEVEL|&ANALYZE\-SUSPEND)/i)
next Apex
end

Expand All @@ -139,6 +140,12 @@ def match?(filename)

Puppet
end

disambiguate '*.p' do
next Prolog if contains?(':-')
next Prolog if matches?(/\A\w+(\(\w+\,\s*\w+\))*\./)
next OpenEdge
end
end
end
end
12 changes: 6 additions & 6 deletions lib/rouge/lexers/dart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ class Dart < RegexLexer
mimetypes 'text/x-dart'

keywords = %w(
as assert await break case catch continue default do else finally for
if in is new rethrow return super switch this throw try while with yield
as assert await break case catch continue default do else finally for if
in is new rethrow return super switch this throw try while when with yield
)

declarations = %w(
abstract async dynamic const covariant external extends factory final get
implements late native on operator required set static sync typedef var
abstract base async dynamic const covariant external extends factory final get implements
inline interface late native on operator required sealed set static sync typedef var
)

types = %w(bool Comparable double Dynamic enum Function int List Map Never Null num Object Pattern Set String Symbol Type Uri void)
types = %w(bool Comparable double Dynamic enum Function int List Map Never Null num Object Pattern Record Set String Symbol Type Uri void)

imports = %w(import deferred export library part\s*of part source)

Expand Down Expand Up @@ -53,7 +53,7 @@ class Dart < RegexLexer
rule %r/(?:#{declarations.join('|')})\b/, Keyword::Declaration
rule %r/(?:#{types.join('|')})\b/, Keyword::Type
rule %r/(?:true|false|null)\b/, Keyword::Constant
rule %r/(?:class|interface|mixin)\b/, Keyword::Declaration, :class
rule %r/(?:class|mixin)\b/, Keyword::Declaration, :class
rule %r/(?:#{imports.join('|')})\b/, Keyword::Namespace, :import
rule %r/(\.)(#{id})/ do
groups Operator, Name::Attribute
Expand Down
4 changes: 0 additions & 4 deletions lib/rouge/lexers/mosel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class Mosel < RegexLexer

mimetypes 'text/x-mosel'

def self.detect?(text)
return true if text =~ /^\s*(model|package)\s+/
end

id = /[a-zA-Z_][a-zA-Z0-9_]*/

############################################################################################################################
Expand Down
957 changes: 581 additions & 376 deletions lib/rouge/lexers/openedge.rb

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions lib/rouge/lexers/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def current_string
groups Punctuation, Text, Str::Doc
end

rule %r/\.\.\.\B$/, Name::Builtin::Pseudo

rule %r/[^\S\n]+/, Text
rule %r(#(.*)?\n?), Comment::Single
rule %r/[\[\]{}:(),;.]/, Punctuation
Expand All @@ -88,6 +90,8 @@ def current_string

rule %r/@#{dotted_identifier}/i, Name::Decorator

rule %r/(>>>|\.\.\.)\B/, Generic::Prompt

rule %r/(in|is|and|or|not)\b/, Operator::Word
rule %r/(<<|>>|\/\/|\*\*)=?/, Operator
rule %r/[-~+\/*%=<>&^|@]=?|!=/, Operator
Expand Down Expand Up @@ -120,7 +124,7 @@ def current_string
# TODO: not in python 3
rule %r/`.*?`/, Str::Backtick
rule %r/([rfbu]{0,2})('''|"""|['"])/i do |m|
groups Str::Affix, Str
groups Str::Affix, Str::Heredoc
current_string.register type: m[1].downcase, delim: m[2]
push :generic_string
end
Expand Down Expand Up @@ -178,11 +182,12 @@ def current_string
end

state :generic_string do
rule %r/[^'"\\{]+/, Str
rule %r/>>>|\.\.\./, Generic::Prompt, :doctest
rule %r/[^'"\\{]+?/, Str
rule %r/{{/, Str

rule %r/'''|"""|['"]/ do |m|
token Str
token Str::Heredoc
if current_string.delim? m[0]
current_string.remove
pop!
Expand Down Expand Up @@ -220,6 +225,17 @@ def current_string
rule %r/\\./, Str, :pop!
end

state :doctest do
rule %r/\n\n/, Text, :pop!

rule %r/'''|"""/ do
token Str::Heredoc
pop!(2) if in_state?(:generic_string) # pop :doctest and :generic_string
end

mixin :root
end

state :generic_interpol do
rule %r/[^{}!:]+/ do |m|
recurse m[0]
Expand Down
13 changes: 7 additions & 6 deletions lib/rouge/lexers/rust.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ def self.keywords
def self.builtins
@builtins ||= Set.new %w(
Add BitAnd BitOr BitXor bool c_char c_double c_float char
c_int clock_t c_long c_longlong Cons Const Copy c_schar c_short
c_int clock_t c_long c_longlong Copy c_schar c_short
c_uchar c_uint c_ulong c_ulonglong c_ushort c_void dev_t DIR
dirent Div Either Eq Err f32 f64 Failure FILE float fpos_t
i16 i32 i64 i8 isize Index ino_t int intptr_t Left mode_t Modulo Mul
Neg Nil None Num off_t Ok Option Ord Owned pid_t Ptr ptrdiff_t
Right Send Shl Shr size_t Some ssize_t str Sub Success time_t
dirent Div Eq Err f32 f64 FILE float fpos_t
i16 i32 i64 i8 isize Index ino_t int intptr_t mode_t Mul
Neg None off_t Ok Option Ord Owned pid_t ptrdiff_t
Send Shl Shr size_t Some ssize_t str Sub time_t
u16 u32 u64 u8 usize uint uintptr_t
Box Vec String Gc Rc Arc
Box Vec String Rc Arc
u128 i128 Result Sync Pin Unpin Sized Drop drop Fn FnMut FnOnce
Clone PartialEq PartialOrd AsMut AsRef From Into Default
DoubleEndedIterator ExactSizeIterator Extend IntoIterator Iterator
FromIterator ToOwned ToString TryFrom TryInto
)
end

Expand Down
16 changes: 16 additions & 0 deletions spec/lexers/openedge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
it 'guesses by filename' do
assert_guess :filename => 'foo.w'
assert_guess :filename => 'foo.i'
assert_guess :filename => 'foo.cls', :source => "BLOCK-LEVEL ON ERROR UNDO, THROW\r\nDEF VAR toto AS CHAR NO-UNDO."
assert_guess :filename => 'foo.p', :source => "BLOCK-LEVEL ON ERROR UNDO, THROW\r\nDEF VAR toto AS CHAR NO-UNDO."
end

it 'guesses by mimetype' do
Expand All @@ -23,5 +25,19 @@
it 'recognizes one-line comments not followed by a newline (#796)' do
assert_tokens_equal '// comment', ['Comment.Single', '// comment']
end

it 'recognizes multiline comment ' do
assert_tokens_equal "/*** \r\n/* * hello\r\n */*/", ["Comment.Multiline", "/*** \r\n/* * hello\r\n */*/"]
end

it 'recognizes comment at end of line' do
assert_tokens_equal '&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12 // hello', ["Comment.Preproc", "&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12 "], ["Comment.Single", "// hello"]
end

it 'recognizes preprocess' do
assert_tokens_equal "{ test.i\r\n&abc = ABC\r\n&def = 'D E F'\r\n&hij=\"H I J\" }",
["Comment.Preproc", "{ test.i\r\n&abc = ABC\r\n&def = 'D E F'\r\n&hij=\"H I J\" }"]
assert_tokens_equal "{ test.i \"{&Test}\" }", ["Comment.Preproc", "{ test.i \"{&Test}\" }"]
end
end
end
2 changes: 1 addition & 1 deletion spec/lexers/prolog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

it 'guesses by filename' do
assert_guess :filename => 'foo.pro'
assert_guess :filename => 'foo.P'
assert_guess :filename => 'foo.P', :source => ':-'
assert_guess :filename => 'foo.prolog'
assert_guess :filename => 'foo.pl', :source => ':-'
end
Expand Down
114 changes: 113 additions & 1 deletion spec/visual/samples/openedge
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
/****** Sample of .w or .p file ******/

/* This .W file was created with the Progress UIB. */

&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12 // hello
&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12

// hello
DEFINE VARIABLE w AS HANDLE NO-UNDO.
/**** /*
hello
*/ / */


&SCOPED-DEFINE preprocessor-name definition

CREATE WINDOW w ASSIGN
WIDTH = 50
HEIGHT = 5
MESSAGE-AREA = FALSE
STATUS-AREA = FALSE.

&IF PROVERSION > "12" &THEN
CURRENT-WINDOW = w.
&ENDIF

DEFINE TEMP-TABLE inventario
FIELD fecInv AS DATE format 99/99/9999
FIELD almInv AS CHARACTER
FIELD linInv AS CHARACTER
FIELD invIni LIKE in_qty_oh FORMAT "->>>,>>9.999"
FIELD entProd LIKE in_qty_oh FORMAT "->>>,>>9.999"
FIELD entProdCedis LIKE in_qty_oh FORMAT "->>>,>>9.999"
FIELD entTransf LIKE in_qty_oh FORMAT "->>,>>9.999"
FIELD embCedis LIKE in_qty_oh FORMAT "->>>,>>9.999"
FIELD uniEmbCedis AS DECIMAL FORMAT ">,>>9.<<"
FIELD embPlanta LIKE in_qty_oh FORMAT "->>>,>>9.999"
FIELD uniEmbPlanta AS DECIMAL FORMAT ">,>>9.<<"
FIELD invFin LIKE in_qty_oh FORMAT "->>>,>>9.999"
FIELD tonEmb LIKE in_qty_oh FORMAT "->>>,>>9.999"
FIELD uniEmb AS INTEGER FORMAT ">,>>9".

DEFINE BUTTON btnOK LABEL "OK" SIZE 12 BY 1.2.

Expand All @@ -25,3 +52,88 @@ WAIT-FOR "CHOOSE" OF btnOK.
DELETE OBJECT w.

&ANALYZE-RESUME

PROCEDURE GetCurrentProcessId EXTERNAL "KERNEL32.DLL":
DEFINE RETURN PARAMETER intProcessHandle AS LONG.
END PROCEDURE.

procedure 'TpFrame.TaskPanel.ItemClick':U:

end procedure.
{ test.i "{&Test}" }
{ test.i &abc = ABC &def = 'D E F' &hij="H I J" }
{ test.i
&abc = ABC
&def = 'D E F'
&hij="H I J" }

/****** Sample of .cls file ******/

block-level on error undo, throw.

using OpenEdge.Core.Collections.IList.
using OpenEdge.Core.Collections.List FROM PROPATH.
using OpenEdge.Core.Util.Token FROM ASSEMBLY.
using OpenEdge.Core.Util.*.
using OpenEdge.Logging.Filter.* FROM PROPATH.
using OpenEdge.Logging.Filter.* FROM ASSEMBLY.
using OpenEdge.Logging.Filter.LoggerFilterNode.
using OpenEdge.Logging.Format.ISupportFormatting.
using OpenEdge.Logging.ILogWriter.
using OpenEdge.Logging.LogEvent.
using OpenEdge.Logging.LogLevelEnum.
using OpenEdge.Logging.LogMessage.
using OpenEdge.Logging.Logger.

class OpenEdge.Logging.Logger final implements ILogWriter, ISupportFormatting:
{Consultingwerk/Framework/ttServiceLoader.i}



// (mandatory) Holds filters for formatting the messagesto this logger
define public property LogFilters as ILoggerFilter extent no-undo
get.
private set.

// (mandatory) The level being logged at
define public property LogLevel as LogLevelEnum no-undo get. private set.



/* Constructor

@param character The name of this logger implementation
@param LogLevelEnum The level we're logging at
@param LoggerFilterList A list of filters to format and write the log data */
@Test(expected="Progress.Lang.AppError"). //coucou
constructor public Logger(input pcName as character,
input poLevel as LogLevelEnum,
input poLogFilters as ILoggerFilter extent):

end constructor.

/* Log for a simple message

@param LogMessage The message to log. */
@Test.
method public void Fatal(input poMessage as LogMessage):
if this-object:LogLevel lt LogLevelEnum:FATAL then
return.
DEFINE VARIABLE var1 AS LOGICAL NO-UNDO INITIAL NO.
DEFINE VARIABLE var2 AS CHARACTER NO-UNDO.
var2 = "hello".
var2 = 'hello'.
var2 = 'hello':U.
var2 = "hello":U.
var2 = "hello ~r~n".
var2 = "hello ""World""".
var2 = "hello{&hello}":U.
var2 = {&hello}.
READ-XML(LogLevelEnum:FATAL, poMessage, ?).
WriteMessage(LogLevelEnum:FATAL, poMessage, ?).

ASSIGN toto = 2 + var1 * (toto + 4).
ASSIGN toto = 2 + var1 (toto + 4).
end method.

end class.
34 changes: 34 additions & 0 deletions spec/visual/samples/python
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,37 @@ class Spam:
pass

spam = Spam()

# Doctest
def factorial(n):
"""Return the factorial of n, an exact integer >= 0.

>>> [factorial(n) for n in range(6)]
[1, 1, 2, 6, 24, 120]

>>> for i in [factorial(n) for n in range(2)]:
... print(i)
1
1
>>> factorial(30)
265252859812191058636308480000000
>>> factorial(-1)
Traceback (most recent call last):
...
ValueError: n must be >= 0

Factorials of floats are OK, but the float must be an exact integer:
>>> factorial(30.1)
Traceback (most recent call last):
...
ValueError: n must be exact integer
>>> factorial(30.0)
265252859812191058636308480000000

It must also not be ridiculously large:
>>> factorial(1e100)
Traceback (most recent call last):
...
OverflowError: n too large
"""
print("hello world")
Loading

0 comments on commit 450356d

Please sign in to comment.