Skip to content

Commit

Permalink
Merge branch 'master' into bugfix.reduce-ruby-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrmont committed Jul 3, 2019
2 parents 9125166 + 5809757 commit 3aa37e3
Show file tree
Hide file tree
Showing 28 changed files with 1,969 additions and 748 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,13 @@ If you're here to implement a lexer for your awesome language, there's a good ch

### Run the tests

You can test the core of Rouge simply by running `rake` (no `bundle exec` required), or `rake spec TEST=spec/xxx_spec.rb`
to run a single test file.
You can test the core of Rouge simply by running `rake` (no `bundle exec` required). You can also run a single test file by
setting the `TEST` environment variable to the path of the desired test. For example, to test just the *`ruby` lexer* which is
at path, `spec/lexers/ruby_spec.rb` within the repository, one may simply run the following:

```sh
TEST=spec/lexers/ruby_spec.rb rake
```

It's also set up with `guard`, if you like.

Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'rake/clean'
require 'pathname'
require 'bundler/setup'
require "bundler/gem_tasks"
require "rake/testtask"

Expand Down Expand Up @@ -54,7 +55,7 @@ task :profile_memory do
lexer = Rouge::Lexers::Ruby.new
formatter.format(lexer.lex(sample))
end
print_options = { :scale_bytes => true }
print_options = { scale_bytes: true, normalize_paths: true }

if ENV['CI']
report.pretty_print(print_options)
Expand Down
4 changes: 4 additions & 0 deletions docs/DevEnvironment.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Rouge is written in Ruby and has a number of development dependencies. To
develop new features for Rouge (like a lexer for a new syntax) or to fix bugs,
you need to set up a development environment.

Please note that this guide is about how to configure a development environment
on your local machine. If you want to isolate your Rouge development environment
using Docker, take a gander at {file:docs/Docker.md our guide}.

### Ruby and Git

First things first. This guide is _not_ a guide to installing Ruby and Git.
Expand Down
102 changes: 102 additions & 0 deletions docs/Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!--
# @title Using Docker
-->
# Using Docker

