Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/rouge/demos/scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// --------------------------------------------------------------------
// a round groove to be substracted from other solids
// --------------------------------------------------------------------
module round_groove(length = goove_length)
{
groove_radius = 2.25;
groove_center = 2.4;
groove_width = 3.0;
union()
{
translate([0, groove_center, 0] )
cylinder(r = groove_radius, h=len + 2 * manifold_correction, center=true);
translate([0, 0.5, 0] )
cube([groove_width,1.5,len + 2 * manifold_correction], center = true);
}
}
18 changes: 18 additions & 0 deletions lib/rouge/lexers/jinja.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,17 @@ def self.word_operators
# Numbers
rule %r/\d+(?=}\s)/, Num

# The = might not only be an operator but also an assignment of a
# list, tuple or dictionary. The dictionary, starting with an {
# and ending with an } is not yet recognized!
rule %r/(=)( *\{)/ do
groups Operator, Punctuation
push :dictionary
end

# Arithmetic operators (+, -, *, **, //, /)
# TODO : implement modulo (%)
# rule %r/(\+|\-|\*|\/\/?|\*\*?|=)/, Operator
rule %r/(\+|\-|\*|\/\/?|\*\*?|=)/, Operator

# Comparisons operators (<=, <, >=, >, ==, ===, !=)
Expand All @@ -105,8 +114,17 @@ def self.word_operators
rule %r/\]/, Punctuation
rule %r/\(/, Punctuation
rule %r/\)/, Punctuation
# The colon, used in dictionaries was missing
rule %r/\:/, Punctuation
end

state :dictionary do
mixin :literal
mixin :text
rule %r/\}/, Punctuation, :pop!
end


state :comment do
rule %r/[^#]+/m, Comment
rule(/#}/) { token Comment; pop! }
Expand Down
106 changes: 106 additions & 0 deletions lib/rouge/lexers/scad.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
module Lexers
class Scad < Go
title "Scad"
desc 'The OpenSCAD 3D programming language (https://openscad.org/documentation.html#language-reference)'
tag 'scad'
aliases 'scad', 'openscad'
filenames '*.scad'

mimetypes 'text/x-scad'

# This lexer is inherited from the go lexer, which looks clear and conchise :-)
# Those definitions which are different for OpenSCAD are overwritten and the
# states are modified to add the required and remove the unused regexp

# Keywords related to OpenSCAD

KEYWORD = /\b(?:
function | module | if | else | let | for | intersection_for
)\b/x


# Operators and delimiters related to OpenSCAD

OPERATOR = / \+ | - | \*
| % | \^
| <= | < | >= | >
| != | == | = | \!
| && | \|\|
| \/ | \#
/x

SEPARATOR = / \( | \) | \[ | \] | \{
| \} | , | ; | \: | \?
/x

# Literals related to OpenSCAD
INT_LIT = /#{DECIMAL_LIT}/
ESCAPED_CHAR = /\\[nrt\\"]/
CHAR_LIT = /'(?:#{UNICODE_VALUE})'/

# Predeclared identifiers related to OpenSCAD

SPECIAL_VARIABLES = /\$(fa|fs|fn|t|vpr|vpt|vpd|vpf|children|preview|parent_modules)/

PREDECLARED_CONSTANTS = /\b(?:true|false|PI|undef)\b/

PREDECLARED_FUNCTIONS = /\b(?:
circle | square | polygon | text
| sphere | cube | cylinder | polyhedron
| translate | rotate | scale | resize
| mirror | multimatrix | color | offset
| hull | minkowski
| union | difference | intersection
| is_undef | is_bool | is_num | is_string
| is_list | is_function
| concat | lookup | str | chr
| ord | search | version | version_num
| parent_module
| abs | sign | sin | cos
| tan | acos | asin | atan
| atan2 | floor | round | ceil
| ln | len | let | log
| pow | sqrt | exp | rands
| min | max | norm | cross
| echo | render | surface | assert
)\b/x

state :root do
mixin :include_or_use
mixin :simple_tokens
rule(/"/, Str, :interpreted_string)
end

state :simple_tokens do
rule(COMMENT, Comment)
rule(KEYWORD, Keyword)
rule(SPECIAL_VARIABLES, Name::Variable)
rule(PREDECLARED_FUNCTIONS, Name::Builtin)
rule(PREDECLARED_CONSTANTS, Name::Constant)
rule(FLOAT_LIT, Num)
rule(INT_LIT, Num)
rule(CHAR_LIT, Str::Char)
rule(OPERATOR, Operator)
rule(SEPARATOR, Punctuation)
rule(IDENTIFIER, Name)
rule(WHITE_SPACE, Text)
end

# use or include are somehow special:
# Although they are keywords, they are valid only in combination with
# <subdir_and_filename> which uses the < and > which normally are operators
# Here they are used as punctuation and the path is highlighted as an
# ordinary string value even without the delimiting "".
state :include_or_use do
rule /^#{WHITE_SPACE}*(include|use)(#{WHITE_SPACE}+)(<)(.*)(>).*([\n])/ do
groups Keyword, Text, Punctuation, Str, Punctuation, Text
end
end

end
end
end
8 changes: 8 additions & 0 deletions rouge.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
18 changes: 18 additions & 0 deletions spec/lexers/scad_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

describe Rouge::Lexers::Scad do
let(:subject) { Rouge::Lexers::Scad.new }

describe 'guessing' do
include Support::Guessing

it 'guesses by filename' do
assert_guess :filename => 'foo.scad'
end

it 'guesses by mimetype' do
assert_guess :mimetype => 'text/x-scad'
end
end
end
9 changes: 9 additions & 0 deletions spec/visual/samples/jinja
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@ Cool list filter {{ listx | join(', ') }}
{% raw %} One line {{ raw }} block {% endraw %}

{% include 'footer.html' %}

{% set lights = {
'Floor': 'on',
'Livingroom': 'off',
'Bedroom': 'on'
} %}
{% for room, status in lights.items() %}
The light in {{ room }} is {{ status }}.
{% endfor %}
Loading