Skip to content

Adds a Dylan lexer#2248

Merged
jneen merged 6 commits intomainfrom
lexer.dylan
Mar 10, 2026
Merged

Adds a Dylan lexer#2248
jneen merged 6 commits intomainfrom
lexer.dylan

Conversation

@jneen
Copy link
Member

@jneen jneen commented Mar 9, 2026

Extends and supersedes #1706.
Fixes #25.

Changes made:

  • Explicitly support Dylan Interchange Format (the frontmatter at the beginning of Dylan modules)
  • Use keyword sets instead of joined regexes
  • Fix string parsing and operator parsing (=> parsed as two separate tokens previously)
  • Inline most regexes

@jneen
Copy link
Member Author

jneen commented Mar 9, 2026

May be of interest to @pedro-w - please let me know if I've missed any syntax!

@pedro-w
Copy link
Contributor

pedro-w commented Mar 10, 2026

Great, thank you @jneen . I can give it quick try on some other dylan files if that would help?

@jneen
Copy link
Member Author

jneen commented Mar 10, 2026

For sure! If you have more detailed stress-test files I'd love to see them as well.

@jneen
Copy link
Member Author

jneen commented Mar 10, 2026

I'm going to merge this for now, @pedro-w please let me know if you have more dylan code to test against.

@jneen jneen added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit 3eaf116 Mar 10, 2026
10 checks passed
@jneen jneen deleted the lexer.dylan branch March 10, 2026 23:53
@pedro-w
Copy link
Contributor

pedro-w commented Mar 11, 2026

Sorry, it took me a while to remember how to work ruby and then build rouge from github !!

It looks great apart from handling backslash - it's used to escape names that might be reserved words or operators.

From the DRM

name:
    word
    \ word
    operator-name

unreserved-name:
    any word that is not also a reserved-word
    \ word
    operator-name

operator-name:
    \ unary-operator
    \ binary-operator

Is that trivial for you to add? - please say if not and I will roll up my sleeves and send a PR, might take a while...

Thanks!

@jneen
Copy link
Member Author

jneen commented Mar 11, 2026

Can you provide some sample code that uses this?

@pedro-w
Copy link
Contributor

pedro-w commented Mar 11, 2026

Sure,

https://github.com/dylan-lang/opendylan/blob/85fc782bf2b1390929bdb9fc98f88e5e55d7a742/sources/collections/collectors.dylan#L160-L180

define inline method collector-protocol
    (class :: subclass(<number>), #key from = 0, by = \+)
  => (new-collector      :: <box>,
      add-first          :: <function>,
      add-last           :: <function>,
      add-sequence-first :: <function>,
      add-sequence-last  :: <function>,
      collection         :: <function>)
  values(box(from),
         method (collector, value)
           collector.object := by(value, collector.object);
         end,
         method (collector, value)
           collector.object := by(collector.object, value);
         end,
         sequence-collection-not-yet-implemented,
         sequence-collection-not-yet-implemented,
         method (collector)
           collector.object
         end)
end method;

In the part (class :: subclass(<number>), #key from = 0, by = \+) , \+ is an "operator name" in the DRM grammar. Rougify show it as a a white char on a red background and rougify debug says it's an error, not matched (I haven't got the exact text in front of me sorry)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement a Dylan lexer

2 participants