So you want to help with Rouge development but aren't too keen on needing to
install Ruby and whatever dependencies are required by Rouge?
[Docker](https://www.docker.com/) to the rescue!

Docker can be used as a way install Ruby, Rouge and the development dependencies
in a self-contained environment for development. In addition to providing an
alternative for users who don't want to install Ruby, it's also a good choice
for users with an existing installation of Ruby with which they don't want to
interfere.

## Prerequisites

This guide assumes you have Docker and Git installed.

For a guide on installing Docker, we recommend [Docker's official
documentation][dk-inst-docs]. For a guide on installing Git, take a look at
[GitHub's documentation][gh-inst-docs].

[dk-inst-docs]: https://docs.docker.com/get-started/
[gh-inst-docs]: https://help.github.com/en/articles/set-up-git

## Installing

### Downloading Rouge

Clone the project first, and navigate into your clone:

```bash
$ git clone https://github.com/rouge-ruby/rouge.git
$ cd rouge
```

### Configuring the Container

The following line of code sets up Docker with Ruby and Rouge's development
dependencies:

```bash
$ docker run -t -v $PWD:/app -v /tmp/vendor:/vendor -w /app -e BUNDLE_PATH=/vendor ruby bundle
```

Pretty sweet. Let's unpack this:

- `docker run -it`: Runs the command in a new container. `-t` is not strictly
necessary but allows nice colors in the output.

- `-v $PWD:app`: Maps the current folder into the `/app` path within the
container. Used in conjunction with `-w` (see below), this allows the
container to run as if it were inside this directory.

- `-v /tmp/vendor:/vendor`: Maps an arbitrary `vendor` folder into the `/vendor`
path within the container. This is to persist the installed dependencies
across Docker commands, otherwise you would have to re-install each time as
containers are ephemeral by nature.

- `-e BUNDLE_PATH=/vendor`: Sets an environment variable inside the container
that tells Bundler to lookup the dependencies from the `/vendor` path (that
we've mapped to our host machine with the previous line)

- `ruby`: Tells Docker which image to use for the container. The `ruby` image is
part of the official library of "base" Docker images.

- `bundle`: Runs the `bundle` command within the container.

## Executing Commands

### Running Rake

Just replace the `bundle` command with `rake`:

```bash
$ docker run -t -v $PWD:/app -v /tmp/vendor:/vendor -w /app -e BUNDLE_PATH=/vendor ruby rake
```

### Running Rack

Similarly, we can run Rack by replacing `bundle` with `rackup`:

```bash
$ docker run -t -v $PWD:/app -v /tmp/vendor:/vendor -w /app -e BUNDLE_PATH=/vendor -p 9292:9292 ruby bundle exec rackup --host 0.0.0.0
```

The additional command line flags are:

- `-p 9292:9292`: Exposes port 9292 of the container to the same port on the
host.

- `bundle exec rackup --host 0.0.0.0`: Runs Rack and asks it to listen on all
addresses. Without this it will only listen on the `localhost` of the
container and we won't be able to access the server from the host machine.

You should be able to visit <http://localhost:9292> at this point.

## Conclusion

Now that you've got Docker set up, perhaps you'd like to work on
{file:docs/LexerDevelopment.md a lexer}?
4 changes: 4 additions & 0 deletions lib/rouge/demos/openedge
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FORM
"Hello World!" VIEW-AS TEXT AT COL 20 ROW 2
btnOK AT COL 20 ROW 4
WITH FRAME f SIZE 50 BY 5 NO-BOX THREE-D.
60 changes: 12 additions & 48 deletions lib/rouge/demos/powershell
Original file line number Diff line number Diff line change
@@ -1,49 +1,13 @@
Function Get-IPv4Scopes
<#
.SYNOPSIS
Read IPv4Scopes from an array of servers
.PARAMETER Servers
Specifies an array of servers
.EXAMPLE
Get-IPv4Scopes

Will prompt for all inputs
#>
function Verb-Noun
{
[CmdletBinding()]
Param(
# 1
[parameter(
Mandatory=$true,
Position=0,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Server List"
)]
[string[]]$Servers,
#2
[parameter(Mandatory=$false,ValueFromPipeline=$false)]
[bool]$Unique=$false
) #EndParam

Begin {}

Process {
$arrayJobs=@()
foreach ($server in $Servers) {
$arrayJobs+=Invoke-Command -ComputerName $server -scriptblock {Get-DhcpServerv4Scope} -AsJob
}
$complete=$false
while (-not $complete) {
$arrayJobsInProgress= $arrayJobs | Where-Object { $_.State -match 'running' }
if (-not $arrayJobsInProgress) { $complete=$true }
}
$Scopes=$arrayJobs|Receive-Job
$UniqueScopes=$Scopes|Sort-Object -Property ScopeId -Unique
}

End {
if ($Unique) { return $UniqueScopes }
else { return $Scopes }
}

} #end function
<#
.SYNOPSIS
Tells you what it does

.DESCRIPTION
Tells you what it does with more detail.
#>
param ([string]$Name, [string]$Extension = "txt", [string]$foo="bar")
$name = $name + "." + $extension
$name
}
3 changes: 2 additions & 1 deletion lib/rouge/demos/xojo
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Dim f As FolderItem
f = GetOpenFolderItem(FileTypes1.jpeg) // defined in the File Type Set editor
rem - we should check for nil!
If not f.Exists Then
Beep
Beep 'Just for fun
MsgBox("The file " + f.NativePath + "doesn't ""exist.""")
Else // document exists
ImageWell1.image=Picture.Open(f)
Expand Down
2 changes: 2 additions & 0 deletions lib/rouge/demos/xpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(: Authors named Bob Joe who didn't graduate from Harvard :)
//author[first-name = "Joe" and last-name = "Bob"][degree/@from != "Harvard"]
22 changes: 22 additions & 0 deletions lib/rouge/demos/xquery
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
declare namespace html = "http://www.w3.org/1999/xhtml";

declare function local:test-function($catalog as document-node()) {
<html>
<head>
<title>XQuery example for the Rouge highlighter</title>
<link href="style.css"/>
</head>
<body>
<h1>List</h1>
<ul>
{for $product in $catalog/items/product[@sell-by > current-date()] return
<li>
<ul>
<li>{data($product/name)}</li>
<li>{$product/price * (1 + $product/tax)}$</li>
</ul>
</li>}
</ul>
</body>
</html>
};
7 changes: 5 additions & 2 deletions lib/rouge/lexers/elixir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ class Elixir < RegexLexer
rule %r/[a-zA-Z_!]\w*[!\?]?/, Name
rule %r{::|[%(){};,/\|:\\\[\]]}, Punctuation
rule %r/@[a-zA-Z_]\w*|&\d/, Name::Variable
rule %r{\b(0[xX][0-9A-Fa-f]+|\d(_?\d)*(\.(?![^\d\s])
(_?\d)*)?([eE][-+]?\d(_?\d)*)?|0[bB][01]+)\b}x, Num
rule %r{\b\d(_?\d)*(\.(?![^\d\s])(_?\d)+)([eE][-+]?\d(_?\d)*)?\b}, Num::Float
rule %r{\b0x[0-9A-Fa-f](_?[0-9A-Fa-f])*\b}, Num::Hex
rule %r{\b0o[0-7](_?[0-7])*\b}, Num::Oct
rule %r{\b0b[01](_?[01])*\b}, Num::Bin
rule %r{\b\d(_?\d)*\b}, Num::Integer

mixin :strings
mixin :sigil_strings
Expand Down
Loading

0 comments on commit 3aa37e3

Please sign in to comment.